From 242556e176502ec61271a3945e1337917bc88f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Mon, 9 Sep 2013 15:12:26 +0200 Subject: [PATCH] [-] MO: Fix unifunc smarty errors if module is displayed on multiplehook without cache --- classes/module/Module.php | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/classes/module/Module.php b/classes/module/Module.php index 0dfdd6535..79ec715c1 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -118,6 +118,9 @@ abstract class ModuleCore /** @var Smarty_Data */ protected $smarty; + + /** @var currentSmartySubTemplate */ + protected $current_subtemplate = null; const CACHE_FILE_MODULES_LIST = '/config/xml/modules_list.xml'; @@ -1653,20 +1656,35 @@ abstract class ModuleCore if ($cacheId !== null) Tools::enableCache(); - $smarty_subtemplate = $this->context->smarty->createTemplate( - $this->getTemplatePath($template), - $cacheId, - $compileId, - $this->smarty - ); - $result = $smarty_subtemplate->fetch(); + $result = $this->getCurrentSubTemplate($template, $cacheId, $compileId)->fetch(); if ($cacheId !== null) Tools::restoreCacheSettings(); + $this->resetCurrentSubTemplate($template, $cacheId, $compileId); + return $result; } } + + protected function getCurrentSubTemplate($template, $cache_id = null, $compile_id = null) + { + if (!isset($this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id])) + { + $this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id] = $this->context->smarty->createTemplate( + $this->getTemplatePath($template), + $cache_id, + $compile_id, + $this->smarty + ); + } + return $this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id]; + } + + protected function resetCurrentSubTemplate($template, $cache_id, $compile_id) + { + $this->current_subtemplate[$template.'_'.$cache_id.'_'.$compile_id] = null; + } /** * Get realpath of a template of current module (check if template is overriden too) @@ -1696,10 +1714,8 @@ abstract class ModuleCore public function isCached($template, $cacheId = null, $compileId = null) { - $context = Context::getContext(); - Tools::enableCache(); - $is_cached = $context->smarty->isCached($this->getTemplatePath($template), $cacheId, $compileId); + $is_cached = $this->getCurrentSubTemplate($this->getTemplatePath($template), $cacheId, $compileId)->isCached($this->getTemplatePath($template), $cacheId, $compileId); Tools::restoreCacheSettings(); return $is_cached;