Flex: Improve row rename logic

This commit is contained in:
Matias Griese
2020-08-31 15:25:02 +03:00
parent 7157ed08f9
commit f1126e63b1
2 changed files with 9 additions and 6 deletions

View File

@@ -12,7 +12,6 @@
* Fixed `Flex Pages` bug where `onAdminSave` passes page as `$event['page']` instead of `$event['object']` [#2995](https://github.com/getgrav/grav/issues/2995)
* Fixed `Flex Pages` bug where changing a modular page template added duplicate file [admin#1899](https://github.com/getgrav/grav-plugin-admin/issues/1899)
* Fixed `Flex Pages` bug where renaming slug causes bad ordering range after save [#2997](https://github.com/getgrav/grav/issues/2997)
#2997
# v1.7.0-rc.15
## 07/22/2020

View File

@@ -230,10 +230,6 @@ class FolderStorage extends AbstractFilesystemStorage
*/
public function renameRow(string $src, string $dst): bool
{
if ($this->hasKey($dst)) {
throw new \RuntimeException("Cannot rename object: key '{$dst}' is already taken");
}
if (!$this->hasKey($src)) {
return false;
}
@@ -241,7 +237,15 @@ class FolderStorage extends AbstractFilesystemStorage
$srcPath = $this->getStoragePath($src);
$dstPath = $this->getStoragePath($dst);
if (!$srcPath || !$dstPath) {
return false;
throw new \RuntimeException("Destination path '{$dst}' is empty");
}
if ($srcPath === $dstPath) {
return true;
}
if ($this->hasKey($dst)) {
throw new \RuntimeException("Cannot rename object '{$src}': key '{$dst}' is already taken $srcPath $dstPath");
}
return $this->moveFolder($srcPath, $dstPath);