Magento Improved Shell
, (*3)
Add some style to your Magento scripts., (*4)
, (*5)
Extend the shell/local/abstract.php
class and put your logic in the run()
method, like you normally would with a Magento shell script., (*6)
Instead of echo
ing, use the $this->log
object. You can output messages using one of Zend_Log
's levels, (*7)
<?php class Zend_Log { const EMERG = 0; // Emergency: system is unusable const ALERT = 1; // Alert: action must be taken immediately const CRIT = 2; // Critical: critical conditions const ERR = 3; // Error: error conditions const WARN = 4; // Warning: warning conditions const NOTICE = 5; // Notice: normal but significant condition const INFO = 6; // Informational: informational messages const DEBUG = 7; // Debug: debug messages }
Example:, (*8)
<?php require_once 'abstract.php'; class Local_Shell_MyScript extends Local_Shell_Abstract { public function run() { $this->log->debug('Hello World!'); } }
Create a progress bar with $bar = $this->progressBar($count);
, where $count
is an integer of how many items you will iterate over. $bar->update($i);
as you walk through, then $bar->finish();
when complete., (*9)
Example:, (*10)
<?php require_once 'abstract.php'; class Local_Shell_MyScript extends Local_Shell_Abstract { public function run() { $collection = Mage::getModel('catalog/product')->getCollection(); $count = $collection->count(); $bar = $this->progressBar($count); $i = 0; foreach ($collection as $product) { $product->setDescription(strip_tags($product->getDescription())) ->save(); $bar->update(++$i); } $bar->finish(); } }
Output is automatically logged to var/log/shell_local_<scriptName>.log
., (*11)
Alternatively, you can specify your own log file by setting the public $logFile
variable in you script., (*12)
Please create an issue for all bugs and feature requests, (*13)
Fork this repository and send a pull request to the dev
branch, (*14)
WTF Public License 2.0, (*15)