Skip to content

Commit

Permalink
run conversion even if file is null
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Oct 18, 2024
1 parent 5cb6605 commit 820e038
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/Definitions/MediaConversionAudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
16 changes: 4 additions & 12 deletions src/Definitions/MediaConversionDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -37,7 +37,7 @@ public function __construct(
public function handle(
Media $media,
?MediaConversion $parent,
string $file,
?string $file,
Filesystem $filesystem,
SpatieTemporaryDirectory $temporaryDirectory
): ?MediaConversion {
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/Definitions/MediaConversionImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
5 changes: 4 additions & 1 deletion src/Definitions/MediaConversionPoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
6 changes: 5 additions & 1 deletion src/Definitions/MediaConversionVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/Models/MediaConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
use Illuminate\Support\Str;

/**
* @template TMedia of Media
*
* @property int $id
* @property string $uuid
* @property string $conversion_name
Expand Down Expand Up @@ -85,7 +83,7 @@ public static function booted()
}

/**
* @return BelongsTo<TMedia, MediaConversion>
* @return BelongsTo<Media, MediaConversion>
*/
public function media(): BelongsTo
{
Expand Down

0 comments on commit 820e038

Please sign in to comment.