Skip to content
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
8 changes: 7 additions & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function meta($key = null)
return $meta;
}

// this handles asset::make() without save()
// e.g. when checking a file exists already when uploading
if (! $this->disk()->exists($this->path())) {
return ['data' => []];
}

return Blink::once($this->metaCacheKey(), function () {
if ($model = app('statamic.eloquent.assets.model')::where([
'container' => $this->containerHandle(),
Expand Down Expand Up @@ -101,7 +107,7 @@ public function metaExists()
'container' => $this->containerHandle(),
'folder' => $this->folder(),
'basename' => $this->basename(),
])->count() > 0;
])->exists();
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Assets/AssetContainerContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function add($path)
$this->add($dir);
}

$this->folders->push(['path' => $path]);
$this->folders->push(['path' => $path, 'type' => 'dir']);

return $this;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Assets/AssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,21 @@ public function saving_an_asset_clears_the_eloquent_blink_cache()

$this->assertFalse(Facades\Blink::has("eloquent-asset-{$asset->id()}"));
}

#[Test]
public function making_an_asset_without_saving_doesnt_make_a_meta_exists_blink_cache_entry()
{
Facades\Blink::flush();

$this->assertCount(0, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));

Storage::disk('test')->put('test.jpg', '');
$asset = Facades\Asset::make()->container('test')->path('test.jpg');

$this->assertCount(0, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));

$asset->save();

$this->assertCount(1, Facades\Blink::allStartingWith('eloquent-asset-meta-exists-'));
}
}