Top 10 n98-magerun command calls

n98-magerun is a very useful tool when working on Magento stores. It saves time and makes a lot of Magento development related tasks much easier. Check out a list of my 10 favorite commands.

1. dev:module:rewrite:conflicts

This one is a must have. It’s a good replacement for an Extension Conflict module which I have been using before I found the n98-magerun. It shows rewrite conflicts in a clean ASCII table:

n98-magerun.phar dev:module:rewrite:conflicts

2. mysql-client

Command opens a mysql command line client without need of looking for a host, a port and credentials in local.xml file.

n98-magerun.phar mysql-client

However, it doesn’t work on a server with proc_open() function disabled.

3. cache:flush

It flushes all Magento caches. If a store uses filesystem cache, this command isn’t much more helpful than simple rm -rf var/cache* var/full_page_cache/* . However, when using the n98-magerun I don’t need to wonder what cache type is used in a store and this command provides an interface working for all cache types.

n98-magerun.phar cache:flush

The only glitch is that in some cases it doesn’t clean cache if file permissions are not correct.

4. sys:cron:list

Prints list of all active CRON jobs configured in a Magento store. It shows output in readable way, showing a job code, minutes, hours, days, month and week days.

n98-magerun.phar sys:cron:list

Another usable command related to CRON may be sys:cron:history which lists recently finished CRON jobs.

5. sys:setup:run

It’s useful to run database updates from a command line when installing an extension or upgrading Magento.

n98-magerun.phar sys:setup:run

Recently I used that when working on a Magento upgrade from 1.12 to 1.14. Frontend kept throwing error as PHP code was trying to use things which haven’t existed in the database yet, but sys:setup:run command dealt with that perfectly.

6. dev:theme:duplicates

This could be used when working on templates, to clean them from not needed files. I ran that command in 3 projects I’m working on and it found a few duplicated templates.

n98-magerun.phar dev:theme:duplicates enterprise/rocketweb base/default

7. sys:info

Command allows to quickly show an overall picture on the store. It shows a store edition and version, list of vendors coming from all code pools and a few other information. Additionally it shows basic factors which can determine the store size – amount of attributes, categories and products.

n98-magerun.phar sys:info

It’s handy when starting to work on an already existing site.

8. sys:check

It checks for missing system paths such as media/, var/ or a local.xml config file and checks if required PHP modules are installed. For example on my local server it keeps complaining about a missing index.php.sample file and about missing bytecode cache extension. I will need to get rid of this to get a nice green output :-)

n98-magerun.phar sys:check

Additionally it checks if each base URL contains dot, however I don’t get this part.

9. dev:console

This opens an interactive console with Magento initialized. It’s marked as experimental but works pretty well. It allows to run code in interactive way, most useful when I need to check multiple objects one by one eg. go through blog posts. For example to open console run:

n98-magerun.phar dev:console

And then run code to dump the blog post data:

Zend_Debug::dump(Mage::getModel('blog/post')->load(3)->debug());
Zend_Debug::dump(Mage::getModel('blog/post')->load(4)->debug());
Zend_Debug::dump(Mage::getModel('blog/post')->load(5)->debug());

Or order:

Zend_Debug::dump(Mage::getModel('sales/order')->load(109)->debug());

10. sys:modules:list

It lists all modules along with fields like code pool, key, version and status.

n98-magerun.phar sys:modules:list

Documentation says it’s possible to filter list by a code pool and a status, but I couldn’t get it working. It simply shows nothing when I use any filter. However, even without filtering it’s pretty useful.

I chose these 10 commands as most interesting, but there are many other handy tools: a command for working with database dumps, a command for debugging Magento configs and all toggle commands which allow to enable/disable things like a cache, a demo notice, template hints and many more.

Take a look on http://magerun.net to see all of them or better just play with the tool. Also make sure to subscribe my RSS feed or my twitter as soon I will talk more about cool n98-magerun use cases.


Comments

6 responses to “Top 10 n98-magerun command calls”

  1. Mario Avatar

    One of my favourite commands not in your list is a must have for all PhpStorm or IntellijIdea users: n98-magerun dev:ide:phpstorm:meta

  2. David Avatar

    Great post! I would add maybe “dev:template-hints” to the list. I am front-ender ;)

  3. I think I missed dev:ide:phpstorm:meta as I use PhpStorm with Magicento which supports auto completion without meta file.

    David, you’re right, actually all these toggle commands are really helpful.

  4. Very thanks for sharing!

  5. […] Naruniec verriet außerdem, was seine 10 Lieblings-Befehle von n98-magerun […]

  6. […] Naruniec verriet außerdem, was seine 10 Lieblings-Befehle von n98-magerun […]

Leave a Reply

Your email address will not be published. Required fields are marked *