Skip to content

Provides some handy tools for magento developers like a quick database info from local.xml or a database dump feature, cache clearing, admin user password reset. You can also easily install a complete shop and sample data with buildin installer. For coders there are also many features like a module kickstarter (with modman support). If something…

Notifications You must be signed in to change notification settings

Zyava/n98-magerun

 
 

Repository files navigation

netz98 magerun CLI tools

The n98 magerun cli tools provides some handy tools to work with Magento from command line.

Build Status

Latest Release

https://travis-ci.org/netz98/n98-magerun.png?branch=master https://www.versioneye.com/user/projects/51236c8b294edc00020064c5/badge.png

Development Branch

https://travis-ci.org/netz98/n98-magerun.png?branch=develop

Compatibility

The tools will automatically be tested for multiple PHP versions (5.3, 5.4, 5.5). It's currently currently running in various Linux distributions and Mac OS X. Microsoft Windows is not fully supported (some Commands like db:dump or install are excluded).

The tool partially works with Magento 2 development branch.

Installation

There are two ways to install the tools:

Download phar file

wget https://raw.github.com/netz98/n98-magerun/master/n98-magerun.phar

or if you have problems with SSL certificate:

curl -o n98-magerun.phar https://raw.github.com/netz98/n98-magerun/master/n98-magerun.phar

You can make the .phar file executable.

chmod +x ./n98-magerun.phar

If you want to use command system wide you can copy it to /usr/local/bin.

sudo cp ./n98-magerun.phar /usr/local/bin/

Debian / suhosin:

On some debian systems with compiled in suhosin the phar extension must be added to a whitelist.

Add this to your php.ini file:

suhosin.executor.include.whitelist="phar"

You don't like the filename?

Just rename it to whatever you want.

Install with Composer

https://github.com/netz98/n98-magerun/wiki/Install-from-source-with-Composer

Update

Since version 1.1.0 we deliver a self-update script within the phar file:

$ n98-magerun.phar self-update

If file was installed system wide do not forget "sudo".

See it in action: http://youtu.be/wMHpfKD9vjM

Usage / Commands

All commands try to detect the current Magento root directory. If you have multiple Magento installation you must change your working directory to the preferred installation.

https://github.com/netz98/n98-magerun/wiki/Commands

You can list all available commands by:

$ n98-magerun.phar list

If you don't have installed the .phar file system wide you can call it with the php cli interpreter:

php n98-magerun.phar list

Open Shop in Browser

$ n98-magerun.phar open-browser [store]

Customer Info

Loads basic customer info by email address.

$ n98-magerun.phar  customer:info [email] [website]

Create customer

Creates a new customer/user for shop frontend.

$ n98-magerun.phar  customer:create [email] [password] [firstname] [lastname] [website]

Example:

$ n98-magerun.phar customer:create [email protected] password123 John Doe base

Generate Dummy Customers

Generate dummy customers. You can specify a count and a locale.

$ n98-magerun.phar customer:create:dummy count locale [website]

Supported Locales:

  • cs_CZ
  • ru_RU
  • bg_BG
  • en_US
  • it_IT
  • sr_RS
  • sr_Cyrl_RS
  • sr_Latn_RS
  • pl_PL
  • en_GB
  • de_DE
  • sk_SK
  • fr_FR
  • es_AR
  • de_AT

List Customers

List customers. The output is limited to 1000 (can be changed by overriding config). If search parameter is given the customers are filtered (searchs in firstname, lastname and email).

$ n98-magerun.phar  customer:list [search]

Change customer password

$ n98-magerun.phar customer:change-password [email] [password] [website]
  • Website parameter must only be given if more than one websites are available.

Print database information

$ n98-magerun.phar db:info

Dump database

Dumps configured magento database with mysqldump.

  • Requires MySQL CLI tools

Arguments

filename Dump filename

Options

--add-time Adds time to filename (only if filename was not provided)

—compression (-c) Compress the dump file using one of the supported algorithms

--only-command Print only mysqldump command. Do not execute

—print-only-filename Execute and prints not output except the dump filename

--no-single-transaction
 Do not use single-transaction (not recommended, this is blocking)

—human-readable Use a single insert with column names per row.

--stdout Dump to stdout

—strip Tables to strip (dump only structure of those tables)

--force (-f)
Do not prompt if all options are defined
$ n98-magerun.phar db:dump

Only the mysqldump command:

$ n98-magerun.phar db:dump --only-command [filename]

Or directly to stdout:

$ n98-magerun.phar db:dump --stdout

