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/Repositories/CollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public function save(Collection $collection)
{
$this->store->save($collection);

if ($collection->isDirty('sites')) {
$this->stache->store('entries')->store($collection->handle())->clear();
}

if ($collection->orderable()) {
$this->stache->store('entries')->store($collection->handle())->index('order')->update();
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Data/Entries/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,36 @@ public function it_saves_quietly()
Event::assertNotDispatched(CollectionSaving::class);
}

#[Test]
public function it_only_queries_entries_in_the_sites_it_was_saved_with()
{
// Like a real cache, hand out copies. The plain array store would hand back
// the collection being saved itself, and fetching it resets its dirty state.
config([
'cache.stores.stache-serializing' => ['driver' => 'array', 'serialize' => true],
'statamic.stache.cache_store' => 'stache-serializing',
]);

$this->setSites([
'en' => ['url' => '/', 'locale' => 'en_US'],
'fr' => ['url' => '/fr/', 'locale' => 'fr_FR'],
]);

$collection = tap(Facades\Collection::make('test')->sites(['en', 'fr']))->save();
Facades\Entry::make()->collection('test')->locale('en')->id('en-entry')->slug('en-entry')->save();
Facades\Entry::make()->collection('test')->locale('fr')->id('fr-entry')->slug('fr-entry')->save();

$queried = [];
Event::listen(CollectionSaved::class, function ($event) use (&$queried) {
$queried[] = $event->collection->queryEntries()->get()->map->id()->sort()->values()->all();
});

$collection->sites(['en'])->save();
$collection->sites(['en', 'fr'])->save();

$this->assertEquals([['en-entry'], ['en-entry', 'fr-entry']], $queried);
}

#[Test]
public function it_dispatches_collection_saved()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/GraphQL/EntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public function it_queries_all_entries()
#[Test]
public function it_queries_all_entries_in_a_specific_site()
{
$this->createEntries();

$this->setSites([
'en' => ['url' => 'http://localhost/', 'locale' => 'en'],
'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'],
]);

$this->createEntries();

Collection::find('events')->routes('/events/{slug}')->sites(['en', 'fr'])->save();

EntryFactory::collection('events')->locale('fr')->origin('4')->id('44')->slug('event-two')->create();
Expand Down
15 changes: 10 additions & 5 deletions tests/Feature/GraphQL/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Facades\Statamic\CP\LivePreview;
use Facades\Statamic\Fields\BlueprintRepository;
use Facades\Tests\Factories\EntryFactory;
use Orchestra\Testbench\Attributes\DefineEnvironment;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
Expand Down Expand Up @@ -269,13 +270,9 @@ public function it_queries_an_entry_by_uri()
}

#[Test]
#[DefineEnvironment('useMultipleSites')]
public function it_queries_an_entry_in_a_specific_site()
{
$this->setSites([
'en' => ['url' => 'http://localhost/', 'locale' => 'en'],
'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'],
]);

Collection::find('events')->routes('/events/{slug}')->sites(['en', 'fr'])->save();

EntryFactory::collection('events')->locale('fr')->origin('4')->id('44')->slug('event-two')->create();
Expand Down Expand Up @@ -625,6 +622,14 @@ public function adding_custom_field_to_an_implementation_does_not_add_it_to_the_
]]]);
}

protected function useMultipleSites()
{
$this->setSites([
'en' => ['url' => 'http://localhost/', 'locale' => 'en'],
'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'],
]);
}

private function createStructuredCollection()
{
$collection = Collection::find('events');
Expand Down
Loading