From e8685b1430c19779760d2b102c095b70a092afd2 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Tue, 13 Aug 2013 15:11:00 +0200 Subject: [PATCH] [*] BO : Add clear smarty cache button --- .../controllers/performance/helpers/form/form.tpl | 3 +++ classes/Tools.php | 12 ++++++++++++ controllers/admin/AdminPerformanceController.php | 7 +++++++ install-dev/models/install.php | 14 +------------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl index b62fc272c..5e9db0548 100644 --- a/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl @@ -40,6 +40,9 @@ {/if} {$smarty.block.parent} + {if $input.type == 'radio' && $input.name == 'smarty_cache'} + {l s='Clear Smarty cache'} + {/if} {/block} {block name="description"} diff --git a/classes/Tools.php b/classes/Tools.php index 802cf391b..10e8d712e 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -704,6 +704,18 @@ class ToolsCore } return false; } + + /** + * Clear smarty cache folders + */ + public static function clearSmartyCache() + { + foreach (array(_PS_CACHE_DIR_.'smarty/cache', _PS_CACHE_DIR_.'smarty/compile') as $dir) + if (file_exists($dir)) + foreach (scandir($dir) as $file) + if ($file[0] != '.' && $file != 'index.php') + self::deleteDirectory($dir.DIRECTORY_SEPARATOR.$file); + } /** * Display an error according to an error code diff --git a/controllers/admin/AdminPerformanceController.php b/controllers/admin/AdminPerformanceController.php index ef4bd674e..798e1912d 100644 --- a/controllers/admin/AdminPerformanceController.php +++ b/controllers/admin/AdminPerformanceController.php @@ -791,6 +791,13 @@ class AdminPerformanceControllerCore extends AdminController else $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } + + if ((bool)Tools::getValue('empty_smarty_cache')) + { + $redirectAdmin = true; + Tools::clearSmartyCache(); + } + if ($redirectAdmin && (!isset($this->errors) || !count($this->errors))) { Hook::exec('action'.get_class($this).ucfirst($this->action).'After', array('controller' => $this, 'return' => '')); diff --git a/install-dev/models/install.php b/install-dev/models/install.php index fb491fbb2..e652d8528 100644 --- a/install-dev/models/install.php +++ b/install-dev/models/install.php @@ -368,7 +368,7 @@ class InstallModelInstall extends InstallAbstractModel public function configureShop(array $data = array()) { // Clear smarty cache - $this->clearSmartyCache(); + Tools::clearSmartyCache(); //clear image cache in tmp folder Tools::deleteDirectory(_PS_TMP_IMG_DIR_, false); @@ -494,18 +494,6 @@ class InstallModelInstall extends InstallAbstractModel return true; } - /** - * Clear smarty cache folders - */ - public function clearSmartyCache() - { - foreach (array(_PS_CACHE_DIR_.'smarty/cache', _PS_CACHE_DIR_.'smarty/compile') as $dir) - if (file_exists($dir)) - foreach (scandir($dir) as $file) - if ($file[0] != '.' && $file != 'index.php') - Tools::deleteDirectory($dir.DIRECTORY_SEPARATOR.$file); - } - public function getModulesList() { // @todo REMOVE DEV MODE