Use compression (gzip cli tool has to be installed):

$ n98-magerun.phar db:dump --compression="gzip"

Stripped Database Dump

Dumps your database and excludes some tables. This is useful i.e. for development.

Separate each table to strip by a space. You can use wildcards like * and ? in the table names to strip multiple tables. In addition you can specify pre-defined table groups, that start with an @ Example: "dataflow_batch_export unimportant_module_* @log

$ n98-magerun.phar db:dump --strip="@stripped"

Available Table Groups:

  • @log Log tables
  • @dataflowtemp Temporary tables of the dataflow import/export tool
  • @stripped Standard definition for a stripped dump (logs and dataflow)
  • @sales Sales data (orders, invoices, creditmemos etc)
  • @customers Customer data
  • @trade Current trade data (customers and orders). You usally do not want those in developer systems.
  • @development Removes logs and trade data so developers do not have to work with real customer data

Extended: https://github.com/netz98/n98-magerun/wiki/Stripped-Database-Dumps

See it in action: http://youtu.be/ttjZHY6vThs

Database Import

Imports an SQL file with mysql cli client into current configured database.

  • Requires MySQL CLI tools
Arguments:
filename Dump filename
Options:
--compression (-c) The compression of the specified file --only-command Print only mysql command. Do not execute
$ n98-magerun.phar db:dump
$ n98-magerun.phar db:import [--only-command] [filename]

Use decompression (gzip cli tool has to be installed):

$ n98-magerun.phar db:import --compression="gzip" [filename]

Database Console / MySQL Client

Opens the MySQL console client with your database settings from local.xml

  • Requires MySQL CLI tools
$ n98-magerun.phar db:console

Database Create

Create currently configured database

$ n98-magerun.phar db:create

Database Drop

Drops the database configured in local.xml.

  • Requires MySQL CLI tools
$ n98-magerun.phar db:drop  [-f|--force]

Database Query

Executes an SQL query on the current configured database. Wrap your SQL in single or double quotes.

If your query produces a result (e.g. a SELECT statement), the output of the mysql cli tool will be returned.

  • Requires MySQL CLI tools
Arguments:
query SQL query
Options:
--only-command Print only mysql command. Do not execute
$ n98-magerun.phar db:query [--only-command] [query]

List Indexes

$ n98-magerun.phar index:list

Reindex a Index

Index by indexer code. Code is optional. If you don't specify a code you can pick a indexer from a list.

$ n98-magerun.phar index:reindex [code]

Since 1.75.0 it's possible to run mutiple indexers by seperating code with a comma.

i.e.

$ n98-magerun.phar index:reindex catalog_product_attribute,tag_summary

If no index is provided as argument you can select indexers from menu by "number" like "1,3" for first and third indexer.

Reindex All

Loops all magento indexes and triggers reindex.

$ n98-magerun.phar index:reindex:all

Generate local.xml file

$ n98-magerun.phar local-config:generate

Config Dump

Dumps merged XML configuration to stdout. Useful to see all the XML.

$ n98-magerun.phar [xpath]

Examples

Config of catalog module:

$ n98-magerun.phar config:dump global/catalog

See module order in XML:

$ n98-magerun.phar config:dump modules

Write output to file:

$ n98-magerun.phar config:dump > extern_file.xml

Set Config

$ n98-magerun.phar config:set [--scope[="..."]] [--scope-id[="..."]] [--encrypt] path value
Arguments:
path The config path value The config value
Options:
--scope The config value's scope (default: "default" | Can be "default", "websites", "stores")
--scope-id The config value's scope ID (default: "0")
--encrypt Encrypt the config value using local.xml's crypt key

Get Config

$ n98-magerun.phar config:get [--scope-id="..."] [--decrypt] [path]
Arguments:
path The config path
Options:
--scope-id The config value's scope ID
--decrypt Decrypt the config value using local.xml's crypt key
Help:
If path is not set, all available config items will be listed. path may contain wildcards (*)

Delete Config

$ n98-magerun.phar config:delete [--scope[="..."]] [--scope-id[="..."]] path
Arguments:
path The config path
Options:
--scope The config scope (default, websites, stores)
--scope-id The config value's scope ID

Config Search

Search system configuration descriptions.

$ n98-magerun.phar text

List Magento cache status

$ n98-magerun.phar cache:list

Clean Magento cache

Cleans expired cache entries. If you like to remove all entries use cache:flush

$ n98-magerun.phar cache:clean

Or only one cache type like i.e. full_page cache:

