diff --git a/src/Stache/Indexes/Submissions/Site.php b/src/Stache/Indexes/Submissions/Site.php new file mode 100644 index 00000000000..05b229f6824 --- /dev/null +++ b/src/Stache/Indexes/Submissions/Site.php @@ -0,0 +1,13 @@ +site()->handle(); + } +} diff --git a/src/Stache/Stores/FormSubmissionsStore.php b/src/Stache/Stores/FormSubmissionsStore.php index 4660f869168..8b617164b8b 100644 --- a/src/Stache/Stores/FormSubmissionsStore.php +++ b/src/Stache/Stores/FormSubmissionsStore.php @@ -7,6 +7,7 @@ use Statamic\Facades\FormSubmission; use Statamic\Facades\Path; use Statamic\Facades\YAML; +use Statamic\Stache\Indexes; use Statamic\Stache\Indexes\Value; use Statamic\Support\Str; use Statamic\Yaml\ParseException; @@ -18,6 +19,7 @@ class FormSubmissionsStore extends ChildStore protected $storeIndexes = [ 'form', 'date', + 'site' => Indexes\Submissions\Site::class, ]; public function getItemKey($item) diff --git a/tests/Forms/SubmissionQueryBuilderTest.php b/tests/Forms/SubmissionQueryBuilderTest.php index 1395fb0fabb..45c5095842e 100644 --- a/tests/Forms/SubmissionQueryBuilderTest.php +++ b/tests/Forms/SubmissionQueryBuilderTest.php @@ -7,6 +7,8 @@ use Statamic\Contracts\Forms\Submission; use Statamic\Facades\Form; use Statamic\Facades\FormSubmission; +use Statamic\Facades\Site; +use Statamic\Facades\Stache; use Tests\PreventSavingStacheItemsToDisk; use Tests\TestCase; @@ -506,6 +508,25 @@ public function it_filters_by_site() $this->assertEquals(['b', 'c'], $this->ids(FormSubmission::query()->where('site', 'fr')->get())); $this->assertEquals(['a'], $this->ids(FormSubmission::query()->where('site', 'en')->get())); + $this->assertEquals(['b', 'c'], $this->ids(FormSubmission::query()->where('site', Site::get('fr'))->get())); + } + + #[Test] + public function it_stores_site_handles_in_the_site_index() + { + $this->setSites([ + 'en' => ['url' => '/'], + 'fr' => ['url' => '/fr'], + ]); + + $form = tap(Form::make('test'))->save(); + $en = tap(FormSubmission::make()->form($form)->site('en'))->save(); + $fr = tap(FormSubmission::make()->form($form)->site('fr'))->save(); + + $this->assertSame([ + "test::{$en->id()}" => 'en', + "test::{$fr->id()}" => 'fr', + ], Stache::store('form-submissions')->store('test')->index('site')->items()->all()); } #[Test]