1
0

Delete invalid attachments all together

This commit is contained in:
Richard Dern 2024-05-03 16:45:42 +02:00
parent 67c3dd73cb
commit 6fe9928b4d

View File

@ -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());