diff --git a/app/Classes/Traits/Repairs/RepairsImages.php b/app/Classes/Traits/Repairs/RepairsImages.php index feffaf2..93f3289 100644 --- a/app/Classes/Traits/Repairs/RepairsImages.php +++ b/app/Classes/Traits/Repairs/RepairsImages.php @@ -3,8 +3,10 @@ namespace App\Classes\Traits\Repairs; use App\Classes\AttachmentsManager; +use App\Exceptions\AttachmentNotFound; use Carbon\Carbon; use Illuminate\Support\Str; +use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Laravel\Facades\Image; use League\Flysystem\StorageAttributes; @@ -148,8 +150,15 @@ private function syncImageVariants(string $ref) */ private function syncImageVariant(string $ref, string $filter) { - $originalData = $this->getAttachmentData($ref); - $variantData = $this->getVariantData($ref, $filter); + try { + $originalData = $this->getAttachmentData($ref); + } catch (AttachmentNotFound $ex) { + $this->deleteAttachment($ref); + + return; + } + + $variantData = $this->getVariantData($ref, $filter); $variantFilepath = $this->getVariantFullPath($ref, $filter); @@ -171,10 +180,26 @@ private function syncImageVariant(string $ref, string $filter) private function createImageVariant(string $ref, string $filter) { $filterClass = config(sprintf('imagefilters.%s', $filter)); - $original = $this->getAttachmentFullPath($ref); - $target = $this->getVariantFullPath($ref, $filter); - $contents = $this->disk->get($original); - $image = Image::read($contents); + + try { + $original = $this->getAttachmentFullPath($ref); + } catch (AttachmentNotFound $ex) { + $this->deleteAttachment($ref); + + return; + } + + $target = $this->getVariantFullPath($ref, $filter); + $contents = $this->disk->get($original); + + try { + $image = Image::read($contents); + } catch (DecoderException $ex) { + $this->deleteAttachment($ref); + + return; + } + $variantData = $this->getVariantData($ref, $filter); $image->modify(new $filterClass());