steverobbins/magento-shell

Magento Improved Shell

Installs: 28

Dependents: 1

Suggesters: 0

Security: 0

Stars: 49

Watchers: 6

Forks: 8

Open Issues: 1

Type:magento-module

v1.0 2015-05-09 00:17 UTC

This package is auto-updated.

Last update: 2024-10-29 04:52:56 UTC


README

Join the chat at https://gitter.im/steverobbins/Magento-Shell

Master Build Status Master Code Quality

OMG COLORS

Drool

Add some style to your Magento scripts.

Sample

Usage

Extend the shell/local/abstract.php class and put your logic in the run() method, like you normally would with a Magento shell script.

Output

Instead of echoing, use the $this->log object. You can output messages using one of Zend_Log's levels

<?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:

<?php

require_once 'abstract.php';

class Local_Shell_MyScript extends Local_Shell_Abstract
{
    public function run()
    {
        $this->log->debug('Hello World!');
    }
}

Progress Bar

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.

Example:

<?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();
    }
}

Logging

Output is automatically logged to var/log/shell_local_<scriptName>.log.

Alternatively, you can specify your own log file by setting the public $logFile variable in you script.

Support

Please create an issue for all bugs and feature requests

Contributing

Fork this repository and send a pull request to the dev branch

License

WTF Public License 2.0