diff --git a/src/Entity/Attachment.php b/src/Entity/Attachment.php index 05ac40980c..89263b35a1 100644 --- a/src/Entity/Attachment.php +++ b/src/Entity/Attachment.php @@ -221,6 +221,7 @@ class Attachment extends Entity } else { $this->setFilename(null); $this->setSize(null); + // Important not to null neither width nor height DB::persist($this); DB::flush(); } diff --git a/src/Entity/AttachmentThumbnail.php b/src/Entity/AttachmentThumbnail.php index 98d8b8f170..b2e00170fc 100644 --- a/src/Entity/AttachmentThumbnail.php +++ b/src/Entity/AttachmentThumbnail.php @@ -163,12 +163,19 @@ class AttachmentThumbnail extends Entity $predicted_width = null; $predicted_height = null; try { + if (is_null($attachment->getWidth()) || is_null($attachment->getHeight())) { + // TODO: check if we can generate from an existing thumbnail + throw new ClientException(_m('Invalid dimensions requested for thumbnail.')); + } return Cache::get('thumb-' . $attachment->getId() . "-{$width}x{$height}", function () use ($crop, $attachment, $width, $height, &$predicted_width, &$predicted_height) { [$predicted_width, $predicted_height] = self::predictScalingValues($attachment->getWidth(), $attachment->getHeight(), $width, $height, $crop); return DB::findOneBy('attachment_thumbnail', ['attachment_id' => $attachment->getId(), 'width' => $predicted_width, 'height' => $predicted_height]); }); } catch (NotFoundException $e) { + if (is_null($attachment->getPath())) { + throw new NotFoundException('Can\'t generate a thumbnail for this attachment given the requested dimensions'); + } $thumbnail = self::create(['attachment_id' => $attachment->getId()]); $event_map = []; Event::handle('ResizerAvailable', [&$event_map]);