From 24ee3830c23f7147f82febe3d3c6743d5ae8d4e6 Mon Sep 17 00:00:00 2001 From: Jonas L Date: Wed, 27 Dec 2023 17:32:33 +0100 Subject: [PATCH] fix(legacy): ensure last played criteria works with never played files (#2840) ### Description Closes #2798 COALESCE last played null values with date -infinity, to ensure newly added files are found by the last played smart block criteria. --- legacy/application/models/Block.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/legacy/application/models/Block.php b/legacy/application/models/Block.php index e2248a7b7..343f8d476 100644 --- a/legacy/application/models/Block.php +++ b/legacy/application/models/Block.php @@ -1689,31 +1689,22 @@ SQL; // need to pull in the current time and subtract the value or figure out how to make it relative $relativedate = new DateTime($spCriteriaValue); $dt = $relativedate->format(DateTime::ISO8601); - // Logging::info($spCriteriaValue); - $spCriteriaValue = "{$spCriteria} <= '{$dt}'"; + $spCriteriaValue = "COALESCE({$spCriteria}, DATE '-infinity') <= '{$dt}'"; } elseif ($spCriteriaModifier == 'after') { $relativedate = new DateTime($spCriteriaValue); $dt = $relativedate->format(DateTime::ISO8601); - // Logging::info($spCriteriaValue); - $spCriteriaValue = "{$spCriteria} >= '{$dt}'"; + $spCriteriaValue = "COALESCE({$spCriteria}, DATE '-infinity') >= '{$dt}'"; } elseif ($spCriteriaModifier == 'between') { $fromrelativedate = new DateTime($spCriteriaValue); $fdt = $fromrelativedate->format(DateTime::ISO8601); - // Logging::info($fdt); $torelativedate = new DateTime($spCriteriaExtra); $tdt = $torelativedate->format(DateTime::ISO8601); - // Logging::info($tdt); - $spCriteriaValue = "{$spCriteria} >= '{$fdt}' AND {$spCriteria} <= '{$tdt}'"; + $spCriteriaValue = "COALESCE({$spCriteria}, DATE '-infinity') >= '{$fdt}' AND COALESCE({$spCriteria}, DATE '-infinity') <= '{$tdt}'"; } - // logging::info('before'); - // logging::info($spCriteriaModifier); $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; - // logging::info('after'); - // logging::info($spCriteriaModifier); - try { if ($spCriteria == 'owner_id') { $spCriteria = 'subj.login';