Skip to content

Commit 2ca2cd0

Browse files
Allow regenerate to queue all conversions (#3793)
* Allow regenerate to queue all conversions * Better naming * Update RegenerateCommand.php --------- Co-authored-by: Freek Van der Herten <[email protected]>
1 parent d8517f3 commit 2ca2cd0

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/Conversions/Commands/RegenerateCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class RegenerateCommand extends Command
2222
{--X|exclude-starting-id : Exclude the provided id when regenerating from a specific id}
2323
{--only-missing : Regenerate only missing conversions}
2424
{--with-responsive-images : Regenerate responsive images}
25-
{--force : Force the operation to run when in production}';
25+
{--force : Force the operation to run when in production}
26+
{--queue-all : Queue all conversions, even non-queued ones}';
2627

2728
protected $description = 'Regenerate the derived images of media';
2829

@@ -56,7 +57,8 @@ public function handle(MediaRepository $mediaRepository, FileManipulator $fileMa
5657
$media,
5758
Arr::wrap($this->option('only')),
5859
$this->option('only-missing'),
59-
$this->option('with-responsive-images')
60+
$this->option('with-responsive-images'),
61+
$this->option('queue-all'),
6062
);
6163
} catch (Exception $exception) {
6264
$this->errorMessages[$media->getKey()] = $exception->getMessage();

src/Conversions/FileManipulator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function createDerivedFiles(
1818
Media $media,
1919
array $onlyConversionNames = [],
2020
bool $onlyMissing = false,
21-
bool $withResponsiveImages = false
21+
bool $withResponsiveImages = false,
22+
bool $queueAll = false,
2223
): void {
2324
if (! $this->canConvertMedia($media)) {
2425
return;
@@ -33,7 +34,7 @@ public function createDerivedFiles(
3334
return in_array($conversion->getName(), $onlyConversionNames);
3435
})
3536
->filter(fn (Conversion $conversion) => $conversion->shouldBePerformedOn($media->collection_name))
36-
->partition(fn (Conversion $conversion) => $conversion->shouldBeQueued());
37+
->partition(fn (Conversion $conversion) => $queueAll || $conversion->shouldBeQueued());
3738

3839
$this
3940
->performConversions($conversions, $media, $onlyMissing)

tests/Conversions/Commands/RegenerateCommandTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Illuminate\Support\Facades\Queue;
4+
use Spatie\MediaLibrary\Conversions\Jobs\PerformConversionsJob;
35
use Spatie\MediaLibrary\Tests\TestSupport\TestModels\TestModelWithConversion;
46

57
it('can regenerate all files', function () {
@@ -364,3 +366,19 @@
364366

365367
expect($media->updated_at)->toBeGreaterThanOrEqual(now()->subSeconds(5));
366368
});
369+
370+
it('can force queue non-queued conversions', function () {
371+
Queue::fake();
372+
373+
$media = $this->testModelWithConversion
374+
->addMedia($this->getTestFilesDirectory('test.jpg'))
375+
->toMediaCollection('images');
376+
377+
unlink($thumbConversion = $this->getMediaDirectory("{$media->id}/conversions/test-thumb.jpg"));
378+
379+
$this->artisan('media-library:regenerate', ['--queue-all' => true]);
380+
381+
$this->assertFileDoesNotExist($this->getMediaDirectory($thumbConversion));
382+
383+
Queue::assertPushed(PerformConversionsJob::class);
384+
});

0 commit comments

Comments
 (0)