Skip to content

Commit

Permalink
always set the updated_at column when marking conversions generated (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech authored Jul 20, 2023
1 parent c90dcef commit ce45100
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/MediaCollections/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function markAsConversionGenerated(string $conversionName): self

$this->generated_conversions = $generatedConversions;

$this->save();
$this->saveOrTouch();

return $this;
}
Expand All @@ -280,7 +280,7 @@ public function markAsConversionNotGenerated(string $conversionName): self

$this->generated_conversions = $generatedConversions;

$this->save();
$this->saveOrTouch();

return $this;
}
Expand Down Expand Up @@ -452,4 +452,13 @@ public function toMailAttachment(): Attachment
{
return $this->mailAttachment();
}

protected function saveOrTouch(): bool
{
if (! $this->exists || $this->isDirty()) {
return $this->save();
}

return $this->touch();
}
}
15 changes: 15 additions & 0 deletions tests/Conversions/Commands/RegenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,18 @@
expect($derivedImage2)->toBeFile();
expect($derivedImage3)->toBeFile();
});

it('can set updated_at column when regenerating', function () {
$this->travelTo('2020-01-01 00:00:00');
$media = $this->testModelWithConversion
->addMedia($this->getTestFilesDirectory('test.jpg'))
->toMediaCollection('images');

$this->travelBack();

$this->artisan('media-library:regenerate');

$media->refresh();

expect($media->updated_at)->toBeGreaterThanOrEqual(now()->subSeconds(5));
});

0 comments on commit ce45100

Please sign in to comment.