Categories


Archives


Recent Posts


Categories


N98-magerun: Indexing, Magento Connect, and Grab Bag

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This article is part of a longer series covering the n98-magerun power tool

We’re almost at the end of our n98-magerun command review. Today we’re going to blitz through the remaining commands on our plate

$ n98-magerun list local
    Available commands for the "local-config:generate" namespace:
      local-config:generate   Generates local.xml config

$ n98-magerun list index
    Available commands for the "index" namespace:
      index:list          Lists all magento indexes
      index:reindex       Reindex a magento index by code
      index:reindex:all   Reindex all magento indexes

$ n98-magerun list extension
    Available commands for the "extension" namespace:
      extension:download   Download magento-connect package
      extension:install    Install magento-connect package
      extension:list       List magento connection extensions
      extension:search     List magento connection extensions
      extension:upgrade    Upgrade magento-connect package

Let’s get to it.

Local Config

The local-config:generate command will recreate the local configuration file at app/etc/local.xml.

$ n98-magerun local-config:generate

  Generate Magento local.xml  

Please enter the database host:localhost
Please enter the database username:merlin
Please enter the database password:password12345
Please enter the database name:magento_example_com
Please enter the session save:file
Please enter the admin frontname:admin
Generated config

This file is the first one loaded into the global configuration tree, and is generated by installing Magento. This command appears to exist as a fix for stores with a missing local.xml. Consider the results if you run the command with app/etc/local.xml in place.

$ n98-magerun local-config:generate
local.xml file already exists in folder "/path/to/magento/app/etc"

Also, local-config:generate relies on the existence of the app/etc/local.xml.template file that ships with Magento. Running the command without this will result in the following error.

File /Users/alanstorm/Sites2012/magento1point7pointzeropoint1.dev/app/etc/local.xml.template does not exist.

Finally, while there are interactive prompts for entering data, the script does no validation on the values. Database credentials aren’t checked, it’s possible to enter an invalid session save type, etc. Keep your wits about you when using this command.

Indexer Commands

The index category contains three commands for working with Magento’s indexes. These commands are very similar to the shell/indexer.php script that ships with Magento. For those new to the platform, a Magento “index” is conceptually like an index on a database column, but a more practical definition might be

An index takes data Magento either stores across many tables in a normalized-(ish) way or calculates, and then de-normalizes or caches it for performance and convenience reasons.

You can use the index:list command to fetch a list of all known Magento indexers, (also known as “index processes”).

$ n98-magerun index:list

  Index list  

+---------------------------+-----------------+--------+
| code                      | status          | time   |
+---------------------------+-----------------+--------+
| catalog_product_attribute | pending         | 0      |
| catalog_product_price     | pending         | 2m 52s |
| catalog_url               | pending         | 5s     |
| catalog_product_flat      | pending         | 1m 27s |
| catalog_category_flat     | require_reindex | 1s     |
| catalog_category_product  | pending         | 0      |
| catalogsearch_fulltext    | pending         | 3s     |
| cataloginventory_stock    | pending         | 1s     |
| tag_summary               | pending         | 0      |
+---------------------------+-----------------+--------+

The status column indicates if Magento thinks a re-index is required (pending being the normal status), and the time column indicates how long the last re-index took.

You can run a specific index process with the index:reindex command

$ n98-magerun index:reindex
$ n98-magerun index:reindex catalog_url

  Reindex  

Started reindex of: catalog_url
Estimated end: 2013-04-23 04:41:27 UTC
Successfully reindexed catalog_url (Runtime: 5s)

or re-index everything with the index:reindex:all command.

$ n98-magerun index:reindex:all
Successfully reindexed catalog_product_attribute
Successfully reindexed catalog_product_price
Successfully reindexed catalog_url
Successfully reindexed catalog_product_flat
Successfully reindexed catalog_category_flat
Successfully reindexed catalog_category_product
Successfully reindexed catalogsearch_fulltext
Successfully reindexed cataloginventory_stock
Successfully reindexed tag_summary

