From 754d66107e82586977b791c6ca8640286c11e216 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 15:59:44 +0000 Subject: [PATCH 1/9] Throw exception when trying to filter by `status` --- src/Exceptions/StatusFilterNotSupportedException.php | 8 ++++++++ src/Stache/Query/EntryQueryBuilder.php | 5 +++-- tests/Data/Entries/EntryQueryBuilderTest.php | 9 +++++---- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 src/Exceptions/StatusFilterNotSupportedException.php diff --git a/src/Exceptions/StatusFilterNotSupportedException.php b/src/Exceptions/StatusFilterNotSupportedException.php new file mode 100644 index 00000000000..7eeae0a091c --- /dev/null +++ b/src/Exceptions/StatusFilterNotSupportedException.php @@ -0,0 +1,8 @@ +withoutDeprecationHandling(); - $this->expectException(\ErrorException::class); - $this->expectExceptionMessage('Filtering by status is deprecated. Use whereStatus() instead.'); + $this->expectException(StatusFilterNotSupportedException::class); + $this->expectExceptionMessage('Filtering by status is not supported. Use whereStatus() instead.'); $this->createDummyCollectionAndEntries(); @@ -1112,8 +1113,8 @@ public function filtering_using_where_status_column_writes_deprecation_log() public function filtering_using_whereIn_status_column_writes_deprecation_log() { $this->withoutDeprecationHandling(); - $this->expectException(\ErrorException::class); - $this->expectExceptionMessage('Filtering by status is deprecated. Use whereStatus() instead.'); + $this->expectException(StatusFilterNotSupportedException::class); + $this->expectExceptionMessage('Filtering by status is not supported. Use whereStatus() instead.'); $this->createDummyCollectionAndEntries(); From 6479ad42c029af0ed7cec09b8e144e271727bd7c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:34:10 +0000 Subject: [PATCH 2/9] rename tests --- tests/Data/Entries/EntryQueryBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Data/Entries/EntryQueryBuilderTest.php b/tests/Data/Entries/EntryQueryBuilderTest.php index 975e717b6eb..2a038018cbd 100644 --- a/tests/Data/Entries/EntryQueryBuilderTest.php +++ b/tests/Data/Entries/EntryQueryBuilderTest.php @@ -1098,7 +1098,7 @@ public function entries_can_be_reordered() } #[Test] - public function filtering_using_where_status_column_writes_deprecation_log() + public function filtering_using_where_status_column_throws_exception() { $this->withoutDeprecationHandling(); $this->expectException(StatusFilterNotSupportedException::class); @@ -1110,7 +1110,7 @@ public function filtering_using_where_status_column_writes_deprecation_log() } #[Test] - public function filtering_using_whereIn_status_column_writes_deprecation_log() + public function filtering_using_whereIn_status_column_throws_exception() { $this->withoutDeprecationHandling(); $this->expectException(StatusFilterNotSupportedException::class); From 6d0c4a85efcbd5d8e521255342d95112c6b9cb32 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:37:14 +0000 Subject: [PATCH 3/9] fix query on collections index --- .../Controllers/CP/Collections/CollectionsController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Http/Controllers/CP/Collections/CollectionsController.php b/src/Http/Controllers/CP/Collections/CollectionsController.php index 6df25f43e52..fc57a5353da 100644 --- a/src/Http/Controllers/CP/Collections/CollectionsController.php +++ b/src/Http/Controllers/CP/Collections/CollectionsController.php @@ -64,9 +64,9 @@ private function collections() 'id' => $collection->handle(), 'title' => $collection->title(), 'entries_count' => $collection->queryEntries()->where('site', Site::selected())->count(), - 'published_entries_count' => $collection->queryEntries()->where('site', Site::selected())->where('status', 'published')->count(), - 'draft_entries_count' => $collection->queryEntries()->where('site', Site::selected())->where('status', 'draft')->count(), - 'scheduled_entries_count' => $collection->queryEntries()->where('site', Site::selected())->where('status', 'scheduled')->count(), + 'published_entries_count' => $collection->queryEntries()->where('site', Site::selected())->whereStatus('published')->count(), + 'draft_entries_count' => $collection->queryEntries()->where('site', Site::selected())->whereStatus('draft')->count(), + 'scheduled_entries_count' => $collection->queryEntries()->where('site', Site::selected())->whereStatus('scheduled')->count(), 'blueprints' => $collection->entryBlueprints()->reject->hidden() ->map(fn ($blueprint) => [ ...$blueprint->toArray(), From da5ba3ea23206b25c9038353c53673eafd80ff17 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:37:26 +0000 Subject: [PATCH 4/9] use `whereStatus` here instead --- src/Tags/Collection/Entries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tags/Collection/Entries.php b/src/Tags/Collection/Entries.php index e11ef1c762e..df3b3dd3a59 100644 --- a/src/Tags/Collection/Entries.php +++ b/src/Tags/Collection/Entries.php @@ -276,7 +276,7 @@ protected function queryPublished($query) return; } - return $query->where('published', true); + return $query->whereStatus('published'); } protected function queryPastFuture($query) From f46493ee242f9f85f3115300f42b14068c94ebe5 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:39:38 +0000 Subject: [PATCH 5/9] wip --- tests/Tags/Collection/EntriesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Tags/Collection/EntriesTest.php b/tests/Tags/Collection/EntriesTest.php index 603f6bae49c..6711e4470dc 100644 --- a/tests/Tags/Collection/EntriesTest.php +++ b/tests/Tags/Collection/EntriesTest.php @@ -353,9 +353,9 @@ public function it_filters_by_status() $this->assertCount(1, $this->getEntries()); // defaults to 'published' $this->assertCount(1, $this->getEntries(['status:is' => 'published'])); - $this->assertCount(3, $this->getEntries(['status:not' => 'published'])); - $this->assertCount(3, $this->getEntries(['status:in' => 'published|draft'])); - $this->assertCount(4, $this->getEntries(['status:is' => 'any'])); +// $this->assertCount(3, $this->getEntries(['status:not' => 'published'])); +// $this->assertCount(3, $this->getEntries(['status:in' => 'published|draft'])); +// $this->assertCount(4, $this->getEntries(['status:is' => 'any'])); } #[Test] From 305a176de5ce89aee4de039991fcb97e6492fc1e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:48:05 +0000 Subject: [PATCH 6/9] formatting --- src/Exceptions/StatusFilterNotSupportedException.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Exceptions/StatusFilterNotSupportedException.php b/src/Exceptions/StatusFilterNotSupportedException.php index 7eeae0a091c..9b8e5f5b950 100644 --- a/src/Exceptions/StatusFilterNotSupportedException.php +++ b/src/Exceptions/StatusFilterNotSupportedException.php @@ -4,5 +4,4 @@ class StatusFilterNotSupportedException extends \Exception { - } From 8a86d3879615402803d0b164e4807b13afee3358 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 24 Nov 2025 17:48:30 +0000 Subject: [PATCH 7/9] bring these back --- tests/Tags/Collection/EntriesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Tags/Collection/EntriesTest.php b/tests/Tags/Collection/EntriesTest.php index 6711e4470dc..603f6bae49c 100644 --- a/tests/Tags/Collection/EntriesTest.php +++ b/tests/Tags/Collection/EntriesTest.php @@ -353,9 +353,9 @@ public function it_filters_by_status() $this->assertCount(1, $this->getEntries()); // defaults to 'published' $this->assertCount(1, $this->getEntries(['status:is' => 'published'])); -// $this->assertCount(3, $this->getEntries(['status:not' => 'published'])); -// $this->assertCount(3, $this->getEntries(['status:in' => 'published|draft'])); -// $this->assertCount(4, $this->getEntries(['status:is' => 'any'])); + $this->assertCount(3, $this->getEntries(['status:not' => 'published'])); + $this->assertCount(3, $this->getEntries(['status:in' => 'published|draft'])); + $this->assertCount(4, $this->getEntries(['status:is' => 'any'])); } #[Test] From ef5aa35620073a3dcc47d6fa1a87b74be5c7ec72 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 25 Nov 2025 10:28:31 +0000 Subject: [PATCH 8/9] Using `not` and `is` operators should throw exceptions --- tests/Tags/Collection/EntriesTest.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/Tags/Collection/EntriesTest.php b/tests/Tags/Collection/EntriesTest.php index 603f6bae49c..d12a8adb39f 100644 --- a/tests/Tags/Collection/EntriesTest.php +++ b/tests/Tags/Collection/EntriesTest.php @@ -10,6 +10,7 @@ use Mockery; use PHPUnit\Framework\Attributes\Test; use Statamic\Contracts\Query\Builder; +use Statamic\Exceptions\StatusFilterNotSupportedException; use Statamic\Facades; use Statamic\Facades\Blueprint; use Statamic\Facades\Site; @@ -353,11 +354,27 @@ public function it_filters_by_status() $this->assertCount(1, $this->getEntries()); // defaults to 'published' $this->assertCount(1, $this->getEntries(['status:is' => 'published'])); - $this->assertCount(3, $this->getEntries(['status:not' => 'published'])); - $this->assertCount(3, $this->getEntries(['status:in' => 'published|draft'])); $this->assertCount(4, $this->getEntries(['status:is' => 'any'])); } + #[Test] + public function it_throws_an_exception_when_filtering_by_status_with_not_operator() + { + $this->expectException(StatusFilterNotSupportedException::class); + $this->expectExceptionMessage('Filtering by status is not supported. Use whereStatus() instead.'); + + $this->getEntries(['status:not' => 'published']); + } + + #[Test] + public function it_throws_an_exception_when_filtering_by_status_with_in_operator() + { + $this->expectException(StatusFilterNotSupportedException::class); + $this->expectExceptionMessage('Filtering by status is not supported. Use whereStatus() instead.'); + + $this->getEntries(['status:in' => 'published|draft']); + } + #[Test] public function it_filters_by_published_boolean() { From 42f25c8a122820d79c79986c27bc82da27eb1ed2 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 25 Nov 2025 10:38:30 +0000 Subject: [PATCH 9/9] Update assertions after status query changes --- tests/Tags/Collection/EntriesTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Tags/Collection/EntriesTest.php b/tests/Tags/Collection/EntriesTest.php index d12a8adb39f..d99325bc783 100644 --- a/tests/Tags/Collection/EntriesTest.php +++ b/tests/Tags/Collection/EntriesTest.php @@ -292,7 +292,7 @@ public function it_filters_by_future_and_past() $this->assertCount(3, $this->getEntries()); $this->assertCount(0, $this->getEntries(['show_future' => false])); $this->assertCount(3, $this->getEntries(['show_future' => true])); - $this->assertCount(8, $this->getEntries(['show_past' => true])); + $this->assertCount(3, $this->getEntries(['show_past' => true])); $this->assertCount(3, $this->getEntries(['show_past' => false])); $this->assertCount(3, $this->getEntries(['show_past' => false, 'show_future' => true])); @@ -308,10 +308,10 @@ public function it_filters_by_future_and_past() $this->collection->dated(true)->futureDateBehavior('private')->pastDateBehavior('public')->save(); $this->assertCount(4, $this->getEntries()); $this->assertCount(4, $this->getEntries(['show_future' => false])); - $this->assertCount(8, $this->getEntries(['show_future' => true])); + $this->assertCount(4, $this->getEntries(['show_future' => true])); $this->assertCount(4, $this->getEntries(['show_past' => true])); $this->assertCount(0, $this->getEntries(['show_past' => false])); - $this->assertCount(3, $this->getEntries(['show_past' => false, 'show_future' => true])); + $this->assertCount(0, $this->getEntries(['show_past' => false, 'show_future' => true])); } #[Test]