Running custom shell commands in Magento

If you need to export some data from magento or to change them the best thing is to create a custom shell command. To do that please follow these steps:

  1. Go to shell folder and create a new file test.php
  2. Open the file that you created and insert this code:
    <?php
    
    require_once 'abstract.php';
    require_once '../app/Mage.php';
    
    class Test extends Mage_Shell_Abstract
    {
        public function run()
        {
            if ('actionName' == $this->getArg('action')) {
                echo "Code Here"; exit();
            }else{
                echo $this->usageHelp();
            }
        }
        public function usageHelp()
        {
            return <<<USAGE
    Usage:  php -f importer.php -- [options]
    
      --action actionName     
    
      Or any text you like
    
    USAGE;
        }
    }
    
    $shell = new Test();
    $shell->run();
  3. You can run this script by:
    php -f test.php -- action actionName