Delete invalid attachments all together
This commit is contained in:
parent
67c3dd73cb
commit
6fe9928b4d
|
@ -3,8 +3,10 @@
|
||||||
namespace App\Classes\Traits\Repairs;
|
namespace App\Classes\Traits\Repairs;
|
||||||
|
|
||||||
use App\Classes\AttachmentsManager;
|
use App\Classes\AttachmentsManager;
|
||||||
|
use App\Exceptions\AttachmentNotFound;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Intervention\Image\Exceptions\DecoderException;
|
||||||
use Intervention\Image\Laravel\Facades\Image;
|
use Intervention\Image\Laravel\Facades\Image;
|
||||||
use League\Flysystem\StorageAttributes;
|
use League\Flysystem\StorageAttributes;
|
||||||
|
|
||||||
|
@ -148,7 +150,14 @@ private function syncImageVariants(string $ref)
|
||||||
*/
|
*/
|
||||||
private function syncImageVariant(string $ref, string $filter)
|
private function syncImageVariant(string $ref, string $filter)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
$originalData = $this->getAttachmentData($ref);
|
$originalData = $this->getAttachmentData($ref);
|
||||||
|
} catch (AttachmentNotFound $ex) {
|
||||||
|
$this->deleteAttachment($ref);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$variantData = $this->getVariantData($ref, $filter);
|
$variantData = $this->getVariantData($ref, $filter);
|
||||||
|
|
||||||
$variantFilepath = $this->getVariantFullPath($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)
|
private function createImageVariant(string $ref, string $filter)
|
||||||
{
|
{
|
||||||
$filterClass = config(sprintf('imagefilters.%s', $filter));
|
$filterClass = config(sprintf('imagefilters.%s', $filter));
|
||||||
|
|
||||||
|
try {
|
||||||
$original = $this->getAttachmentFullPath($ref);
|
$original = $this->getAttachmentFullPath($ref);
|
||||||
|
} catch (AttachmentNotFound $ex) {
|
||||||
|
$this->deleteAttachment($ref);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$target = $this->getVariantFullPath($ref, $filter);
|
$target = $this->getVariantFullPath($ref, $filter);
|
||||||
$contents = $this->disk->get($original);
|
$contents = $this->disk->get($original);
|
||||||
|
|
||||||
|
try {
|
||||||
$image = Image::read($contents);
|
$image = Image::read($contents);
|
||||||
|
} catch (DecoderException $ex) {
|
||||||
|
$this->deleteAttachment($ref);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$variantData = $this->getVariantData($ref, $filter);
|
$variantData = $this->getVariantData($ref, $filter);
|
||||||
|
|
||||||
$image->modify(new $filterClass());
|
$image->modify(new $filterClass());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user