Categories


Archives


Recent Posts


Categories


N98-magerun: Admin and Cache Commands

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.

Updated for Magento 2! 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

Today we’ll be covering n98-magerun’s admin and cache commands. You can see the internal descriptions for these commands by using the top-level list command.

$ n98-magerun.phar list admin

...
Available commands for the "admin" namespace:
  admin:notifications          Toggles admin notifications
  admin:user:change-password   Changes the password of a adminhtml user.
  admin:user:create            Create admin user.
  admin:user:list              List admin users.

...

$ n98-magerun.phar list cache

...
Available commands for the "cache" namespace:
  cache:clean     Clean magento cache
  cache:disable   Disables magento caches
  cache:enable    Enables magento caches
  cache:flush     Flush magento cache storage
  cache:list      Lists all magento caches

...

Admin Commands

The commands in the admin hierarchy relate to Magento’s backend admin console, (sometimes referred to as the adminhtml area). With n98-magerun you can get a list of all the admin users in a particular system

$ n98-magerun.phar admin:user:list
+-----+----------+----------------------+--------+
| id  | username | email                | status |
+-----+----------+----------------------+--------+
|   1 | admin    | owner@example.com    | active |
|   2 | astorm   | astorm@example.com   | active |
|   3 | alan     | alan@example.com     | active |
+-----+----------+----------------------+--------+

There’s also an interactive command for creating new users

$ n98-magerun.phar admin:user:create
Username:test
Email:test@example.com
Password:password12345luggage
Firstname:Bob
Lastname:Hoffner

User test successfully created

While useful, it appears this command doesn’t allow you to assign users to a particular admin role — you’ll need to login and assign a role through the GUI.

The final user command, admin:user:change-password will let you change an admin user’s password.

$ n98-magerun.phar admin:user:change-password
Username:astorm
Password:password12345luggage

Password successfully changed

This command is particularly useful if you’re inheriting a Magento system, setting up a development environment, and no one knows the password for the super user account.

There’s one more admin command to cover, but this one isn’t in the user category. The admin:notifications command allows you to toggle the admin notification bar (and the occasional accompanying modal ajax alert) on or off.

$ n98-magerun.phar admin:notifications
Admin Notifications hidden

This is accomplished by toggling the Disable Module Output system configuration setting for the Mage_AdminNotification module.

Cache Commands

If there’s one thing Magento teaches you, its the art of cache programming. Magento has multiple different types of data it caches — you can see a list of the caches, including their enabled/disabled state, with the cache:list command.

$ n98-magerun.phar cache:list

  Cache list  

+-------------+----------+
| code        | status   |
+-------------+----------+
| config      | enabled  |
| layout      | enabled  |
| block_html  | enabled  |
| translate   | enabled  |
| collections | enabled  |
| eav         | enabled  |
| config_api  | enabled  |
| config_api2 | disabled |
+-------------+----------+

You can also enable every cache type with the cache:enable command

$ n98-magerun.phar cache:enable

or disable every cache type with the cache:disable command

$ n98-magerun cache:disable

Unfortunately, there doesn’t appear to be a way to enable or disable individual cache types. If you need that functionality, you’ll need to hop into the GUI admin.

Fortunately, the cache:clean command allows you finely grained control over which cache you want to clean.

$ n98-magerun.phar cache:clean config
config cache cleaned

as well as an argument-less version that will clear each Magento cache type

$ n98-magerun.phar cache:clean 
block_html cache cleaned
collections cache cleaned
config cache cleaned
config_api cache cleaned
config_api2 cache cleaned
eav cache cleaned
layout cache cleaned
translate cache cleaned

Cleaning a cache means removing all its keys from the cache storage engine, which will prompt Magento to rebuild the cache items.

Despite having a typed cache system, it’s posible to stick items in the Magento cache without assigning the data to a particular type. There’s also Zend Framework code that drops items into the cache without regards for Magento’s types. To get this data out of the cache, you’ll need to flush the entire cache store engine with the cache:flush command

$ n98-magerun.phar cache:flush
Cache cleared

Cleaning the cache is like a surgeon going in and cutting out the parts o the cache that are no longer needed. Flushing the cache is like chemo therapy — obliterating everything to ensure the parts you want are gone.

Copyright © Alan Storm 1975 – 2019 All Rights Reserved

Originally Posted: 17th April 2013