mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-11-24 16:51:25 -05:00
Allow the main_ext to be webp by not creating or deleting a webp copy when this is the case, and delete thumbnails when DashboardModel items are deleted
This commit is contained in:
parent
f8aa6e9984
commit
ced98ebb81
1 changed files with 22 additions and 4 deletions
|
@ -282,7 +282,10 @@ class DashboardModel extends Model
|
|||
|
||||
// Save the image
|
||||
$image->save($base_image_filename . $main_ext);
|
||||
|
||||
if ($main_ext !== 'webp') {
|
||||
$image->save($base_image_filename . 'webp');
|
||||
}
|
||||
|
||||
// Create the thumbnail directory if it doesn't exist
|
||||
$thumb_directory = public_path($this->getUploadsPath('thumb'));
|
||||
|
@ -303,8 +306,11 @@ class DashboardModel extends Model
|
|||
|
||||
// Save the thumbnail
|
||||
$thumb->save($base_thumb_filename . $main_ext);
|
||||
|
||||
if ($main_ext !== 'webp') {
|
||||
$thumb->save($base_thumb_filename . 'webp');
|
||||
}
|
||||
}
|
||||
|
||||
return 'success';
|
||||
}
|
||||
|
@ -342,8 +348,8 @@ class DashboardModel extends Model
|
|||
// Build the set of extensions to delete
|
||||
array_push($extensions, $main_ext);
|
||||
|
||||
// If the image extension isn't svg also delete the webp
|
||||
if ($main_ext != 'svg') {
|
||||
// If the image extension isn't svg or webp also delete the webp copy
|
||||
if ($main_ext != 'svg' && $main_ext != 'webp') {
|
||||
array_push($extensions, 'webp');
|
||||
}
|
||||
|
||||
|
@ -360,6 +366,18 @@ class DashboardModel extends Model
|
|||
} else if ($not_exist_fail) {
|
||||
return 'image-not-exists-fail';
|
||||
}
|
||||
|
||||
// Get the full path of the thumbnail
|
||||
$thumb = public_path($this->getUploadsPath('thumb') . $this->id . '-' . $name . '.' . $ext);
|
||||
|
||||
// Try to delete the thumbnail
|
||||
if (file_exists($thumb)) {
|
||||
if (!unlink($thumb)) {
|
||||
return 'thumb-delete-fail';
|
||||
}
|
||||
} else if ($not_exist_fail) {
|
||||
return 'thumb-not-exists-fail';
|
||||
}
|
||||
}
|
||||
|
||||
// Success
|
||||
|
|
Loading…
Reference in a new issue