$ n98-magerun.phar cache:clean full_page

Remove all cache entries

$ n98-magerun.phar cache:flush

List Magento caches

$ n98-magerun.phar cache:list

Disable Magento cache

$ n98-magerun.phar cache:disable

Enable Magento cache

$ n98-magerun.phar cache:enable

Demo Notice

Toggle demo store notice

$ n98-magerun.phar design:demo-notice [store_code]

List admin users

$ n98-magerun.phar admin:user:list

Create admin user

$ n98-magerun.phar admin:user:create [username] [email] [password] [firstname] [lastname]

Change admin user password

$ n98-magerun.phar admin:user:change-password [username] [password]

Disable admin notifications

Toggle admin notifications.

$ n98-magerun.phar admin:notifications

Maintenance mode

If no option is provided it toggles the mode on every call.

$ n98-magerun.phar sys:maintenance [--on] [--off]

Magento system info

Provides info like the edition and version or the configured cache backends.

$ n98-magerun.phar sys:info

Magento Stores

Lists all store views.

$ n98-magerun.phar sys:store:list

Magento Store Config - BaseURLs

Lists base urls for each store.

$ n98-magerun.phar sys:store:config:base-url:list

Magento Websites

Lists all websites.

$ n98-magerun.phar sys:website:list

List Cronjobs

Lists all cronjobs defined in config.xml files.

$ n98-magerun.phar sys:cron:list

Run Cronjob

Runs a cronjob by code.

$ n98-magerun.phar sys:cron:run [job]

If no job argument is passed you can select a job from a list. See it in action: http://www.youtube.com/watch?v=QkzkLgrfNaM

Cronjob History

Last executed cronjobs with status.

$ n98-magerun.phar sys:cron:history

List URLs

$ sys:url:list [--add-categories] [--add-products] [--add-cmspages] [--add-all] [stores] [linetemplate]

Examples:

  • Create a list of product urls only:
$ n98-magerun.phar sys:url:list --add-products 4
  • Create a list of all products, categories and cms pages of store 4 and 5 separating host and path (e.g. to feed a jmeter csv sampler):
$ n98-magerun.phar sys:url:list --add-all 4,5 '{host},{path}' > urls.csv
  • The "linetemplate" can contain all parts "parse_url" return wrapped in '{}'. '{url}' always maps the complete url and is set by default

Run Setup Scripts

Runs all setup scripts (no need to call frontend). This command is useful if you update your system with enabled maintenance mode.

$ n98-magerun.phar sys:setup:run

Compare Setup Versions

Compares module version with saved setup version in core_resource table and displays version mismatch.

$ n98-magerun.phar sys:setup:compare-versions [--ignore-data]

System Check

  • Checks missing files and folders
  • Security
  • PHP Extensions (Required and Bytecode Cache)
  • MySQL InnoDB Engine
$ n98-magerun.phar sys:check

CMS: Toggle Banner

Hide/Show CMS Banners

$ n98-magerun.phar cms:banner:toggle <banner_id>

CMS: Publish a page

Publishes a page by page id and revision.

$ n98-magerun.phar cms:page:publish <page_id> <revision_id>

Useful to automatically publish a page by a cron job.

Interactive Development Console

Opens PHP interactive shell with initialized Magento Admin-Store.

$ n98-magerun.phar dev:console

See it in action: http://www.youtube.com/watch?v=zAWpRpawTGc

The command is only available for PHP 5.4 users.

Template Hints

Toggle debug template hints settings of a store

$ n98-magerun.phar dev:template-hints [store_code]

Template Hints Blocks

Toggle debug template hints blocks settings of a store

$ n98-magerun.phar dev:template-hints-blocks [store_code]

Inline Translation

Toggle settings for shop frontend:

$ n98-magerun.phar dev:translate:shop [store_code]

Toggle for admin area:

$ n98-magerun.phar dev:translate:admin

Profiler

Toggle profiler for debugging a store:

$ n98-magerun.phar dev:profiler [--on] [--off] [--global] [store]

Development Logs

Activate/Deactivate system.log and exception.log for a store:

$ n98-magerun.phar dev:log [--on] [--off] [--global] [store]

Show size of a log file:

$ n98-magerun.phar dev:log:size [log_filename]

Activate/Deactivate MySQL query logging via lib/Varien/Db/Adapter/Pdo/Mysql.php

$ n98-magerun.phar dev:log:db [--on] [--off]

Setup Script Generation

Generate Script for attributes:

$ n98-magerun.phar dev:setup:script:attribute entityType attributeCode

