/** * Should return list of tags to clean * * @param Mage_Cms_Model_Block $object * @return string[]|string */ protected function _collectTags($object) { if ($object instanceof Mage_Cms_Model_Block) { return self::TAG_PREFIX . $object->getIdentifier(); } return self::TAG_PREFIX . $object->getId(); }
/** * @test */ public function testCmsBlockSaveAfter() { $this->_fpc->save('page1', 'page1_cache_id', array(sha1('cmsblock_1'))); $this->_fpc->save('page2', 'page2_cache_id', array(sha1('cmsblock_2'))); $cmsBlock = new Mage_Cms_Model_Block(); $cmsBlock->setIdentifier('1'); Mage::dispatchEvent('model_save_after', array('object' => $cmsBlock)); $this->assertFalse($this->_fpc->load('page1_cache_id')); $this->assertEquals('page2', $this->_fpc->load('page2_cache_id')); }
/** * @magentoDataFixture Mage/Cms/_files/block.php * @magentoDataFixture Mage/Core/_files/variable.php * @magentoConfigFixture current_store web/unsecure/base_url http://example.com/ * @magentoConfigFixture current_store web/unsecure/base_link_url http://example.com/ */ public function testToHtml() { $cmsBlock = new Mage_Cms_Model_Block(); $cmsBlock->load('fixture_block', 'identifier'); $block = new Mage_Cms_Block_Block(); $block->setBlockId($cmsBlock->getId()); $result = $block->toHtml(); $this->assertContains('<a href="http://example.com/', $result); $this->assertContains('<p>Config value: "http://example.com/".</p>', $result); $this->assertContains('<p>Custom variable: "HTML Value".</p>', $result); }
/** * @test */ public function testCmsBlockSaveAfter() { $page1Data = new \Lesti_Fpc_Model_Fpc_CacheItem('page1', time(), 'text/html'); $this->_fpc->save($page1Data, 'page1_cache_id', array(sha1('cmsblock_1'))); $page2Data = new \Lesti_Fpc_Model_Fpc_CacheItem('page2', time(), 'text/html'); $this->_fpc->save($page2Data, 'page2_cache_id', array(sha1('cmsblock_2'))); $cmsBlock = new Mage_Cms_Model_Block(); $cmsBlock->setIdentifier('1'); Mage::dispatchEvent('model_save_after', array('object' => $cmsBlock)); $this->assertFalse($this->_fpc->load('page1_cache_id')); $this->assertEquals($page2Data, $this->_fpc->load('page2_cache_id')); }
/** * Limit CMS block save * * @param Mage_Cms_Model_Block $model */ public function cmsBlockSaveBefore($model) { $originalStoreIds = $model->getResource()->lookupStoreIds($model->getId()); if ($model->getId() && !$this->_role->hasStoreAccess($originalStoreIds)) { $this->_throwSave(); } if (!$this->_role->hasExclusiveStoreAccess($originalStoreIds)) { $this->_throwSave(); } $model->setData('stores', $this->_forceAssignToStore($this->_updateSavingStoreIds($model->getData('stores'), $originalStoreIds))); }
/** * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Cms * @subpackage integration_tests * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ $block = new Mage_Cms_Model_Block(); $block->setTitle('CMS Block Title')->setIdentifier('fixture_block')->setContent('<h1>Fixture Block Title</h1> <a href="{{store url=""}}">store url</a> <p>Config value: "{{config path="web/unsecure/base_url"}}".</p> <p>Custom variable: "{{customvar code="variable_code"}}".</p> ')->setIsActive(1)->setStores(array(Mage::app()->getStore()->getId()))->save();
private function _processBlock($identifier, Mage_Cms_Model_Block $block, $data) { $canSave = false; // Load block model if (!$block->getId()) { $block = Mage::getModel('cms/block'); $block->setIdentifier($identifier); } unset($data['contents']); if (isset($data['stores'])) { // Loop through the store view names to get its corresponding ID $storeIds = array(); foreach ($data['stores'] as $storeViewName) { $store = Mage::getModel('core/store')->load($storeViewName, 'code'); if (!$store->getId()) { throw new Exception("Store View Name: {$storeViewName} does not exist for {$identifier}"); } $storeIds[] = $store->getId(); unset($store); } unset($storeViewName); // @todo check what stores it is associated to already $oldStoreIds = Mage::getModel('cms/block')->load($block->getId())->getStoreId(); sort($storeIds); if ($oldStoreIds != $storeIds) { $canSave = true; $block->setStores($storeIds); } unset($oldStoreIds); unset($storeIds); unset($data['stores']); } else { $block->setStores(array(0)); } // Loop through block attributes foreach ($data as $key => $value) { // content file attribute would require to read it from a file if ($key == "content_file") { // If a value/path is set then get its contents if ($value != "") { // locate file path $filePath = Mage::getBaseDir() . DS . 'app' . DS . 'etc' . DS . 'components' . DS . 'html' . DS . $value; // Check if the file exists if (file_exists($filePath)) { // Get the contents of the file and save it as the value $value = file_get_contents($filePath); unset($filePath); $key = 'content'; } else { throw new Exception("No file found in {$filePath}"); } } else { continue; } } // If the value is already equal to the value in the database, skip it if ($block->getData($key) == $value) { continue; } $canSave = true; $block->setData($key, $value); $this->log("Setting block attribute {$key} to {$value} for {$identifier}"); } if ($canSave) { $block->save(); $this->log("Saved block {$identifier}"); } }
/** * @param Mage_Cms_Model_Block $block */ protected function _cmsBlockSaveAfter(Mage_Cms_Model_Block $block) { $this->_getFpc()->clean(sha1('cmsblock_' . $block->getIdentifier())); }