diff --git a/CHANGELOG.md b/CHANGELOG.md index 901fb8183..8672ca34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,8 @@ * 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 + * 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 25fd578ec..f0aebba17 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -578,6 +578,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(); } diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index 149f5fadb..59948e1be 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);