Skip to content

Commit

Permalink
[5.x] Fix querying by status on non-dated collections (#10099)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga authored May 16, 2024
1 parent d85f4fc commit 5a6567e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Stache/Query/QueriesEntryStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ private function addCollectionStatusLogicToQuery($query, $status, $collection):
{
$this->addCollectionWhereToStatusQuery($query, $collection->handle());

if ($collection->futureDateBehavior() === 'public' && $collection->pastDateBehavior() === 'public') {
if (! $collection->dated() || ($collection->futureDateBehavior() === 'public' && $collection->pastDateBehavior() === 'public')) {
if ($status === 'scheduled' || $status === 'expired') {
$query->where('date', 'invalid'); // intentionally trigger no results.
}

return;
}

if ($collection->futureDateBehavior() === 'private') {
Expand Down
8 changes: 8 additions & 0 deletions tests/Data/Entries/EntryQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,12 @@ public function it_filters_by_status($status, $expected)
EntryFactory::collection('calendar')->id('calendar-past')->published(true)->date(now()->subDay())->create();
EntryFactory::collection('calendar')->id('calendar-past-draft')->published(false)->date(now()->subDay())->create();

// Undated, but with customized date behavior. Nonsensical situation, but it can happen.
// See https://github.com/statamic/eloquent-driver/issues/288
Collection::make('undated')->dated(false)->futureDateBehavior('private')->pastDateBehavior('private')->save();
EntryFactory::collection('undated')->id('undated')->published(true)->create();
EntryFactory::collection('undated')->id('undated-draft')->published(false)->create();

$this->assertEquals($expected, Entry::query()->whereStatus($status)->get()->map->id->all());
}

Expand All @@ -844,13 +850,15 @@ public static function filterByStatusProvider()
'event-past-draft',
'calendar-future-draft',
'calendar-past-draft',
'undated-draft',
]],
'published' => ['published', [
'page',
'blog-past',
'event-future',
'calendar-future',
'calendar-past',
'undated',
]],
'scheduled' => ['scheduled', [
'blog-future',
Expand Down

0 comments on commit 5a6567e

Please sign in to comment.