Skip to content

Commit

Permalink
add dispatchMediaConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Jan 25, 2025
1 parent 713a885 commit 8141abd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
38 changes: 13 additions & 25 deletions src/Concerns/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
use Elegantly\Media\Jobs\DeleteModelMediaJob;
use Elegantly\Media\MediaCollection;
use Elegantly\Media\Models\Media;
use Elegantly\Media\Models\MediaConversion;
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;

Expand Down Expand Up @@ -246,32 +244,22 @@ public function clearMediaCollection(
}

/**
* @param int|TMedia $media
* @return \Illuminate\Support\Collection<int, \Illuminate\Foundation\Bus\PendingDispatch>
*/
public function dispatchMediaConversion(
int|Media $media,
string $conversion
): ?PendingDispatch {

$media = $media instanceof Media ? $media : $this->media->find($media);

$media->model()->associate($this);

return $media->dispatchConversion($conversion);
}

/**
* @param int|TMedia $media
*/
public function executeMediaConversion(
int|Media $media,
string $conversion
): ?MediaConversion {

$media = $media instanceof Media ? $media : $this->media->find($media);
string $conversionName,
bool $force = true,
?string $collectionName = null,
?string $collectionGroup = null,
): \Illuminate\Support\Collection {

$media->model()->associate($this);
return $this
->getMedia($collectionName, $collectionGroup)
->toBase()
->map(function ($media) use ($conversionName, $force) {
return $media->dispatchConversion($conversionName, $force);
})
->filter();

return $media->executeConversion($conversion);
}
}
20 changes: 6 additions & 14 deletions src/Contracts/InteractWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

use Elegantly\Media\MediaCollection;
use Elegantly\Media\Models\Media;
use Elegantly\Media\Models\MediaConversion;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;

Expand Down Expand Up @@ -95,18 +93,12 @@ public function clearMediaCollection(
): static;

/**
* @param int|TMedia $media
* @return \Illuminate\Support\Collection<int, \Illuminate\Foundation\Bus\PendingDispatch>
*/
public function dispatchMediaConversion(
int|Media $media,
string $conversion
): ?PendingDispatch;

/**
* @param int|TMedia $media
*/
public function executeMediaConversion(
int|Media $media,
string $conversion
): ?MediaConversion;
string $conversionName,
bool $force = true,
?string $collectionName = null,
?string $collectionGroup = null,
): \Illuminate\Support\Collection;
}

0 comments on commit 8141abd

Please sign in to comment.