Skip to content
Open
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/Stache/Stores/BasicStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function getItem($key)
return $item;
}

if (! File::exists($path)) {
return null;
}

$item = $this->makeItemFromFile($path, File::get($path));

$this->cacheItem($item);
Expand Down
28 changes: 28 additions & 0 deletions tests/Stache/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Statamic\Facades\Collection;
use Statamic\Facades\Data;
use Statamic\Facades\Entry;
use Statamic\Facades\File;
use Statamic\Facades\GlobalSet;
use Statamic\Facades\Nav;
use Statamic\Facades\Nav as NavRepository;
Expand Down Expand Up @@ -284,6 +285,33 @@ public function saving_an_entry_writes_it_to_file()
$entry->delete();
}

#[Test]
public function it_does_not_restore_a_deleted_entry_when_its_cached_item_is_missing()
{
config(['statamic.stache.watcher' => false]);

$entry = tap(Entry::make()
->locale('en')
->id('stale-entry')
->collection(Collection::findByHandle('blog'))
->slug('stale-entry')
->date('2017-07-04')
->data(['title' => 'Stale Entry'])
)->save();

$path = $entry->path();

Entry::all();

File::delete($path);
$this->stache->cacheStore()->forget('stache::items::entries::blog::'.$entry->id());

$entries = Entry::all();

$this->assertCount(14, $entries);
$this->assertFileDoesNotExist($path);
}

#[Test]
public function saving_an_entry_with_a_closure_based_slug_resolves_it_before_writing_to_file()
{
Expand Down
Loading