Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flushing of all CMS pages and blocks when products or categorie… #235

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions app/code/community/Lesti/Fpc/Model/Observer/Save.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Lesti_Fpc (http:gordonlesti.com/lestifpc)
*
Expand Down Expand Up @@ -27,6 +28,8 @@ public function catalogProductSaveAfter($observer)
$product = $observer->getEvent()->getProduct();
if ($product->getId()) {
$this->_getFpc()->clean(sha1('product_' . $product->getId()));
$this->_cleanAllCMSBlocks();
$this->_cleanAllCMSPages();

$origData = $product->getOrigData();
if (empty($origData)
Expand All @@ -52,6 +55,8 @@ public function catalogCategorySaveAfter($observer)
$category = $observer->getEvent()->getCategory();
if ($category->getId()) {
$this->_getFpc()->clean(sha1('category_' . $category->getId()));
$this->_cleanAllCMSBlocks();
$this->_cleanAllCMSPages();
}
}
}
Expand All @@ -67,7 +72,7 @@ public function cmsPageSaveAfter($observer)
$tags = array(sha1('cms_' . $page->getId()),
sha1('cms_' . $page->getIdentifier()));
$this->_getFpc()
->clean($tags, Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG);
->clean($tags);
}
}
}
Expand All @@ -84,8 +89,8 @@ public function modelSaveAfter($observer)
} elseif ($object instanceof Mage_Index_Model_Event) {
$dataObject = $object->getDataObject();
if ($object->getType() === 'mass_action' &&
$object->getEntity() === 'catalog_product' &&
$dataObject instanceof Mage_Catalog_Model_Product_Action) {
$object->getEntity() === 'catalog_product' &&
$dataObject instanceof Mage_Catalog_Model_Product_Action) {
$this->_catalogProductSaveAfterMassAction(
$dataObject->getProductIds()
);
Expand Down Expand Up @@ -156,4 +161,32 @@ protected function _catalogProductSaveAfterMassAction(array $productIds)
$this->_getFpc()->clean($tags);
}
}

/**
*
*/
protected function _cleanAllCMSPages()
{
$pages = Mage::getModel('cms/page')->getCollection();
$tags = array();
foreach ($pages as $page) {
if ($page->getId()) {
$tags = array(sha1('cms_' . $page->getId()),
sha1('cms_' . $page->getIdentifier()));
$this->_getFpc()->clean($tags);
}
}
}

protected function _cleanAllCMSBlocks()
{
$blocks = Mage::getModel('cms/block')->getCollection();
foreach ($blocks as $block) {
if ($block->getIdentifier()) {
$tags = sha1('cmsblock_' . $block->getIdentifier());
$this->_getFpc()->clean($tags);
}
}
}

}