steverobbins/magento-shell

Magento Improved Shell

安装: 27

依赖: 1

建议者: 0

安全: 0

星标: 49

关注者: 6

分支: 8

公开问题: 1

类型:magento-module

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

This package is auto-updated.

Last update: 2024-09-29 04:42:18 UTC


README

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

Master Build Status Master Code Quality

OMG 颜色

Drool

为您的 Magento 脚本添加一些样式。

Sample

用法

扩展 shell/local/abstract.php 类,并在 run() 方法中放置您的逻辑,就像您通常使用 Magento 脚本一样。

输出

而不是使用 echo,请使用 $this->log 对象。您可以使用 Zend_Log 中的一个级别输出消息

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

示例

<?php

require_once 'abstract.php';

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

进度条

使用 $bar = $this->progressBar($count); 创建一个进度条,其中 $count 是您将迭代的整数项数。在遍历过程中使用 $bar->update($i);,完成后使用 $bar->finish();

示例

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

日志记录

输出会自动记录到 var/log/shell_local_<scriptName>.log

或者,您可以在脚本中设置公共变量 $logFile 来指定自己的日志文件。

支持

请为所有错误和功能请求 创建一个问题

贡献

分叉此存储库并向 dev 分支发送拉取请求。

许可

WTF 公共许可证 2.0