From 8d7ccb4d3f4feeb7631bf5f3fabee9f7a1ad3712 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 28 Aug 2017 12:32:07 +0200 Subject: [PATCH] Change cache path and get configuration variable to not use cache --- .../privatesales/controllers/front/home.php | 36 +++++++++++++------ modules/privatesales/models/SaleCache.php | 14 +++++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/modules/privatesales/controllers/front/home.php b/modules/privatesales/controllers/front/home.php index 2016f784..a5f17ab3 100644 --- a/modules/privatesales/controllers/front/home.php +++ b/modules/privatesales/controllers/front/home.php @@ -8,7 +8,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { /** - * + * */ public function init(){ @@ -31,12 +31,12 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { } /** - * + * */ public function initContent(){ if(!$this->context->cookie->logged && !Configuration::get('PRIVATESALES_LISTING_PUBLIC')){ Tools::redirect($this->context->link->getPageLink('authentication',null,$this->context->cookie->id_lang,'ps=0&back='.$this->context->link->getModuleLink('privatesales', 'home'))); - } + } $news = null; if(Tools::getValue('type') == "nouveautes"){ @@ -50,10 +50,24 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { $this->setTemplate('privatesales-home.tpl'); // 12613 - Optimisation - $sale_cache = new SaleCache($this->context, "home", 7200, $news); // 2 Hours - if ($sale_cache->isCached($this->template)) { - $this->setCacheHtml($sale_cache->getCache()); - return; + if(Configuration::get('PS_SMARTY_CACHE') == 1) { + $lifetime = 7200; + switch (Configuration::get('PS_SMARTY_FORCE_COMPILE')) { + case 0: + case 1: + $lifetime = 7200; + break; + case 2: + $lifetime = 0; + break; + } + if ($lifetime > 0) { + $sale_cache = new SaleCache($this->context, "home", $lifetime, $news); + if ($sale_cache->isCached($this->template)) { + $this->setCacheHtml($sale_cache->getCache()); + return; + } + } } // 12613 - End optimisation @@ -75,7 +89,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { else $pastsales = array(); - if(Configuration::get('PRIVATESALES_FUTURESALES')) + if(Configuration::get('PRIVATESALES_FUTURESALES')) $futuresales = SaleCore::getSales("future",Configuration::get('PRIVATESALES_FUTURELIMIT'), TRUE, FALSE, TRUE, 'date_start', 'ASC'); else $futuresales = array(); @@ -100,7 +114,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { $now = $now->format('Y-m-d H:i:s'); $slider = array(); - for ($i=1; $i < 6; $i++) { + for ($i=1; $i < 6; $i++) { if (Configuration::get('PRIVATESALES_SLIDER_ACTIVE_'.$i)) { $date_start = Configuration::get('PRIVATESALES_SLIDER_DATE_START_'.$i); $date_end = Configuration::get('PRIVATESALES_SLIDER_DATE_END_'.$i); @@ -109,7 +123,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { (empty($date_start) && $date_end >= $now) || (empty($date_end) && $date_start <= $now) || ($date_start <= $now && $date_end >= $now) - ) + ) { $slider[] = array( 'title' => Configuration::get('PRIVATESALES_SLIDER_TITLE_'.$i), @@ -167,7 +181,7 @@ class privatesaleshomeModuleFrontController extends ModuleFrontController { 'banner_concour_title_2' => Configuration::get('PRIVATESALES_BANNER_TITLE_CONCOURS_2'), 'banner_concour_link_active' => Configuration::get('PRIVATESALES_BANNER_LINK_CONCOURS_ACTIVE'), )); - } + } diff --git a/modules/privatesales/models/SaleCache.php b/modules/privatesales/models/SaleCache.php index 1df562a8..05836007 100644 --- a/modules/privatesales/models/SaleCache.php +++ b/modules/privatesales/models/SaleCache.php @@ -6,7 +6,7 @@ class SaleCache private $smarty = null; private $max_filemtime = 0; private $template_path = ''; - private $path_cache_file = ''; + private $path_cache = ''; function __construct(Context $context, $cache_prefix, $lifetime, $is_sales_news = null) { @@ -32,7 +32,13 @@ class SaleCache $this->cache_id = md5("private_sales_".$cache_prefix."_".$d->format('Ymd')); $this->max_filemtime = $d->getTimestamp() - $lifetime; - $this->path_cache_file = __DIR__.'/../cache/'.$this->cache_id; + + $path_cache = _PS_CACHE_DIR_.'smarty/cache/privatesales'; + if (!file_exists($path_cache)) { + mkdir($path_cache, 0755); + } + $this->path_cache_file = $path_cache.'/'.$this->cache_id; + $this->smarty = $context->smarty; } @@ -78,7 +84,7 @@ class SaleCache $slider = array(); - for ($i=1; $i < 6; $i++) { + for ($i=1; $i < 6; $i++) { if (Configuration::get('PRIVATESALES_SLIDER_ACTIVE_'.$i)) { $date_start = Configuration::get('PRIVATESALES_SLIDER_DATE_START_'.$i); $date_end = Configuration::get('PRIVATESALES_SLIDER_DATE_END_'.$i); @@ -87,7 +93,7 @@ class SaleCache (empty($date_start) && $date_end >= $now) || (empty($date_end) && $date_start <= $now) || ($date_start <= $now && $date_end >= $now) - ) + ) { $slider[] = 'slider/slider_'.$i.'_'.Configuration::get('PRIVATESALES_SLIDER_TITLEIMG_'.$i).'.png'; }