i.e.

$ n98-magerun.phar dev:setup:script:attribute catalog_product color

Currently only catalog_product entity type is supported.

Development IDE Support

PhpStorm Code Completion -> Meta file generation.

$ n98-magerun.phar dev:ide:phpstorm:meta [--stdout]

Reports

Prints count of reports in var/reports folder.

$ n98-magerun.phar dev:report:count

Resolve/Lookup Class Names

Resolves the given type and grouped class name to a class name, useful for debugging rewrites.

$ n98-magerun.phar dev:class:lookup <block|model|helper> <name>

Example:

$ n98-magerun.phar dev:resolve model catalog/product

Toggle Symlinks

Allow usage of symlinks for a store-view:

$ n98-magerun.phar dev:symlinks [--on] [--off] [--global] [store_code]

Global scope can be set by not permitting store_code parameter:

$ n98-magerun.phar dev:symlinks

Create Module Skel

Creates an empty module and registers it in current magento shop:

$ n98-magerun.phar dev:module:create [--add-blocks] [--add-helpers] [--add-models] [--add-setup] [--add-all] [--modman] [--add-readme] [--add-composer] [--author-name[="..."]] [--author-email[="..."]] [--description[="..."]] vendorNamespace moduleName [codePool]

Code-Pool defaults to local.

Example:

$ n98-magerun.phar dev:module:create MyVendor MyModule
  • --modman option creates a new folder based on vendorNamespace and moduleName argument.

Run this command inside your .modman folder.

  • --add-all option add blocks, helpers and models.
  • --add-readme Adds a readme.md file to your module.
  • --add-composer Adds a composer.json to your module.
  • --author-email Author email for composer.json file.
  • --author-name Author name for composer.json file.

List Modules

Lists all installed modules with codepool and version

$ n98-magerun.phar dev:module:list  [--codepool[="..."]] [--status[="..."]] [--vendor=[="..."]]

Rewrite List

Lists all registered class rewrites:

$ n98-magerun.phar dev:module:rewrite:list

Rewrite Conflicts

Lists all duplicated rewrites and tells you which class is loaded by Magento. The command checks class inheritance in order of your module dependencies.

$ n98-magerun.phar dev:module:rewrite:conflicts [--log-junit="..."]
  • If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.

Observer List

Lists all registered observer by type.

$ n98-magerun.phar dev:module:observer:list [type]

Type is one of "adminhtml", "global", "frontend".

Theme List

Lists all frontend themes

$ n98-magerun.phar dev:theme:list

Find Duplicates in your theme

Find duplicate files (templates, layout, locale, etc.) between two themes.

$ n98-magerun.phar dev:theme:duplicates [--log-junit="..."] theme [originalTheme]
  • originTheme default is "base/default".

Example:

$ n98-magerun.phar dev:theme:duplicates default/default
  • If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.

List Extensions

List and find connect extensions by a optional search string:

$ n98-magerun.phar extension:list <search>
  • Requires Magento's mage shell script.
  • Does not work with Windows as operating system.

Install Extensions

Installs a connect extension by package key:

$ n98-magerun.phar extension:install <package_key>

If the package could not be found a search for alternatives will be done. If alternatives could be found you can select the package to install.

  • Requires Magento's mage shell script.
  • Does not work with Windows as operating system.

Download Extensions

Downloads connect extensions by package key:

$ n98-magerun.phar extension:download <search>
  • Requires Magento's mage shell script.
  • Does not work with Windows as operating system.

Upgrade Extensions

Upgrade connect extensions by package key:

$ n98-magerun.phar extension:upgrade <search>
  • Requires Magento's mage shell script.
  • Does not work with Windows as operating system.

Magento Installer

Since version 1.1.0 we deliver a Magento installer which does the following:

  • Download Magento by a list of git repos and zip files (mageplus, magelte, official community packages).
  • Try to create database if it does not exist.
  • Installs Magento sample data if available (since version 1.2.0).
  • Starts Magento installer
  • Sets rewrite base in .htaccess file

Interactive installer:

$ n98-magerun.phar install

Unattended installation:

$ n98-magerun.phar install [--magentoVersion[="..."]] [--magentoVersionByName[="..."]] [--installationFolder[="..."]] [--dbHost[="..."]] [--dbUser[="..."]] [--dbPass[="..."]] [--dbName[="..."]] [--installSampleData[="..."]] [--useDefaultConfigParams[="..."]] [--baseUrl[="..."]] [--replaceHtaccessFile[="..."]]

