diff --git a/src/Definitions/MediaConversionAudio.php b/src/Definitions/MediaConversionAudio.php index f880855..e3132b4 100644 --- a/src/Definitions/MediaConversionAudio.php +++ b/src/Definitions/MediaConversionAudio.php @@ -54,10 +54,13 @@ public function shouldExecute(Media $media, ?MediaConversion $parent): bool public function handle( Media $media, ?MediaConversion $parent, - string $file, + ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory ): ?MediaConversion { + if (! $file) { + return null; + } $fileName = $this->fileName ?? "{$media->name}.mp3"; diff --git a/src/Definitions/MediaConversionDefinition.php b/src/Definitions/MediaConversionDefinition.php index 2238700..8fc127d 100644 --- a/src/Definitions/MediaConversionDefinition.php +++ b/src/Definitions/MediaConversionDefinition.php @@ -17,7 +17,7 @@ class MediaConversionDefinition /** * @param bool $immediate Determine if the conversion should be dispatched immediatly after `addMedia` * @param MediaConversionDefinition[] $conversions - * @param Closure(Media $media, ?MediaConversion $parent, string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory): ?MediaConversion $handle + * @param Closure(Media $media, ?MediaConversion $parent, ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory): ?MediaConversion $handle * @param null|bool|Closure(Media $media, ?MediaConversion $parent): bool $when */ public function __construct( @@ -37,7 +37,7 @@ public function __construct( public function handle( Media $media, ?MediaConversion $parent, - string $file, + ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory ): ?MediaConversion { @@ -80,18 +80,10 @@ public function execute(Media $media, ?MediaConversion $parent): ?MediaConversio $source = $parent ?? $media; - if (! $source->path) { - return null; - } - - $copy = $source->copyFileTo( + $copy = $source->path ? $source->copyFileTo( disk: $storage, path: $source->path - ); - - if (! $copy) { - return null; - } + ) : null; return $this->handle($media, $parent, $copy, $storage, $temporaryDirectory); diff --git a/src/Definitions/MediaConversionImage.php b/src/Definitions/MediaConversionImage.php index 14c47c4..cf4b2b9 100644 --- a/src/Definitions/MediaConversionImage.php +++ b/src/Definitions/MediaConversionImage.php @@ -55,10 +55,13 @@ public function shouldExecute(Media $media, ?MediaConversion $parent): bool public function handle( Media $media, ?MediaConversion $parent, - string $file, + ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory ): ?MediaConversion { + if (! $file) { + return null; + } $fileName = $this->fileName ?? "{$media->name}.jpg"; diff --git a/src/Definitions/MediaConversionPoster.php b/src/Definitions/MediaConversionPoster.php index 896c15c..0242f63 100644 --- a/src/Definitions/MediaConversionPoster.php +++ b/src/Definitions/MediaConversionPoster.php @@ -57,10 +57,13 @@ public function shouldExecute(Media $media, ?MediaConversion $parent): bool public function handle( Media $media, ?MediaConversion $parent, - string $file, + ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory ): ?MediaConversion { + if (! $file) { + return null; + } $fileName = $this->fileName ?? "{$media->name}.jpg"; diff --git a/src/Definitions/MediaConversionVideo.php b/src/Definitions/MediaConversionVideo.php index 9df4c2c..a10c5ba 100644 --- a/src/Definitions/MediaConversionVideo.php +++ b/src/Definitions/MediaConversionVideo.php @@ -58,11 +58,15 @@ public function shouldExecute(Media $media, ?MediaConversion $parent): bool public function handle( Media $media, ?MediaConversion $parent, - string $file, + ?string $file, Filesystem $filesystem, SpatieTemporaryDirectory $temporaryDirectory ): ?MediaConversion { + if (! $file) { + return null; + } + $fileName = $this->fileName ?? "{$media->name}.mp4"; $source = $parent ?? $media; diff --git a/src/Models/MediaConversion.php b/src/Models/MediaConversion.php index fc77352..9506056 100644 --- a/src/Models/MediaConversion.php +++ b/src/Models/MediaConversion.php @@ -23,8 +23,6 @@ use Illuminate\Support\Str; /** - * @template TMedia of Media - * * @property int $id * @property string $uuid * @property string $conversion_name @@ -85,7 +83,7 @@ public static function booted() } /** - * @return BelongsTo + * @return BelongsTo */ public function media(): BelongsTo {