Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Fix asset meta file not being deleted with asset #9300

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ public function meta($key = null)
return $this->metaValue($key);
}

if (! $this->exists()) {
return $this->generateMeta();
}

if (! config('statamic.assets.cache_meta')) {
return $this->generateMeta();
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ public function it_checks_if_an_extension_matches()
public function it_gets_the_extension_guessed_extension_and_mime_type()
{
Storage::fake('test');
Storage::disk('test')->put('foo.mp4a', '');
Storage::disk('test')->put('.meta/foo.mp4a.yaml', YAML::dump(['mime_type' => 'audio/mp4']));

$container = Facades\AssetContainer::make('test')->disk('test');
Expand Down Expand Up @@ -720,6 +721,23 @@ public function it_properly_merges_new_unsaved_data_to_meta()
$this->assertEquals($expectedAfterMerge, $asset->meta());
}

/** @test */
public function it_does_not_write_to_meta_file_when_asset_does_not_exist()
{
Storage::fake('test');

$container = Facades\AssetContainer::make('test')->disk('test');
$asset = (new Asset)->container($container)->path('foo/test.txt');

// No meta file should exist yet...
$this->assertFalse(Storage::disk('test')->exists('foo/.meta/test.txt.yaml'));

// Calling `meta` should return an empty meta array, but not write a meta file...
$meta = $asset->meta();
$this->assertEquals(['data' => []], $meta);
$this->assertFalse(Storage::disk('test')->exists('foo/.meta/test.txt.yaml'));
}

/** @test */
public function it_gets_meta_path()
{
Expand Down Expand Up @@ -1398,6 +1416,7 @@ public function it_gets_dimensions_for_svgs()
public function it_gets_no_ratio_when_height_is_zero()
{
Storage::fake('test');
Storage::disk('test')->put('image.jpg', '');
Storage::disk('test')->put('.meta/image.jpg.yaml', YAML::dump(['width' => '30', 'height' => '0']));

$container = Facades\AssetContainer::make('test')->disk('test');
Expand Down Expand Up @@ -2163,6 +2182,7 @@ public function it_syncs_original_state_with_no_data()
/** @test */
public function it_syncs_original_state_with_no_data_but_with_data_in_meta()
{
Storage::disk('test')->put('path/to/test.txt', '');
Storage::disk('test')->put('path/to/.meta/test.txt.yaml', "data:\n foo: bar");
$asset = (new Asset)->container($this->container)->path('path/to/test.txt');

Expand Down Expand Up @@ -2191,6 +2211,7 @@ public function it_syncs_original_state_with_no_data_but_with_data_in_meta()
/** @test */
public function it_syncs_original_state_with_data()
{
Storage::disk('test')->put('path/to/test.txt', '');
$yaml = <<<'YAML'
data:
alfa: bravo
Expand Down Expand Up @@ -2232,6 +2253,7 @@ public function it_syncs_original_state_with_data()
/** @test */
public function it_resolves_pending_original_meta_values_when_hydrating()
{
Storage::disk('test')->put('path/to/test.txt', '');
$yaml = <<<'YAML'
data:
alfa: bravo
Expand Down
Loading