From 22b5fcfe2b27adc9430d40646dad97c7b7bbd78d Mon Sep 17 00:00:00 2001 From: Francois Suter Date: Wed, 4 Apr 2012 15:21:52 +0200 Subject: [PATCH] [BUGFIX] Page cache expiry calculation fails The calculation of the page cache expirationy timestamp based on property config.cache.xx = table:yy fails in some specific scenarios, name when there are records having either a start time in the future but no end time, or an end time in the future and no start time. Contrary to what is being done so far, calculation must be performed separately for each time field to avoid interferences. Change-Id: I4e4e259083a10f7125760d14ede11ff6a68022fe Fixes: #35684 Releases: 6.0, 4.7, 4.6 Reviewed-on: http://review.typo3.org/10156 Reviewed-by: Philipp Gampe Reviewed-by: Wouter Wolters Reviewed-by: Jigal van Hemert Tested-by: Jigal van Hemert Reviewed-by: Xavier Perseguers Reviewed-by: Francois Suter Tested-by: Francois Suter --- typo3/sysext/cms/tslib/class.tslib_fe.php | 49 +++++++---------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/typo3/sysext/cms/tslib/class.tslib_fe.php b/typo3/sysext/cms/tslib/class.tslib_fe.php index 329c2d23279f..7b3401e32ef6 100644 --- a/typo3/sysext/cms/tslib/class.tslib_fe.php +++ b/typo3/sysext/cms/tslib/class.tslib_fe.php @@ -4748,46 +4748,25 @@ if (version == "n3") { $showHidden = ($tableName === 'pages' ? $this->showHiddenPage : $this->showHiddenRecords); $enableFields = $this->sys_page->enableFields($tableName, $showHidden, array('starttime' => TRUE, 'endtime' => TRUE)); - // saves the name of the starttime and endtime field in $tableName (if defined) - $timeFields = array(); - // saves the SELECT parts of the SQL query - $selectFields = array(); - // saves the WHERE parts of the SQL query - $whereConditions = array(); - + // For each start or end time field, get the minimum value foreach (array('starttime', 'endtime') as $field) { - // there is no need to load TCA because we need only enable columns! + // Note: there is no need to load TCA because we need only enable columns! if (isset($GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns'][$field])) { - $timeFields[$field] = $GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns'][$field]; - $selectFields[$field] = 'MIN(' . $timeFields[$field] . ') AS ' . $field; - $whereConditions[$field] = $timeFields[$field] . '>' . $now; - } - } - - // if starttime or endtime are defined, evaluate them - if (count($timeFields)) { - // find the timestamp, when the current page's content changes the next time - $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( - // MIN(starttime) AS starttime, MIN(endtime) AS endtime - implode(', ', $selectFields), - $tableName, - // pid=$pid AND starttime>$now AND $endtime>$now . $enablefields - 'pid=' . intval($pid) . ' AND (' . implode(' OR ', $whereConditions) . ')' . $enableFields - ); - if ($row) { - foreach ($timeFields as $timeField => $_) { - // if a MIN value is found, take it into account for the cache lifetime - // we have to filter out start/endtimes < $now, as the SQL query also returns - // rows with starttime < $now and endtime > $now (and using a starttime from the past - // would be wrong) - if (!is_null($row[$timeField]) && $row[$timeField] > $now) { - $result = min($result, $row[$timeField]); - } + $timeField = $GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns'][$field]; + $selectField = 'MIN(' . $timeField . ') AS ' . $field; + $whereCondition = $timeField . ' > ' . $now; + // Find the smallest timestamp which could influence the cache duration (but is larger than 0) + $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( + $selectField, + $tableName, + 'pid = ' . intval($pid) . ' AND ' . $whereCondition . $enableFields + ); + if ($row && !is_null($row[$timeField])) { + $result = min($result, $row[$timeField]); } } } - return $result; } } -?> \ No newline at end of file +?> -- 2.20.1