Skip to content

Commit

Permalink
Move date check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed May 15, 2024
1 parent ce617bd commit 101356a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Stache/Query/QueriesEntryStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ public function whereStatus(string $status)

return $this->where(fn ($query) => $this
->getCollectionsForStatusQuery()
->filter(fn ($collection) => $collection->dated())
->each(fn ($collection) => $query->orWhere(fn ($q) => $this->addCollectionStatusLogicToQuery($q, $status, $collection))));
}

private function addCollectionStatusLogicToQuery($query, $status, $collection): void
{
$this->addCollectionWhereToStatusQuery($query, $collection->handle());

if (! $collection->dated()) {
if ($status !== 'published') {
$query->where('date', 'invalid'); // intentionally trigger no results.
}

return;
}

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

0 comments on commit 101356a

Please sign in to comment.