Fixed an issue with Image::clearExisting

Now no longer deletes original image regardless of paramter
This commit is contained in:
Isaac 2017-11-24 22:18:31 -08:00
parent e502785c2d
commit e6103bbd54
2 changed files with 4 additions and 6 deletions

View file

@ -41,7 +41,7 @@ class RebuildImages extends Command
{ {
$images = Image::all(); $images = Image::all();
foreach ($images as $image) { foreach ($images as $image) {
$this->info("Regenerating images for ".$image->filename); $this->info("Regenerating images for id:".$image->id. " (".$image->filename.")");
$image->clearExisting(); $image->clearExisting();
$originalFile = new File($image->getFile(Image::ORIGINAL)); $originalFile = new File($image->getFile(Image::ORIGINAL));

View file

@ -201,12 +201,10 @@ class Image extends Model
public function clearExisting($includeOriginal = false) { public function clearExisting($includeOriginal = false) {
$files = scandir($this->getDirectory()); $files = scandir($this->getDirectory());
$filePrefix = $this->id.'_'; $filePrefix = $this->id.'_';
$originalName = $filePrefix.Image::$ImageTypes[Image::ORIGINAL]['name'];
$files = array_filter($files, function($file) use ($includeOriginal, $filePrefix) { $files = array_filter($files, function($file) use ($originalName, $includeOriginal, $filePrefix) {
$originalName = Image::$ImageTypes[Image::ORIGINAL]['name']; if (Str::startsWith($file,$originalName) && !$includeOriginal) return false;
if ($file === $filePrefix.$originalName && !$includeOriginal)
return false;
else return (Str::startsWith($file, $filePrefix)); else return (Str::startsWith($file, $filePrefix));
}); });