From 017120c1efe592a6799aa2d716b6d587666fd39a Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 15 Dec 2015 03:37:13 +0100 Subject: [PATCH] - bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828) --- change_log.txt | 3 ++- libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_cacheresource.php | 9 +++------ .../smarty_internal_extension_clear.php | 8 -------- .../smarty_internal_method_clearallcache.php | 5 +---- .../smarty_internal_method_clearcache.php | 5 +---- ...rty_internal_method_clearcompiledtemplate.php | 16 ++++------------ 7 files changed, 12 insertions(+), 36 deletions(-) diff --git a/change_log.txt b/change_log.txt index 7e178dfa..dda0647f 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,8 @@  ===== 3.1.29-dev ===== (xx.xx.2015) 15.12.2015 - bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122 - + - bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828) + 14.12.2015 - bugfix {$smarty.config.foo} broken in 3.1.28 https://github.com/smarty-php/smarty/issues/120 - bugfix multiple calls of {section} with same name droped E_NOTICE error https://github.com/smarty-php/smarty/issues/118 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 0e275c80..c0628524 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.29-dev/4'; + const SMARTY_VERSION = '3.1.29-dev/5'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_cacheresource.php b/libs/sysplugins/smarty_cacheresource.php index 8cd2805a..14ab62fd 100644 --- a/libs/sysplugins/smarty_cacheresource.php +++ b/libs/sysplugins/smarty_cacheresource.php @@ -215,12 +215,9 @@ abstract class Smarty_CacheResource */ public function invalidLoadedCache(Smarty $smarty) { - if (isset($smarty->_cache['template_objects'])) { - foreach ($smarty->_cache['template_objects'] as $key => $tpl) { - if (isset($tpl->cached)) { - unset ($smarty->_cache['template_objects'][$key]); - } - } + $smarty->_cache['isCached'] = array(); + if (isset($smarty->ext->_subtemplate)) { + $smarty->ext->_subtemplate->tplObjects = array(); } } } diff --git a/libs/sysplugins/smarty_internal_extension_clear.php b/libs/sysplugins/smarty_internal_extension_clear.php index c595214d..00edc5ab 100644 --- a/libs/sysplugins/smarty_internal_extension_clear.php +++ b/libs/sysplugins/smarty_internal_extension_clear.php @@ -114,14 +114,6 @@ class Smarty_Internal_Extension_Clear } } } - // remove from template cache - if (isset($smarty->_cache['template_objects'])) { - foreach ($smarty->_cache['template_objects'] as $key => $tpl) { - if (isset($tpl->cached) && $tpl->cached->filepath == (string) $_file) { - unset($smarty->_cache['template_objects'][$key]); - } - } - } $_count += @unlink((string) $_file) ? 1 : 0; if (function_exists('opcache_invalidate')) { opcache_invalidate((string) $_file); diff --git a/libs/sysplugins/smarty_internal_method_clearallcache.php b/libs/sysplugins/smarty_internal_method_clearallcache.php index 1fe37892..6ae0af15 100644 --- a/libs/sysplugins/smarty_internal_method_clearallcache.php +++ b/libs/sysplugins/smarty_internal_method_clearallcache.php @@ -34,10 +34,7 @@ class Smarty_Internal_Method_ClearAllCache { // load cache resource and call clearAll $_cache_resource = Smarty_CacheResource::load($smarty, $type); - if ($smarty->caching_type != 'file') { - $_cache_resource->invalidLoadedCache($smarty); - } - + $_cache_resource->invalidLoadedCache($smarty); return $_cache_resource->clearAll($smarty, $exp_time); } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearcache.php b/libs/sysplugins/smarty_internal_method_clearcache.php index a923b3ae..063c57cd 100644 --- a/libs/sysplugins/smarty_internal_method_clearcache.php +++ b/libs/sysplugins/smarty_internal_method_clearcache.php @@ -37,10 +37,7 @@ class Smarty_Internal_Method_ClearCache { // load cache resource and call clear $_cache_resource = Smarty_CacheResource::load($smarty, $type); - if ($smarty->caching_type != 'file' && !isset($template_name)) { - $_cache_resource->invalidLoadedCache($smarty); - } - + $_cache_resource->invalidLoadedCache($smarty); return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time); } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php index ae100323..cce8553f 100644 --- a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php +++ b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php @@ -107,13 +107,6 @@ class Smarty_Internal_Method_ClearCompiledTemplate } if ($unlink && @unlink($_filepath)) { - if (isset($smarty->_cache['template_objects'])) { - foreach ($smarty->_cache['template_objects'] as $key => $tpl) { - if (isset($tpl->compiled) && $tpl->compiled->filepath == $_filepath) { - unset($smarty->_cache['template_objects'][$key]); - } - } - } $_count ++; if (function_exists('opcache_invalidate')) { opcache_invalidate($_filepath); @@ -121,11 +114,10 @@ class Smarty_Internal_Method_ClearCompiledTemplate } } } - // clear compiled cache - if (!isset($resource_name) && isset($smarty->_cache['source_objects'])) { - foreach ($smarty->_cache['source_objects'] as $source) { - $source->compileds = array(); - } + // clear template objects cache + $smarty->_cache['isCached'] = array(); + if (isset($smarty->ext->_subtemplate)) { + $smarty->ext->_subtemplate->tplObjects = array(); } return $_count; }