mirror of
https://github.com/getgrav/grav.git
synced 2026-03-01 01:51:29 +01:00
Improve move page into itself check
This commit is contained in:
@@ -206,10 +206,6 @@ class PageObject extends FlexPageObject
|
||||
// Make sure page isn't being moved under itself.
|
||||
$key = $this->getStorageKey();
|
||||
|
||||
if ($key === $parentKey || strpos($parentKey, $key . '/') === 0) {
|
||||
throw new RuntimeException(sprintf('Page /%s cannot be moved to %s', $this->getKey(), $parentRoute));
|
||||
}
|
||||
|
||||
/** @var PageObject|null $parent */
|
||||
$parent = $parentKey !== false ? $this->getFlexDirectory()->getObject($parentKey, 'storage_key') : null;
|
||||
if (!$parent) {
|
||||
|
||||
@@ -373,7 +373,7 @@ class PageStorage extends FolderStorage
|
||||
|
||||
try {
|
||||
if ($key === '' && empty($row['root'])) {
|
||||
throw new RuntimeException('No storage key given');
|
||||
throw new RuntimeException('Page has no path');
|
||||
}
|
||||
|
||||
$grav = Grav::instance();
|
||||
@@ -394,9 +394,17 @@ class PageStorage extends FolderStorage
|
||||
if ($oldFolder !== $newFolder && file_exists($oldFolder)) {
|
||||
$isCopy = $row['__META']['copy'] ?? false;
|
||||
if ($isCopy) {
|
||||
if (strpos($newFolder, $oldFolder . '/') === 0) {
|
||||
throw new RuntimeException(sprintf('Page /%s cannot be copied to itself', $oldKey));
|
||||
}
|
||||
|
||||
$this->copyRow($oldKey, $newKey);
|
||||
$debugger->addMessage("Page copied: {$oldFolder} => {$newFolder}", 'debug');
|
||||
} else {
|
||||
if (strpos($newFolder, $oldFolder . '/') === 0) {
|
||||
throw new RuntimeException(sprintf('Page /%s cannot be moved to itself', $oldKey));
|
||||
}
|
||||
|
||||
$this->renameRow($oldKey, $newKey);
|
||||
$debugger->addMessage("Page moved: {$oldFolder} => {$newFolder}", 'debug');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user