Tuesday, June 21, 2011

Revert all modified files in an SVN repo

svn st | grep -e '^M' | awk '{print $2}' | xargs svn revert

Friday, June 10, 2011

Replace in string : preg_replace

        $pattern = '/(\d+),(\w+)/i';
        $replacement = '<strong>${1}</strong>,$2';
        return  Mage::log( $this->getQuote()->getStore()->formatPrice($price , true) );
        return preg_replace($pattern, $replacement, Mage::log( $this->getQuote()->getStore()->formatPrice($price , false) ) );



Thursday, March 31, 2011

Find folder

find / -name "test_*" -type d -print


Friday, February 18, 2011

Symbolic link

ln -s /etc/apache2/sites-available/phpmyadmin.domain.net /etc/apache2/sites-enabled/phpmyadmin.domain.net

Thursday, January 20, 2011

[PHP] Difference betwen tow date

    public function _getDiffInHours( $date ){
        $usDate = str_replace ( "/" , "-" ,$date);
        $now = strtotime("now");
        $nextDate = strtotime ( $usDate );
        if(! is_numeric( $nextDate ) || ! is_numeric( $now ) || $nextDate <  $now ){
            return 0;
        }
        return floor( ($nextDate-$now) / (60*60));
    }

Friday, January 7, 2011

Log in other file that system.log

    public function _log($msg){
        $nameFile = 'other-file-'.date ( "Y-m-d-H" ).'.log';
        Mage::log($msg, null, $nameFile );
    }

Wednesday, January 5, 2011

Replace accented characters

    public function normaliza ($string){
        $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';   
        $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
        $string = utf8_decode($string);   
        $string = strtr($string, utf8_decode($a), $b);
        $string = strtolower($string);
        return  utf8_encode($string) ;
    }     

Tuesday, December 28, 2010

Date Magento in any format

Mage::app()->getLocale()->date(strtotime($Model->getCreatedAt()), null, null, false)->toString('dd/MM/yyyy')


Monday, December 20, 2010

Catalog Search Index refresh

<?php
require_once 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
Mage::log("Started Rebuilding Search Index At: " . date("d/m/y h:i:s"));
$sql = "truncate catalogsearch_fulltext;";
$mysqli = Mage::getSingleton('core/resource')->getConnection('core_write');
$mysqli->query($sql);
$process = Mage::getModel('index/process')->load(7);
$process->reindexAll();
Mage::log("Finished Rebuilding Search Index At: " . date("d/m/y h:i:s"));

Friday, December 17, 2010

How to add days, weeks, months to any date ?

$date = date("Y-m-d");// current date

$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");

Tuesday, December 14, 2010

/var/empty/sshd must be owned by root and not group or world-writable

Check the ownership and permissions on /var/empty and /var/empty/sshd.
They must be owned by root (chown root /var/empty; chown root /var/empty/sshd) and not be writable by anyone except root.

chmod go-w /var/empty/sshd;
chmod go-w /var/empty

Friday, November 12, 2010

Magento: Use cache

$cacheKey = 'CODE_CODE'.Mage::app()->
getStore()->getId();
        if (Mage::app()->useCache('config') && $collection = Mage::app()->loadCache($cacheKey)) {
            $prod = unserialize($collection);
        } else {
            $prod = Mage::getModel()->getCollection;
            ....
           
            if (Mage::app()->useCache('config')) {
                Mage::app()->saveCache(serialize($prod), $cacheKey, array('config'));
            }
        }

Friday, October 29, 2010

Magento: Get url stores

$stores = Mage::getModel('core/store')->getCollection();
foreach(  $stores as $store ){
            $url = Mage::getModel('core/url') ->setStore($store)->getUrl('');
            echo $url."\n";
}

Magento: Request to do in case of duplication in the flat catalog

SELECT entity_id, count( * )
FROM catalog_category_flat_store_x
GROUP BY entity_id
ORDER BY count( * ) DESC
LIMIT 0 , 30

PHP: 301 redirect

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
Powered by Blogger.