Made the image re-importer more robust + fixed a typo.

This commit is contained in:
Peter Deltchev 2016-03-16 09:32:39 -07:00
parent dab9f08cf5
commit af760aa13f
2 changed files with 14 additions and 15 deletions

View file

@ -83,23 +83,22 @@ class Image extends Model
$hash = md5_file($file->getPathname()); $hash = md5_file($file->getPathname());
$image = Image::whereHash($hash)->whereUploadedBy($userId)->first(); $image = Image::whereHash($hash)->whereUploadedBy($userId)->first();
if (!$forceReupload && $image) { if ($image) {
return $image; if ($forceReupload) {
} // delete existing versions of the image
$filenames = scandir($image->getDirectory());
$imagePrefix = $image->id.'_';
if ($forceReupload) { $filenames = array_filter($filenames, function(string $filename) use ($imagePrefix) {
// delete existing versions of the image return Str::startsWith($filename, $imagePrefix);
$filenames = scandir($image->getDirectory()); });
$imagePrefix = $image->id.'_';
$filenames = array_filter($filenames, function(string $filename) use ($imagePrefix) { foreach($filenames as $filename) {
return Str::startsWith($filename, $imagePrefix); unlink($image->getDirectory().'/'.$filename);
}); }
} else {
foreach($filenames as $filename) { return $image;
unlink($image->getDirectory().'/'.$filename);
} }
} else { } else {
$image = new Image(); $image = new Image();
} }

View file

@ -346,7 +346,7 @@ ponyfm.config [
templateUrl: '/templates/home/index.html' templateUrl: '/templates/home/index.html'
controller: 'home' controller: 'home'
# Final catch-all for aritsts # Final catch-all for artists
state.state 'content.artist', state.state 'content.artist',
url: '^/{slug}' url: '^/{slug}'
templateUrl: '/templates/artists/_show_layout.html' templateUrl: '/templates/artists/_show_layout.html'