setTemplate('clearcache.tpl'); } else { $this->setTemplate('module:pagecache/views/templates/front/clearcache.tpl'); } $result = 'Not OK'; if (JprestaUtils::isModuleEnabled("pagecache")) { $token = Tools::getValue('token', ''); $goodToken = JprestaUtils::getSecurityToken(); if (!$goodToken || strcmp($goodToken, $token) === 0) { if (Tools::getIsset('nbHourExpired')) { header("HTTP/1.0 404 Not Found"); $result = 'Parameter nbHourExpired is not supported anymore, the cache is now reduced continuously, this CRON is not necessary anymore.'; } else { $delete_linking_pages = (bool) Tools::getValue('delete_linking_pages', true); $is_specific = false; $is_purge = Tools::getIsset('purge'); foreach (PageCache::getManagedControllersNames() as $controller) { if (Tools::getIsset($controller)) { // It's not a global reset $is_specific = true; if (strcmp($controller, 'index') === 0 || strcmp($controller, 'newproducts') === 0 || strcmp($controller, 'bestsales') === 0 || strcmp($controller, 'pricesdrop') === 0 || strcmp($controller, 'sitemap') === 0 || strcmp($controller, 'contact') === 0 || strcmp($controller, 'sitemap') === 0 ) { // No ids for this controller //echo "Deleting $controller
"; PageCacheDAO::clearCacheOfObject($controller, false, false, 'from CRON'); } else { $ids_str = Tools::getValue($controller); $ids = self::parseIds($ids_str); if (empty($ids)) { PageCacheDAO::clearCacheOfObject($controller, false, $delete_linking_pages, 'from CRON'); } else { foreach ($ids as $id) { // Delete object one after the other //echo "Deleting $controller # $id
"; PageCacheDAO::clearCacheOfObject($controller, $id, $delete_linking_pages, 'from CRON'); } } } } } $result = 'OK'; if ($is_purge) { // Purge the cache $module = Module::getInstanceByName("pagecache"); $module->purgeCache(Shop::getContextShopID(), 'cron' . (PageCache::isCacheWarmer() ? ' CW' : '')); if (PageCache::isCacheWarmer()) { // Reduce the size of the response to the minimum (save bandwidth and time) if (!headers_sent()) { // Here our cache-warmer/status-checker do not care about these headers, just remove them header_remove(); // Indicates that there is no content so it removes "Content-Length" and "Content-Type" headers header("HTTP/1.1 204 PURGED"); // Unset PHP session (to avoid a useless cookie) session_abort(); // Don't send any cookies Context::getContext()->cookie->disallowWriting(); } die(); } } elseif (!$is_specific) { // Clear the whole cache $module = Module::getInstanceByName("pagecache"); $module->clearCache('cron'); } } } else { header("HTTP/1.0 404 Not Found"); $result = 'Not OK: bad token ' . $token; } } else { $result = 'Not OK: module not active'; } $this->context->smarty->assign(array( 'result' => $result )); } public function getLayout() { return _PS_MODULE_DIR_ . 'pagecache/views/templates/front/layout.tpl'; } /** * @param string $ids Comma separated list of IDs * @return multitype:number Array of ID */ private function parseIds($ids) { $ids_array = array(); if (!empty($ids)) { $ids_str = explode(',', $ids); foreach ($ids_str as $id_str) { $id = (int) $id_str; if ($id > 0) { $ids_array[] = $id; } } } return $ids_array; } }