diff --git a/inc/Service/Media/FallbackMediaHandler.php b/inc/Service/Media/FallbackMediaHandler.php index ea1d3a6a..e745fc61 100644 --- a/inc/Service/Media/FallbackMediaHandler.php +++ b/inc/Service/Media/FallbackMediaHandler.php @@ -2,10 +2,12 @@ namespace Vichan\Service\Media; use Vichan\Data\ThumbGenerationResult; -use Vichan\Functions\{Fs, Metadata}; +use Vichan\Functions\Metadata; class FallbackMediaHandler implements MediaHandler { + use MediaHandlerTrait; + private string $path; private int $width; private int $height; @@ -15,10 +17,10 @@ class FallbackMediaHandler implements MediaHandler { private static function getShape(string $file_path) { $ret = \getimagesize($file_path); if ($ret === false) { - throw new \RuntimeException("Could not read image sizes of '$file_path'"); + throw new MediaException("Could not read image sizes of '$file_path'", MediaException::ERR_NO_OPEN); } if ($ret[2] == \IMAGETYPE_UNKNOWN) { - throw new \RuntimeException("Error '$file_path' is not an image"); + throw new \RuntimeException("Error '$file_path' is not an image", MediaException::ERR_BAD_MEDIA_TYPE); } $width = $ret[0]; @@ -60,15 +62,7 @@ class FallbackMediaHandler implements MediaHandler { list($source_file_path, $source_file_mime, $source_file_kind) = $handle; $out_path = $media_preferred_out_file_dir . DIRECTORY_SEPARATOR . $media_preferred_out_file_name . '.' . Metadata\mime_to_ext($source_file_mime); - 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'"); - } - } + $this->move_or_link_or_copy($source_file_kind, $source_file_path, $out_path); return $this->generateThumb( $handle,