From e6103bbd547d9837444daaaa601d096e905954f9 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 24 Nov 2017 22:18:31 -0800 Subject: [PATCH] Fixed an issue with Image::clearExisting Now no longer deletes original image regardless of paramter --- app/Console/Commands/RebuildImages.php | 2 +- app/Models/Image.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/RebuildImages.php b/app/Console/Commands/RebuildImages.php index 51c6a9bf..d2fb2048 100644 --- a/app/Console/Commands/RebuildImages.php +++ b/app/Console/Commands/RebuildImages.php @@ -41,7 +41,7 @@ class RebuildImages extends Command { $images = Image::all(); foreach ($images as $image) { - $this->info("Regenerating images for ".$image->filename); + $this->info("Regenerating images for id:".$image->id. " (".$image->filename.")"); $image->clearExisting(); $originalFile = new File($image->getFile(Image::ORIGINAL)); diff --git a/app/Models/Image.php b/app/Models/Image.php index 46a10b70..253ce857 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -201,12 +201,10 @@ class Image extends Model public function clearExisting($includeOriginal = false) { $files = scandir($this->getDirectory()); $filePrefix = $this->id.'_'; + $originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name']; - $files = array_filter($files, function($file) use ($includeOriginal, $filePrefix) { - $originalName = Image::$ImageTypes[Image::ORIGINAL]['name']; - - if ($file === $filePrefix.$originalName && !$includeOriginal) - return false; + $files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) { + if (Str::startsWith($file,$originalName) && !$includeOriginal) return false; else return (Str::startsWith($file, $filePrefix)); });