Magento CLI: The /shell Folder

I noticed the /shell directory in the Magento root folder, so I took a peek inside. Cool stuff. There’s a small set of PHP scripts intended to be called via the PHP CLI! This means a nice tidy interface to working with Magento via the command line.

You may be thinking, “Command line is cool?!? Really?” Definitely. The CLI is great for deployment and maintenance operations on your Magento server. Instead of writing exposed controllers to trigger operations, you can safely do it via terminal, cron or any other scripting mechanism.

There’s even a nifty abstract.php, that contains everything needed to build your own custom command line interfaces. Thanks Magento, that was nice! Then only thing that’s missing is a shell script for cache refresh. :)

Some example usage:


ticean@ticean-laptop:~/Projects/local.magento/shell$ ls
abstract.php compiler.php indexer.php log.php

ticean@ticean-laptop:~/Projects/local.magento/shell$ php log.php
Usage: php -f log.php -- [options]
php -f log.php -- clean --days 1

clean Clean Logs
--days Save log, days. (Minimum 1 day, if defined - ignoring system value)
status Display statistics per log tables
help This help

#This is a local development instance, so there's not a lot of log data.
ticean@ticean-laptop:~/Projects/local.magento/shell$ php log.php status
-----------------------------------+------------+------------+------------+
Table Name | Rows | Data Size | Index Size |
-----------------------------------+------------+------------+------------+
log_customer | 1 | 16.38Kb | 16.38Kb |
log_visitor | 8 | 16.38Kb | 0 b |
log_visitor_info | 8 | 16.38Kb | 0 b |
log_url | 51 | 16.38Kb | 16.38Kb |
log_url_info | 51 | 16.38Kb | 0 b |
log_quote | 1 | 16.38Kb | 0 b |
report_viewed_product_index | 2 | 16.38Kb | 81.92Kb |
report_compared_product_index | 0 | 16.38Kb | 81.92Kb |
report_event | 4 | 16.38Kb | 81.92Kb |
catalog_compare_item | 0 | 16.38Kb | 81.92Kb |
-----------------------------------+------------+------------+------------+
Total | 126 | 163.84Kb | 360.45Kb |
-----------------------------------+------------+------------+------------+

ticean@ticean-laptop:~/Projects/local.magento/shell$ php indexer.php
Usage: php -f indexer.php -- [options]

--status Show Indexer(s) Status
--mode Show Indexer(s) Index Mode
--mode-realtime Set index mode type "Update on Save"
--mode-manual Set index mode type "Manual Update"
--reindex Reindex Data
info Show allowed indexers
reindexall Reindex Data by all indexers
help This help

Comma separated indexer codes or value "all" for all indexers

ticean@ticean-laptop:~/Projects/local.magento/shell$ php indexer.php info
catalog_product_attribute Product Attributes
catalog_product_price Product Prices
catalog_url Catalog URL Rewrites
catalog_product_flat Product Flat Data
catalog_category_flat Category Flat Data
catalog_category_product Category Products
catalogsearch_fulltext Catalog Search Index
tag_summary Tag Aggregation Data
cataloginventory_stock Stock Status

ticean@ticean-laptop:~/Projects/local.magento/shell$ php indexer.php reindexall
Product Attributes index was rebuilt successfully
Product Prices index was rebuilt successfully
Catalog URL Rewrites index was rebuilt successfully
Product Flat Data index was rebuilt successfully
Category Flat Data index was rebuilt successfully
Category Products index was rebuilt successfully
Catalog Search Index index was rebuilt successfully
Tag Aggregation Data index was rebuilt successfully
Stock Status index was rebuilt successfully

No TweetBacks yet. (Be the first to Tweet this post)

Leave a Reply

You must be logged in to post a comment.