Skip to content

Commit

Permalink
allow sync dispatch of conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGab committed Jan 10, 2024
1 parent d076809 commit ca33594
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/Jobs/ConversionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ protected function dispatchChildrenConversions()
}

foreach ($conversion->conversions as $childConversion) {
$job = $childConversion->job;
$job->conversion = implode('.', [$this->conversion, $job->conversion]);
dispatch($job);
$childConversion->job->conversion = implode('.', [$this->conversion, $childConversion->job->conversion]);

if ($childConversion->sync) {
dispatch_sync($childConversion->job);
} else {
dispatch($childConversion->job);
}
}
}
}
6 changes: 5 additions & 1 deletion src/MediaConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

class MediaConversion
{
/**
* @param bool $sync When sync is true, dispatch_sync is used
*/
public function __construct(
public string $name,
public ConversionJob $job,
public Collection $conversions = new Collection()
public bool $sync = false,
public Collection $conversions = new Collection(),
) {
$this->conversions = $conversions->keyBy('name');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Traits/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ public function dispatchConversions(Media $media): static
$media->save();

foreach ($conversions as $conversion) {
dispatch($conversion->job);
if ($conversion->sync) {
dispatch_sync($conversion->job);
} else {
dispatch($conversion->job);
}
}

return $this;
Expand Down

0 comments on commit ca33594

Please sign in to comment.