mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Improve move page into itself check
This commit is contained in:
parent
eb89c00bd5
commit
fa819064ef
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user