From f1126e63b1b9ccfa84d7594ee9c2b39b3fe9cac6 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 31 Aug 2020 15:25:02 +0300 Subject: [PATCH] Flex: Improve row rename logic --- CHANGELOG.md | 1 - .../Grav/Framework/Flex/Storage/FolderStorage.php | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b4116c1c..0f64e32ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php index 124e2bc3c..dd8cbb336 100644 --- a/system/src/Grav/Framework/Flex/Storage/FolderStorage.php +++ b/system/src/Grav/Framework/Flex/Storage/FolderStorage.php @@ -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);