From 38718e0b5dec9a98bab3d4875c9d2c6d331c1bdb Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 21 Aug 2020 17:53:28 -0600 Subject: [PATCH] Fixed bug where FileModel images wouldn't properly store their config after being retrieved from the cache --- modules/system/classes/ImageResizer.php | 45 ++++++++++++++----------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/modules/system/classes/ImageResizer.php b/modules/system/classes/ImageResizer.php index 678f8d21c..e73fb2d19 100644 --- a/modules/system/classes/ImageResizer.php +++ b/modules/system/classes/ImageResizer.php @@ -230,10 +230,10 @@ class ImageResizer 'options' => $this->options, ]; - if (!empty($this->image['fileModel']) && $this->image['fileModel'] instanceof FileModel) { + if ($fileModel = $this->getFileModel()) { $config['image']['fileModel'] = [ - 'class' => get_class($this->image['fileModel']), - 'key' => $this->image['fileModel']->getKey(), + 'class' => get_class($fileModel), + 'key' => $fileModel->getKey(), ]; } @@ -249,14 +249,8 @@ class ImageResizer return; } - // Get the target disk & path to store the final image - if ($this->image['source'] === 'filemodel' && $fileModel = $this->getFileModel()) { - $disk = $fileModel->getDisk(); - $path = $fileModel->getDiskPath($fileModel->getThumbFilename($this->width, $this->height, $this->options)); - } else { - $disk = Storage::disk(Config::get('cms.resized.disk', 'local')); - $path = $this->getPathToResizedImage(); - } + // Get the details for the target image + list($disk, $path) = $this->getTargetDetails(); // Copy the image to be resized to the temp directory $tempPath = $this->getLocalTempPath(); @@ -402,6 +396,24 @@ class ImageResizer return $this->fileModel; } + /** + * Get the details for the target image + * + * @return array [Illuminate\Filesystem\FilesystemAdapter $disk, (string) $path] + */ + protected function getTargetDetails() + { + if ($this->image['source'] === 'filemodel' && $fileModel = $this->getFileModel()) { + $disk = $fileModel->getDisk(); + $path = $fileModel->getDiskPath($fileModel->getThumbFilename($this->width, $this->height, $this->options)); + } else { + $disk = Storage::disk(Config::get('cms.resized.disk', 'local')); + $path = $this->getPathToResizedImage(); + } + + return [$disk, $path]; + } + /** * Get the reference to the resized image if the requested resize exists * @@ -410,15 +422,8 @@ class ImageResizer */ public function isResized() { - if ($this->image['source'] === 'filemodel') { - $model = $this->getFileModel(); - $thumbFile = $model->getThumbFilename($this->width, $this->height, $this->options); - $disk = $model->getDisk(); - $path = $model->getDiskPath($thumbFile); - } else { - $disk = Storage::disk(Config::get('cms.resized.disk', 'local')); - $path = $this->getPathToResizedImage(); - } + // Get the details for the target image + list($disk, $path) = $this->getTargetDetails(); // Return true if the path is a file and it exists on the target disk return !empty(FileHelper::extension($path)) && $disk->exists($path);