From 40eabd834f3ea90935b10c43bcf41debd29b28d3 Mon Sep 17 00:00:00 2001 From: Thomas Steur <thomas.steur@gmail.com> Date: Wed, 29 Jan 2014 10:49:05 +0100 Subject: [PATCH] refs #4532 this should fix custom data range values are not always working. In this case periods like week, month or year were ignored in case the data range was large enough to use one of those --- core/DataAccess/ArchiveSelector.php | 46 +++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php index 1702e19969..b39829895b 100644 --- a/core/DataAccess/ArchiveSelector.php +++ b/core/DataAccess/ArchiveSelector.php @@ -151,8 +151,7 @@ class ArchiveSelector { $getArchiveIdsSql = "SELECT idsite, name, date1, date2, MAX(idarchive) as idarchive FROM %s - WHERE period = ? - AND %s + WHERE %s AND " . self::getNameCondition($plugins, $segment) . " AND idsite IN (" . implode(',', $siteIds) . ") GROUP BY idsite, date1, date2"; @@ -169,19 +168,48 @@ class ArchiveSelector foreach ($monthToPeriods as $table => $periods) { $firstPeriod = reset($periods); - // if looking for a range archive. NOTE: we assume there's only one period if its a range. - $bind = array($firstPeriod->getId()); + $bind = array(); + if ($firstPeriod instanceof Range) { - $dateCondition = "date1 = ? AND date2 = ?"; + $dateCondition = "period = ? AND date1 = ? AND date2 = ?"; + $bind[] = $firstPeriod->getId(); $bind[] = $firstPeriod->getDateStart()->toString('Y-m-d'); $bind[] = $firstPeriod->getDateEnd()->toString('Y-m-d'); - } else { // if looking for a normal period - $dateStrs = array(); + } else { + // we assume there is no range date in $periods + $dateStrs = array(); + $dayPeriod = null; + $dateCondition = '('; + foreach ($periods as $period) { - $dateStrs[] = $period->getDateStart()->toString('Y-m-d'); + if ($period instanceof Period\Day) { + $dateStrs[] = $period->getDateStart()->toString('Y-m-d'); + $dayPeriod = $period; + } } - $dateCondition = "date1 IN ('" . implode("','", $dateStrs) . "')"; + if (!empty($dayPeriod) && !empty($dateStrs)) { + $bind[] = $dayPeriod->getId(); + $dateCondition .= "(period = ? AND date1 IN ('" . implode("','", $dateStrs) . "'))"; + } + + reset($periods); + foreach ($periods as $period) { + if ($period instanceof Period\Week || $period instanceof Period\Month || $period instanceof Period\Year) { + + if (strlen($dateCondition) > 5) { + $dateCondition .= ' OR '; + } + + $dateCondition .= "(period = ? AND date1 = ? AND date2 = ?)"; + $bind[] = $period->getId(); + $bind[] = $period->getDateStart()->toString('Y-m-d'); + $bind[] = $period->getDateEnd()->toString('Y-m-d'); + } + } + + $dateCondition .= ')'; + } $sql = sprintf($getArchiveIdsSql, $table, $dateCondition); -- GitLab