linux – how to exclude some specified files/folders when creating tar ball file

when you want to create a new tar ball file from a folder,you may don’t need all contents in the target you don’t need all the zip or psd file in the folder,then you can use the –exlude option of tar to skip those file,

tar -cvzf bak.tar.gz /home/user1/data –exclude “*.zip”
tar -cvzf bak.tar.gz /home/user1/data –exclude “*.zip” –exclude “*.psd”

if you need to skip some folder,then you can

tar -cvzf bak.tar.gz /home/user1/data –exclude “/home/user1/data/cache”
if you are now in the /home/user1,
tar -cvzf bak.tar.gz  ./data –exclude “./cache”

keep in mind that never add any trailing slash to the end of the path of –exclude,this will make –exclude useless. when specify a path for –exclude option,make sure the path start from the same path same as the the tar destination. that’s why when we use absolute path,the –exclude option start from /,when tar work in /home/user1, –exclude start from “./” (which same as ./data)

tar -cvzf bak.tar.gz /home/user1/data –exclude “/home/user1/data/cache/”
the bak.tar.gz will still contain the cache folder.

tar -cvzf bak.tar.gz /home/user1/data –exclude “data/cache/”  # not work
tar -cvzf bak.tar.gz  ./data –exclude “/home/user1/data/cache” # not work


magento — how to check product page or category page?

you may need to do some specific work when magento are in product page,and not show some content in category list to check ?

// if this is a product view page
if (Mage::registry(‘product’)) {
// get collection of categories this product is associated with
$categories = Mage::registry(‘product’)->getCategoryCollection()
->setPage(1, 1)

from the last block code from magento, when Mage::registry(‘product’) is not null,magento are work in product view page.

if (!$this->_currentCategoryKey) {
$category = Mage::registry(‘current_category’);
if ($category) {
$this->_currentCategoryKey = $category->getPath();

obviously, if Mage::registry(‘current_category’) is set and not null,then we are in category page.but,this not work in all version of magento.we can extend magento in its core to set some status variable for test.Mage::registry will be a good way to do this job.


How to override a Magento function

How to override a Global Magento function which was defined in app/code/core/Mage/Core/functions.php? With the help of magento override system,we can easily ovrride any global function defined in the function.php by make a copy of this file to app/code/local/Mage/Core/ the new file,do whatever changes you want.when magento call a function,it will use the definition in the new file.Kee in mind that code in the local code pool always takes precedence over that in the core pool.this is the way magento works always.

read more from:

magento – Magento Service Temporarily Unavailable

If your magento website got this error page,

Service Temporarily Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

don’t be too worried!First,make sure you don’t put your magento store in maintenance mode.If Magento sees a file named maintenance.flag in the magento store root directory, it will automatically redirect all requests to the magento default 503 error page. This can be used  to prevent users from accessing the store during magento upgrades. To revert your magento store back to production mode,just delete/rename the maintenance.flag file.

However, this error page may also be caused by magento upgrade. If you tried to install magento theme/template/module,magento would temporally put magento store in maintenance mode if it needs to upgrade magento. if the upgrade didn’t finish successfully,it won’t revert the magento store back to production mode.If so,you only need to remove the maintenance.flag to get control back to magento backend. Remove the extension/plugins you installed,it will be ok.


magento – how to rewrite a model class to extend magento feature

To add  or extend magento core feature, we need to make changes to magento code.however,we would not want to change the code directly.To make our code be compatible with magento next release,we’d better make use of magento build in way to extend magento functionality.

To rewrite a magento existing core model,we have two choice.The first one is based upon php include path.Let’s take a look at magento code:

if (defined(‘COMPILER_INCLUDE_PATH’)) {
set_include_path($appPath . PS . Mage::registry(‘original_include_path’));
include_once “Mage_Core_functions.php”;
include_once “Varien_Autoload.php”;
} else {
* Set include path
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘local’;
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘community’;
$paths[] = BP . DS . ‘app’ . DS . ‘code’ . DS . ‘core’;
$paths[] = BP . DS . ‘lib’;

$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry(‘original_include_path’));
include_once “Mage/Core/functions.php”;
include_once “Varien/Autoload.php”;

with the include_path configuration set,magento will search first at the local code pool,then community and core code we can just copy the file which contain the class you want to change from the core code pool to local code pool,and do whatever changes you want.For example,to rewrite the product model class,just copy core/Mage/Catalog/Model/Product.php to local/Mage/Catalog/Model/Product.php.Although the changes we made would keep when we update magento, we still lost the new updated/added feature.

magento has another powerful way to change its core code.this is magento another override mechanism.let’s take a look how it works.

when we try to get a model instance,we call Mage:getModel ,ie $p = Mage:getModel(‘catalog/product’); The real logic is implemented in the getGroupedClassName method of Mage_Core_Model_Config class defined in app\code\core\Mage\Core\Model\Config.php

public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
if (empty($groupRootNode)) {
$groupRootNode = ‘global/’.$groupType.’s’;

$classArr = explode(‘/’, trim($classId));
$group = $classArr[0];
$class = !empty($classArr[1]) ? $classArr[1] : null;

if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
return $this->_classNameCache[$groupRootNode][$group][$class];

$config = $this->_xml->global->{$groupType.’s’}->{$group};

// First – check maybe the entity class was rewritten
$className = null;
if (isset($config->rewrite->$class)) {
$className = (string)$config->rewrite->$class;
} else {
* Backwards compatibility for pre-MMDB extensions.
* In MMDB release resource nodes <…_mysql4> were renamed to <…_resource>. So <deprecatedNode> is left
* to keep name of previously used nodes, that still may be used by non-updated extensions.
if ($config->deprecatedNode) {
$deprecatedNode = $config->deprecatedNode;
$configOld = $this->_xml->global->{$groupType.’s’}->$deprecatedNode;
if (isset($configOld->rewrite->$class)) {
$className = (string) $configOld->rewrite->$class;

// Second – if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
if (empty($className)) {
$className = ‘mage_’.$group.’_’.$groupType;
if (!empty($class)) {
$className .= ‘_’.$class;
$className = uc_words($className);

$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;

so to rewrite a model class,we just need to add proper xml config and extend the orginal model class in the new class of your own namespace in the local code pool,so to rewrite product model,

first,set xml as below:

then declare the new class to textend the original only will this class be compatible with next magento release,but also it would have any new/updated feature  of product model,because the new class extends the original class.
class Mzcart_Catalog_Model_Product extends Mage_Catalog_Model_Product {
  //do whatever changes you want
both the above  methods can be used to to rewrite any magento helper class,block class.

magento — Fatal error: Call to undefined method Mage_Core_Helper_Data::quoteEscape()

one of my customer get this error in the magento admin backend when he install some extension.At last i found this was caused by unfinished upgrade of magento core module.of course,the update was executed when he installed the extension.

his original magento version is magento, i guess it’s been updated to 1.7 but not finished due to some i upload the Mage/Core/Helper/Abstract.php to override and fixed the error.

zen cart — SQL patch to clear all user data from zen car database

The zen cart database contain some data table store user data.If you want to clear all user data from zen cart database,you can import the following sql patch

TRUNCATE `customers`;
TRUNCATE `customers_basket`;
TRUNCATE `customers_basket_attributes`;
TRUNCATE `customers_info`;
TRUNCATE `customers_wishlist`;
TRUNCATE `customers_info`;
TRUNCATE `customers_basket`;
TRUNCATE `orders`;
TRUNCATE `orders_products`;
TRUNCATE `orders_status_history`;
TRUNCATE `orders_total`;
TRUNCATE `reviews`;
TRUNCATE `reviews_description`;