From 26c465ad0c1d5b6801507ed190430f44ac92c672 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 6 Dec 2015 21:09:58 +0100 Subject: update smarty to 3.1.28-dev which fixes a bug where changes in a template are only visible on the second pageload which is annoying for developing --- .../smarty_cacheresource_keyvaluestore.php | 63 +++++++++++----------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'library/Smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php') diff --git a/library/Smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/library/Smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php index 2fdc7e42f..ee4021a19 100644 --- a/library/Smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php +++ b/library/Smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php @@ -54,7 +54,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource */ public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) { - $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); + $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . + $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); $this->populateTimestamp($cached); } @@ -81,10 +82,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource * * @param Smarty_Internal_Template $_template template object * @param Smarty_Template_Cached $cached cached object + * @param bool $update flag if called because cache update * * @return boolean true or false if the cached content does not exist */ - public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null) + public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false) { if (!$cached) { $cached = $_template->cached; @@ -121,7 +123,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource { $this->addMetaTimestamp($content); - return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']); + return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime); } /** @@ -162,7 +164,14 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource if (!$this->purge()) { $this->invalidate(null); } - + // remove from template cache + if (isset($smarty->_cache['template_objects'])) { + foreach ($smarty->_cache['template_objects'] as $key => $tpl) { + if (isset($tpl->cached)) { + unset($smarty->_cache['template_objects'][$key]); + } + } + } return - 1; } @@ -183,11 +192,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource */ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) { - $uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id); - $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id); + $uid = $this->getTemplateUid($smarty, $resource_name); + $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . + $this->sanitize($compile_id); $this->delete(array($cid)); $this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid); - + // remove from template cache + if (isset($resource_name) && isset($smarty->_cache['template_objects'])) { + if (isset($smarty->_cache['template_objects'])) { + foreach ($smarty->_cache['template_objects'] as $key => $tpl) { + if ($tpl->source->uid == $uid && isset($tpl->cached)) { + unset($smarty->_cache['template_objects'][$key]); + } + } + } + } return - 1; } @@ -196,33 +215,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource * * @param Smarty $smarty Smarty object * @param string $resource_name template name - * @param string $cache_id cache id - * @param string $compile_id compile id * * @return string filepath of cache file + * @throws \SmartyException + * */ - protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id) + protected function getTemplateUid(Smarty $smarty, $resource_name) { - $uid = ''; if (isset($resource_name)) { - $tpl = new $smarty->template_class($resource_name, $smarty); - if ($tpl->source->exists) { - $uid = $tpl->source->uid; - } - - // remove from template cache - if ($smarty->allow_ambiguous_resources) { - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; - } else { - $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; - } - if (isset($_templateId[150])) { - $_templateId = sha1($_templateId); + $source = Smarty_Template_Source::load(null, $smarty, $resource_name); + if ($source->exists) { + return $source->uid; } - unset($smarty->template_objects[$_templateId]); } - - return $uid; + return ''; } /** @@ -234,12 +240,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource */ protected function sanitize($string) { - // some poeple smoke bad weed $string = trim($string, '|'); if (!$string) { return null; } - return preg_replace('#[^\w\|]+#S', '_', $string); } @@ -397,7 +401,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource $t[] = 'IVK#COMPILE' . $_compile; } $_name .= '#'; - // some poeple smoke bad weed $cid = trim($cache_id, '|'); if (!$cid) { return $t; -- cgit v1.2.3