From a372ae90c2cef725d768eec682c40b6f09c9b950 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 16 Jul 2019 09:11:11 +0300 Subject: [PATCH 1/2] Fixed an error when trying to delete a file from non-existing Flex Object --- CHANGELOG.md | 1 + .../Grav/Framework/Flex/Traits/FlexMediaTrait.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeea7f2ee..5a49f7f7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Fixed fatal error 'Expiration date must be an integer, a DateInterval or null, "double" given' [#2529](https://github.com/getgrav/grav/issues/2529) * Fixed non-existing Flex object having a bad media folder * Fixed collections using `page@.self:` should allow modular pages if requested + * Fixed an error when trying to delete a file from non-existing Flex Object # v1.6.11 ## 06/21/2019 diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index 0cee41e98..8b2270604 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -153,6 +153,12 @@ trait FlexMediaTrait /** @var UniformResourceLocator $locator */ $locator = $grav['locator']; $path = $media->getPath(); + if (!$path) { + $language = $grav['language']; + + throw new RuntimeException($language->translate('PLUGIN_ADMIN.FAILED_TO_MOVE_UPLOADED_FILE'), 400); + } + if ($locator->isStream($path)) { $path = $locator->findResource($path, true, true); $locator->clearCache($path); @@ -202,12 +208,16 @@ trait FlexMediaTrait } $media = $this->getMedia(); + $path = $media->getPath(); + if (!$path) { + return; + } /** @var UniformResourceLocator $locator */ $locator = $grav['locator']; - $targetPath = $media->getPath() . '/' . $dirname; - $targetFile = $media->getPath() . '/' . $filename; + $targetPath = $path . '/' . $dirname; + $targetFile = $path . '/' . $filename; if ($locator->isStream($targetFile)) { $targetPath = $locator->findResource($targetPath, true, true); $targetFile = $locator->findResource($targetFile, true, true); From 57c65ad881cc2e0bcd809f3d30042d9aee443fe3 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 16 Jul 2019 09:50:30 +0300 Subject: [PATCH 2/2] Fixed `FlexObject::exists()` failing sometimes just after the object has been saved --- CHANGELOG.md | 1 + system/src/Grav/Framework/Flex/FlexObject.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a49f7f7b..25737ad31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Fixed non-existing Flex object having a bad media folder * Fixed collections using `page@.self:` should allow modular pages if requested * Fixed an error when trying to delete a file from non-existing Flex Object + * Fixed `FlexObject::exists()` failing sometimes just after the object has been saved # v1.6.11 ## 06/21/2019 diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 01f45d079..7fbdbc076 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -550,6 +550,15 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface } } + // FIXME: For some reason locator caching isn't cleared for the file, investigate! + $locator = Grav::instance()['locator']; + $locator->clearCache(); + + // Make sure that the object exists before continuing (just in case). + if (!$this->exists()) { + throw new \RuntimeException('Saving failed: Object does not exist!'); + } + if (method_exists($this, 'saveUpdatedMedia')) { $this->saveUpdatedMedia(); }