From a5348f2427e1ef16478ba1afccb3be0a9b5e4e8e Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Thu, 22 Jul 2021 21:17:23 +0100 Subject: [PATCH] [MEDIA][AttachmentThumbnail] Add mimetype to Entity --- plugins/ImageEncoder/ImageEncoder.php | 5 +++-- plugins/VideoEncoder/VideoEncoder.php | 12 ++++++++++++ src/Entity/AttachmentThumbnail.php | 11 ++++++----- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/plugins/ImageEncoder/ImageEncoder.php b/plugins/ImageEncoder/ImageEncoder.php index bdb4c83f9a..01a7ae716e 100644 --- a/plugins/ImageEncoder/ImageEncoder.php +++ b/plugins/ImageEncoder/ImageEncoder.php @@ -106,11 +106,11 @@ class ImageEncoder extends Plugin } /** - * @param $event_map + * @param array $event_map * * @return bool */ - public function onResizerAvailable(&$event_map): bool + public function onResizerAvailable(array &$event_map): bool { $event_map['image'] = 'ResizeImagePath'; return Event::next; @@ -121,6 +121,7 @@ class ImageEncoder extends Plugin * * @param array $vars * @param array $res + * * @return bool */ public function onViewAttachmentImage(array $vars, array &$res): bool diff --git a/plugins/VideoEncoder/VideoEncoder.php b/plugins/VideoEncoder/VideoEncoder.php index 039b7d6ac1..e7ff9a9b29 100644 --- a/plugins/VideoEncoder/VideoEncoder.php +++ b/plugins/VideoEncoder/VideoEncoder.php @@ -57,11 +57,23 @@ class VideoEncoder extends Plugin return true; } + /** + * @param array $event_map + * + * @return bool + */ + public function onResizerAvailable(array &$event_map): bool + { + //$event_map['video'] = 'ResizeVideoPath'; + return Event::next; + } + /** * Generates the view for attachments of type Video * * @param array $vars * @param array $res + * * @return bool */ public function onViewAttachmentVideo(array $vars, array &$res): bool diff --git a/src/Entity/AttachmentThumbnail.php b/src/Entity/AttachmentThumbnail.php index d593f4e92e..24b17d2c95 100644 --- a/src/Entity/AttachmentThumbnail.php +++ b/src/Entity/AttachmentThumbnail.php @@ -186,6 +186,7 @@ class AttachmentThumbnail extends Entity $ext = '.' . MimeTypes::getDefault()->getExtensions($temp->getMimeType())[0]; $filename = "{$predicted_width}x{$predicted_height}{$ext}-" . $attachment->getFileHash(); $thumbnail->setFilename($filename); + $thumbnail->setMimetype($mimetype); DB::persist($thumbnail); DB::flush(); $temp->move(Common::config('thumbnail', 'dir'), $filename); @@ -302,11 +303,11 @@ class AttachmentThumbnail extends Entity 'name' => 'attachment_thumbnail', 'fields' => [ 'attachment_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Attachment.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'thumbnail for what attachment'], - // 'mimetype' => ['type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'], - 'width' => ['type' => 'int', 'not null' => true, 'description' => 'width of thumbnail'], - 'height' => ['type' => 'int', 'not null' => true, 'description' => 'height of thumbnail'], - 'filename' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'thumbnail filename'], - 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], + 'mimetype' => ['type' => 'varchar', 'length' => 50, 'description' => 'mime type of resource'], + 'width' => ['type' => 'int', 'not null' => true, 'description' => 'width of thumbnail'], + 'height' => ['type' => 'int', 'not null' => true, 'description' => 'height of thumbnail'], + 'filename' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'thumbnail filename'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], 'primary key' => ['attachment_id', 'width', 'height'], 'indexes' => [