From 4bbb5f00a43be60e0e7bfe00d3f2401cbed9abdf Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 18 Mar 2025 11:51:48 +0100 Subject: [PATCH] GdMediaHandler.php: handle file kind --- inc/Service/Media/GdMediaHandler.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/inc/Service/Media/GdMediaHandler.php b/inc/Service/Media/GdMediaHandler.php index 62f82d6c..d67278b9 100644 --- a/inc/Service/Media/GdMediaHandler.php +++ b/inc/Service/Media/GdMediaHandler.php @@ -81,12 +81,12 @@ class GdMediaHandler implements MediaHandler { || ($mime === 'image/avif' && self::PHP81 && $info['AVIF Support']); } - public function openHandle(string $file_path, string $file_mime): mixed { + public function openHandle(string $file_path, string $file_mime, int $file_kind): mixed { $gd = self::imageCreateFrom($file_path, $file_mime); if ($gd === false) { throw new \RuntimeException("Could not open '$file_path'"); } - return [ $gd, $file_path, $file_mime ]; + return [ $gd, $file_path, $file_mime, $file_kind ]; } public function generateThumb( @@ -96,7 +96,7 @@ class GdMediaHandler implements MediaHandler { int $max_width, int $max_height ): ThumbGenerationResult { - list($gd, $source_file_path, $source_file_mime) = $handle; + list($gd, $source_file_path, $source_file_mime, $source_file_kind) = $handle; $gd = self::imageCreateFrom($source_file_path, $source_file_mime); if ($gd === false) { @@ -109,8 +109,14 @@ class GdMediaHandler implements MediaHandler { if ($width <= $max_width && $height <= $max_height) { $out_path = $preferred_out_file_path . '.' . self::MIME_TO_EXT[$source_file_mime]; - if (!Fs\link_or_copy($source_file_path, $out_path)) { - throw new \RuntimeException("Could not link or copy '$source_file_path' to '$out_path'"); + if ($source_file_kind === self::FILE_KIND_UPLOADED) { + if (!Fs\move_or_copy_uploaded($source_file_path, $out_path)) { + throw new \RuntimeException("Could not move or copy uploaded file '$source_file_path' to '$out_path'"); + } + } else { + if (!Fs\link_or_copy($source_file_path, $out_path)) { + throw new \RuntimeException("Could not link or copy '$source_file_path' to '$out_path'"); + } } return new ThumbGenerationResult(