diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index 63bfb36d..1cadb11b 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -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(), @@ -101,7 +107,7 @@ public function metaExists() 'container' => $this->containerHandle(), 'folder' => $this->folder(), 'basename' => $this->basename(), - ])->count() > 0; + ])->exists(); }); } diff --git a/src/Assets/AssetContainerContents.php b/src/Assets/AssetContainerContents.php index 24191f79..7fe075e4 100644 --- a/src/Assets/AssetContainerContents.php +++ b/src/Assets/AssetContainerContents.php @@ -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; } diff --git a/tests/Assets/AssetTest.php b/tests/Assets/AssetTest.php index 232a942b..58ecb9b7 100644 --- a/tests/Assets/AssetTest.php +++ b/tests/Assets/AssetTest.php @@ -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-')); + } }