From 72dd4db37a9ff2bcbf83075f34243d8ac2c2bf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 13 Oct 2016 12:50:27 +0300 Subject: [PATCH] calculate lastmodified to be maximum accurate the time() may be incorrect if there's slight delay between file modify and cache write. but as file modify is what is important, rely on that. also needed to use different cache file because the format change. --- lib/Minify/LessCssSource.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/Minify/LessCssSource.php b/lib/Minify/LessCssSource.php index 1e3fa1b..249f9dc 100644 --- a/lib/Minify/LessCssSource.php +++ b/lib/Minify/LessCssSource.php @@ -30,7 +30,7 @@ class Minify_LessCssSource extends Minify_Source { public function getLastModified() { $cache = $this->getCache(); - return $cache['updated']; + return $cache['lastModified']; } /** @@ -70,12 +70,29 @@ class Minify_LessCssSource extends Minify_Source { $cache = $less->cachedCompile($input); if (!is_array($input) || $cache['updated'] > $input['updated']) { + $cache['lastModified'] = $this->getMaxLastModified($cache); $this->cache->store($cacheId, serialize($cache)); } return $this->parsed = $cache; } + /** + * Calculate maximum last modified of all files, + * as the 'updated' timestamp in cache is not the same as file last modified timestamp: + * @link https://github.com/leafo/lessphp/blob/v0.4.0/lessc.inc.php#L1904 + * @return int + */ + private function getMaxLastModified($cache) + { + $lastModified = 0; + foreach ($cache['files'] as $mtime) { + $lastModified = max($lastModified, $mtime); + } + + return $lastModified; + } + /** * Make a unique cache id for for this source. * @@ -86,7 +103,7 @@ class Minify_LessCssSource extends Minify_Source { private function getCacheId($prefix = 'minify') { $md5 = md5($this->filepath); - return "{$prefix}_less_{$md5}"; + return "{$prefix}_less2_{$md5}"; } /**