udpate
This commit is contained in:
94
override/modules/ph_simpleblog/controllers/front/single.php
Normal file
94
override/modules/ph_simpleblog/controllers/front/single.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* Page Cache Ultimate, Page Cache standard and Speed pack are powered by Jpresta (jpresta . com)
|
||||
*
|
||||
* @author Jpresta
|
||||
* @copyright Jpresta
|
||||
* @license See the license of this module in file LICENSE.txt, thank you.
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements getJprestaModelObjectClassName() and getJprestaModelObjectId() to enable the HTML cache provided by the
|
||||
* module Page Cache Ultimate created by jpresta.com
|
||||
*/
|
||||
class PH_SimpleBlogSingleModuleFrontControllerOverride extends PH_SimpleBlogSingleModuleFrontController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !Tools::getIsset('page_cache_dynamics_mods')) {
|
||||
Hook::exec('actionJPrestaClearCache', [
|
||||
'controller' => 'ph_simpleblog__single',
|
||||
'id' => $this->getJprestaModelObjectId(),
|
||||
'delete_linking_pages' => false,
|
||||
'action_origin' => 'method-post'
|
||||
]);
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The ObjectModel class name to be used by Page Cache Ultimate module to refresh the cache of pages generated by this controller
|
||||
*/
|
||||
public static function getJprestaModelObjectClassName()
|
||||
{
|
||||
return 'SimpleBlogPost';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null The ID of the current ObjectModel (if any) to be used by Page Cache Ultimate module to refresh the cache of pages generated by this controller
|
||||
*/
|
||||
public function getJprestaModelObjectId()
|
||||
{
|
||||
// Get Post by link_rewrite
|
||||
$simpleblog_post_rewrite = Tools::getValue('rewrite');
|
||||
|
||||
if (!$simpleblog_post_rewrite || !Validate::isLinkRewrite($simpleblog_post_rewrite)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$simpleBlogPost = SimpleBlogPost::getByRewrite(
|
||||
$simpleblog_post_rewrite,
|
||||
(int) Context::getContext()->language->id,
|
||||
Tools::getValue('sb_category')
|
||||
);
|
||||
return $simpleBlogPost ? $simpleBlogPost->id : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all URLs generated by this controller for the current shop context and the specified language.
|
||||
* This is used by the Jresta-Cache-Warmer service to generate the cache of these pages.
|
||||
* @param $id_lang int ID of the language
|
||||
* @return string[] All URLs to warmup
|
||||
*/
|
||||
public static function getJprestaAllURLs($id_lang) {
|
||||
$urls = [];
|
||||
$finder = new BlogPostsFinder();
|
||||
$finder->setIdShop((int) Shop::getContextShopID());
|
||||
$finder->setIdLang($id_lang);
|
||||
$finder->setCheckForAccess(false);
|
||||
|
||||
$posts = $finder->findPosts();
|
||||
|
||||
foreach ($posts as $post) {
|
||||
$urls[] = $post['url'];
|
||||
}
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* An estimated number of URLs that will be returned by self::getJprestaAllURLs() for the current shop context.
|
||||
* Since we don't have the id_lang parameter we recommend to return the number of URLs for the language that have
|
||||
* the most URLs.
|
||||
* @return int The estimated number of URLs to warmup for the current shop context
|
||||
*/
|
||||
public static function getJprestaAllURLsCount() {
|
||||
$queryCountArticle = 'SELECT count(*) FROM `'._DB_PREFIX_.'simpleblog_post` sbp INNER JOIN `'._DB_PREFIX_.'simpleblog_post_shop` sbps ON sbp.id_simpleblog_post = sbps.id_simpleblog_post WHERE sbp.active=1 AND sbp.date_add <= \'' . SimpleBlogHelper::now(Configuration::get('PH_BLOG_TIMEZONE')) . '\' AND sbps.id_shop=' . (int) Shop::getContextShopID();
|
||||
return (int) JPresta\SpeedPack\JprestaUtils::dbGetValue($queryCountArticle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user