пятница, 30 ноября 2012 г.

Interesting facts about Full Page Cache in Magento.

1.
File: 'app/code/core/Enterprise/PageCache/Model/Processor.php'

const XML_PATH_CACHE_MAX_SIZE       = 'system/page_cache/max_cache_size';

Method: public function processRequestResponse(Zend_Controller_Request_Http $request, Zend_Controller_Response_Http $response)

$maxSizeInBytes = Mage::getStoreConfig(self::XML_PATH_CACHE_MAX_SIZE) * 1024 * 1024;


if ($currentStorageSize >= $maxSizeInBytes) {
    Mage::app()->getCacheInstance()->invalidateType('full_page');
    return $this;
}


By default 'max_cache_size' = 1Gb.


2. Magento 1.7 CE and 1.12 EE has a bug.
'cache_lifetime' option in 'cache.xml' is not used by Magento. It means that if something was cached it won't be rendered whenever.

There is a way how to fix it.

Create your module.
Rewrite the class 'Enterprise_PageCache_Model_Config'.

This is an example of 'etc/config.xml' file for your module.


    <global>
        <models>
            <you_entpagecache>
                <class>YOU_EnterprisePageCache_Model</class>
            </you_entpagecache>
            <enterprise_pagecache>
                <rewrite>
                    <config>YOU_EnterprisePageCache_Model_Config</config>
                </rewrite>
            </enterprise_pagecache>
        </models>
    </global>


This is a new class 'YOU_EnterprisePageCache_Model_Config' without the bug.

class YOU_EnterprisePageCache_Model_Config  extends Enterprise_PageCache_Model_Config
{
    /**
     * Create placeholder object based on block information
     *
     * @param Mage_Core_Block_Abstract $block
     * @return Enterprise_PageCache_Model_Container_Placeholder
     */
    public function getBlockPlaceholder($block)
    {
        $this->_initPlaceholders();
        $type = $block->getType();

        if (isset($this->_placeholders[$type])) {
            $placeholderData = false;
            foreach ($this->_placeholders[$type] as $placeholderInfo) {
                if (!empty($placeholderInfo['name'])) {
                    if ($placeholderInfo['name'] == $block->getNameInLayout()) {
                        $placeholderData = $placeholderInfo;
                    }
                } else {
                    $placeholderData = $placeholderInfo;
                }
            }

            if (!$placeholderData) {
                return false;
            }

            $placeholder = $placeholderData['code']
                . ' container="' . $placeholderData['container'] . '"'
                . ' block="' . get_class($block) . '"';
            $placeholder.= ' cache_id="' . $block->getCacheKey() . '"';
            foreach ($block->getCacheKeyInfo() as $k => $v) {
                if (is_string($k) && !empty($k)) {
                    $placeholder .= ' ' . $k . '="' . $v . '"';
                }
            }
            // Fixed bug -- 'cache_lifetime' is not used for checking that block should be rendered because it is expired.
            $placeholder .= ' cache_lifetime="' . $placeholderData['cache_lifetime'] . '"';

            $placeholder = Mage::getModel('enterprise_pagecache/container_placeholder', $placeholder);
            return $placeholder;
        }
        return false;
    }
}

пятница, 28 сентября 2012 г.

Magento HowTo. Part1

How to

  • Enable/Disable Reviews
    • Manually in Backend
      • System->Configuration->Advanced:Advanced->Disable Modules Output->Mage_Review
        • Enable/Disable
    • In the code (code example):
      • $store = Mage::app()->getStore('davitamon');
      • Mage::getModel('core/config')->saveConfig('advanced/modules_disable_output/Mage_Review', '0' , 'stores', $store->getId());


четверг, 6 сентября 2012 г.

Using readline with Oracle SQL*Plus

This is repost of the following link:
http://blog.cachemiss.com/articles/Using%20readline%20with%20Oracle%20SQL*Plus.pod



By default, Oracle's SQL*Plus has no support for history, command line editing, etc.

This problem can be solved with the rlwrap utility. There is a Debian package, or you can easily compile it for any system.

Source is here: http://utopia.knoware.nl/~hlub/rlwrap/.

Once installed, add this alias to your .bashrc:

alias sqlplus="rlwrap -i -f ~/.sqlplus_history -H ~/.sqlplus_history -s 30000 sqlplus"

This defines a history file and uses it as your completion wordlist, and sets the history size to 30000 entries.

Before running it for the first time, do a:

touch ~/.sqlplus_history

That's all there is to it, and now you have readline support in your SQL*Plus!

How to create a new website/store/storeview in Magento (code snippet)

This is an example of install/upgrade script for creating a new website/store/storeview in Magento.
Also prefixes for order/invoice/shipment numbers are set.


<?php>
try {

    $websiteName = 'Website Name';
    $websiteCode = 'website_code';
    $storeName = 'Store Name';
    $storeViewName = 'Store View Name';
    //$rootCategoryName = 'Website Name Root Category';


    /** @var $installer Mage_Catalog_Model_Resource_Setup */
    $installer = $this;

    /** @var $write Zend_Db_Adapter_Abstract */
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');

    $write->beginTransaction();

//    // Create root category
//    /**  @var Mage_Catalog_Model_Category $rootCategory */
//    $rootCategory = Mage::getModel('catalog/category');
//    $rootCategory->setName($rootCategoryName)
//        ->setDisplayMode('PRODUCTS')
//        ->setIsActive(1)
//        ->setPath('1')
//        ->setStoreId(0)
//    ;
//    //$rootCategory->setThumbnail(null);
//
//    $rootCategory->save();


    // Create website
    /** @var Mage_Core_Model_WebsiРte $website */
    $website = Mage::getModel('core/website');
    $website
        ->setName($websiteName)
        ->setCode($websiteCode)
        ->save();

    // Create Store
    /** @var Mage_Core_Model_Store_Group $store  */
    $store = Mage::getModel('core/store_group');
    $store
        ->setWebsiteId($website->getId())
        ->setName($storeName)
        // Error happened 'exception 'Exception' with message '$_FILES array is empty' in src/lib/Varien/File/Uploader.php:467' when this line is uncommented.
        //->setRootCategoryId($rootCategory->getId())
        ->save();

    // Set relations to Store in Website
    $website->setDefaultGroupId($store->getId());


    // Crate Store View
    /** @var Mage_Core_Model_Store $storeView  */
    $storeView = Mage::getModel('core/store');
    $storeView
        ->setName($storeViewName)
        ->setCode($websiteCode)
        ->setWebsiteId($website->getId())
        ->setGroupId($store->getId())
        ->setIsActive(1)
        ->save();

    // Set relations to StoreView in Store.
    $store->setDefaultStoreId($storeView->getId());
    /** @var $config Mage_Core_Model_Config */
    $config = Mage::getModel('core/config');

    // Set store name
    $config->saveConfig(Mage_Core_Model_Store::XML_PATH_STORE_STORE_NAME, $websiteName, 'stores', $storeView->getId());


    // Add prefix for orders (5), invoices(6), shipments(8)
    $write->query("
        insert into `eav_entity_store` (entity_type_id, store_id, increment_prefix, increment_last_id)
        values
        (5, {$storeView->getId()}, 3, 300000000),
        (6, {$storeView->getId()}, 3, 300000000),
        (8, {$storeView->getId()}, 3, 300000000)
    ");

    $write->commit();

} catch (Exception $e) {
    $write->rollback();
    Mage::throwException($e);
}