From af760aa13f0ca3c27c0d811e26498543c81a97cb Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Wed, 16 Mar 2016 09:32:39 -0700 Subject: [PATCH] Made the image re-importer more robust + fixed a typo. --- app/Models/Image.php | 27 ++++++++++++------------- resources/assets/scripts/app/app.coffee | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/Models/Image.php b/app/Models/Image.php index 95d9ff13..882e8d0c 100644 --- a/app/Models/Image.php +++ b/app/Models/Image.php @@ -83,23 +83,22 @@ class Image extends Model $hash = md5_file($file->getPathname()); $image = Image::whereHash($hash)->whereUploadedBy($userId)->first(); - if (!$forceReupload && $image) { - return $image; - } + if ($image) { + if ($forceReupload) { + // delete existing versions of the image + $filenames = scandir($image->getDirectory()); + $imagePrefix = $image->id.'_'; - if ($forceReupload) { - // delete existing versions of the image - $filenames = scandir($image->getDirectory()); - $imagePrefix = $image->id.'_'; + $filenames = array_filter($filenames, function(string $filename) use ($imagePrefix) { + return Str::startsWith($filename, $imagePrefix); + }); - $filenames = array_filter($filenames, function(string $filename) use ($imagePrefix) { - return Str::startsWith($filename, $imagePrefix); - }); - - foreach($filenames as $filename) { - unlink($image->getDirectory().'/'.$filename); + foreach($filenames as $filename) { + unlink($image->getDirectory().'/'.$filename); + } + } else { + return $image; } - } else { $image = new Image(); } diff --git a/resources/assets/scripts/app/app.coffee b/resources/assets/scripts/app/app.coffee index 42c4324d..561ce43d 100644 --- a/resources/assets/scripts/app/app.coffee +++ b/resources/assets/scripts/app/app.coffee @@ -346,7 +346,7 @@ ponyfm.config [ templateUrl: '/templates/home/index.html' controller: 'home' - # Final catch-all for aritsts + # Final catch-all for artists state.state 'content.artist', url: '^/{slug}' templateUrl: '/templates/artists/_show_layout.html'