Example of an unattended Magento CE 1.7.0.2 installation:

$ n98-magerun.phar install --dbHost="localhost" --dbUser="mydbuser" --dbPass="mysecret" --dbName="magentodb" --installSampleData=yes --useDefaultConfigParams=yes --magentoVersionByName="magento-ce-1.7.0.2" --installationFolder="magento" --baseUrl="http://magento.localdomain/"

See it in action: http://youtu.be/WU-CbJ86eQc

Magento Uninstaller

Uninstalls Magento: Drops your database and recursive deletes installation folder.

$ n98-magerun.phar uninstall [-f|--force]

Please be careful: This removes all data from your installation.

n98-magerun Shell

If you need autocompletion for all n98-magerun commands you can start with "shell command".

$ n98-magerun.phar shell

n98-magerun Script

Run multiple commands from a script file.

$ n98-magerun.phar script filename

Example:

# Set multiple config
config:set "web/cookie/cookie_domain" example.com

# This is a comment
cache:flush

Optionally you can work with unix pipes.

$ echo "cache:flush" | n98-magerun-dev script
$ n98-magerun-dev script < filename

It is even possible to create executable scripts:

Create file test.magerun and make it executable (chmod +x test.magerun):

#!/usr/bin/env n98-magerun.phar script

config:set "web/cookie/cookie_domain" example.com
cache:flush

# Run a shell script with "!" as first char
! ls -l

# Register your own variable (only key = value currently supported)
${my.var}=bar

# Let magerun ask for variable value - add a question mark
${my.var}=?

! echo ${my.var}

# Use resolved variables from n98-magerun in shell commands
! ls -l ${magento.root}/code/local

Pre-defined variables:

  • ${magento.root} -> Magento Root-Folder
  • ${magento.version} -> Magento Version i.e. 1.7.0.2
  • ${magento.edition} -> Magento Edition -> Community or Enterprise
  • ${magerun.version} -> Magerun version i.e. 1.66.0
  • ${php.version} -> PHP Version

Autocompletion

Bash

Copy the file bash_complete as n98-magerun.phar in your bash autocomplete folder. In my Ubuntu system this can be done with the following command:

$ sudo cp autocompletion/bash/bash_complete /etc/bash_completion.d/n98-magerun.phar

PHPStorm

An commandline tool autocompletion XML file for PHPStorm exists in subfolder autocompletion/phpstorm. Copy n98_magerun.xml in your phpstorm config folder.

Linux: ~/.WebIde50/config/commandlinetools

You can also add the XML content over settings menu. For further instructions read this blog post: http://blog.jetbrains.com/webide/2012/10/integrating-composer-command-line-tool-with-phpstorm/

Advanced usage

Add your own commands

https://github.com/netz98/n98-magerun/wiki/Add-custom-commands

Overwrite default settings

Create the yaml config file ~/.n98-magerun.yaml. Now you can define overwrites. The original config file is config.yaml in the source root folder.

Change of i.e. default currency and admin users:

commands:
  N98\Magento\Command\Installer\InstallCommand:
    installation:
      defaults:
        currency: USD
        admin_username: myadmin
        admin_firstname: Firstname
        admin_lastname: Lastname
        admin_password: mydefaultSecret
        admin_email: [email protected]

Add own Magento repositories

Create the yaml config file ~/.n98-magerun.yaml. Now you can define overwrites. The original config file is config.yaml in the source root folder.

Add you repo. The keys in the config file following the composer package structure.

Example:

commands:
  N98\Magento\Command\Installer\InstallCommand:
    magento-packages:
      - name: my-magento-git-repository
        version: 1.x.x.x
        source:
          url: git://myserver/myrepo.git
          type: git
          reference: 1.x.x.x
        extra:
          sample-data: sample-data-1.6.1.0

      - name: my-zipped-magento
        version: 1.7.0.0
        dist:
          url: http://www.myserver.example.com/magento-1.7.0.0.tar.gz
          type: tar
        extra:
          sample-data: sample-data-1.6.1.0

How can you help?

  • Add new commands
  • Send me some proposals if you miss anything
  • Create issues if you find a bug or missing a feature.

Thanks to

  • Symfony2 Team for the great console component.
  • Composer Team for the downloader backend and the self-update command.
  • Francois Zaninotto for great Faker library

About

Provides some handy tools for magento developers like a quick database info from local.xml or a database dump feature, cache clearing, admin user password reset. You can also easily install a complete shop and sample data with buildin installer. For coders there are also many features like a module kickstarter (with modman support). If something…

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%