Magento Connect Commands

The extension category contains commands related to Magento Connect. Magento Connect is the repository of free Magento extensions maintained by eBay Inc.’s Magento division, as well as the ecosystem of tools for installing the extension packages.

While the extension commands may seem like a replacement for the bundled ./mage script, these commands are just wrappers for calls to ./mage. You’ll still need a fully installed and configured Magento Connect to run these commands.

The extension:list command will display a list of every Magento Connect extension that’s available. As of this writing that’s 3800 extensions.

$ mn98-magerun extension:list 
+---------------------+--------------------+--------+
| Package             | Version            | Stabi  |
+---------------------+--------------------+--------+
| Lib_Js_Calendar     | 1.51.1.1           | stable |
| Lib_Js_Ext          | 1.7.0.0            | stable |
| ... snipped ...     |                    |        |
| Ivan_ImageZoom      | 2.0.0              | stable |
| fullpagecache       | 1.0.0              | stable |
+---------------------+--------------------+--------+

If you’re looking for a specific extension, you can perform a simple stristr search on the name with the extension:search command.

$ mn98-magerun extension:search Mage

+-------------------------+----------------+--------+
| Package                 | Version        | Stabi  |
+-------------------------+----------------+--------+
| Mage_Pear_Helpers       | 1.0.18800      | stable |
| Mage_All                | 1.0.19870      | stable |
| Mage_Oscommerce         | 1.1.20123      | dev    |
| Mage_Checkout           | 1.0            | dev    |
| Mage_Strikeiron         | 1.0.18800      | stable |
| Locale_Mage_Core_fr_FR  | 1.0.18800      | beta   |
| ... snipped ...         |                |        |
| mageokcustomoptions     | 1.0.0.0        | alpha  |
| Ivan_ImageZoom          | 2.0.0          | stable |
+-------------------------+----------------+--------+

Keep in mind stristr’s search is not a sophisticated algorithm. You’ll notice our search returned Ivan_ImageZoom due to the mage in Image.

Once you’ve found the extension you’re looking for, you may download it with the extension:download command

$ n98-magerun extension:download Pulsestorm_Launcher
Saved to: /path/to/magento/downloader/.cache/community/Pulsestorm_Launcher-1.0.3.tgz

You can also download and automatically install a package with extension:install.

$ n98-magerun extension:install Pulsestorm_Launcher
Checking dependencies of packages
Starting to download Pulsestorm_Launcher-1.0.3.tgz ...
...done: 8,946 bytes
Installing package community/Pulsestorm_Launcher 1.0.3
Package community/Pulsestorm_Launcher 1.0.3 installed successfully
Package installed: community/Pulsestorm_Launcher 1.0.3

And finally, you can use the extension:upgrade command to check-for-then-automatically-install an upgrade for an extension.

$ n98-magerun extension:upgrade Pulsestorm_Launcher
Checking dependencies of packages
Already installed: community/Pulsestorm_Launcher 1.0.3, skipping

In the example above n98-magerun is telling us it didn’t do anything, since the latest version of the Pulse Storm Launcher is already installed. That points to one of the weaknesses of the extension category of commands. While the commands here are useful, you’ll still need to rely on ./mage (or the Connect GUI) if you want to view a list of available upgrades, uninstall an extension, etc.

Wrap Up

And that completes our command coverage of n98-magerun. There’s a few other commands that are worth checking out on your own. The cms category has two commands that are Magento Enterprise Edition only, cms:banner:toggle for publishing a banner, and cms:page:publish for publishing a specific CMS page. There’s also a design:demo-notice command which can toggle a demo notice on/off in your store.

Next time we’ll start digging into setting up your own n98-magerun development environment.

Copyright © Alan Storm 1975 – 2017 All Rights Reserved

Originally Posted: 25th April 2013