forked from GNUsocial/gnu-social
[ATTACHMENT] Some attachments don't have thumbnails and that's okay
This commit is contained in:
parent
b4a03b814f
commit
f690bc06ae
@ -221,6 +221,7 @@ class Attachment extends Entity
|
|||||||
} else {
|
} else {
|
||||||
$this->setFilename(null);
|
$this->setFilename(null);
|
||||||
$this->setSize(null);
|
$this->setSize(null);
|
||||||
|
// Important not to null neither width nor height
|
||||||
DB::persist($this);
|
DB::persist($this);
|
||||||
DB::flush();
|
DB::flush();
|
||||||
}
|
}
|
||||||
|
@ -163,12 +163,19 @@ class AttachmentThumbnail extends Entity
|
|||||||
$predicted_width = null;
|
$predicted_width = null;
|
||||||
$predicted_height = null;
|
$predicted_height = null;
|
||||||
try {
|
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}",
|
return Cache::get('thumb-' . $attachment->getId() . "-{$width}x{$height}",
|
||||||
function () use ($crop, $attachment, $width, $height, &$predicted_width, &$predicted_height) {
|
function () use ($crop, $attachment, $width, $height, &$predicted_width, &$predicted_height) {
|
||||||
[$predicted_width, $predicted_height] = self::predictScalingValues($attachment->getWidth(), $attachment->getHeight(), $width, $height, $crop);
|
[$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]);
|
return DB::findOneBy('attachment_thumbnail', ['attachment_id' => $attachment->getId(), 'width' => $predicted_width, 'height' => $predicted_height]);
|
||||||
});
|
});
|
||||||
} catch (NotFoundException $e) {
|
} 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()]);
|
$thumbnail = self::create(['attachment_id' => $attachment->getId()]);
|
||||||
$event_map = [];
|
$event_map = [];
|
||||||
Event::handle('ResizerAvailable', [&$event_map]);
|
Event::handle('ResizerAvailable', [&$event_map]);
|
||||||
|
Loading…
Reference in New Issue
Block a user