/n98-magerun

The swiss army knife for Magento developers, sysadmins and devops. The tool provides a huge set of well tested command line commands which safe hours of work time. All commands are extendable by a module API.

Primary LanguagePHPOtherNOASSERTION

netz98 magerun CLI tools

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

Build Status

Latest Release

image

image

image

Development Branch

image

Compatibility

The tools will automatically be tested for multiple PHP versions (5.3, 5.4, 5.5). It's 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

or if you have problems with SSL certificate:

You can make the .phar file executable.

If you want to use the command system wide you can copy it to /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:

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 installations 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 the .phar file installed system wide you can call it with the PHP CLI interpreter:

php n98-magerun.phar list

Global config parameters:

--root-dir

Force Magento root dir. No auto detection.

--skip-config

Do not load any custom config.

--skip-root-check

Do not check if n98-magerun runs as root.

Open Shop in Browser

Customer Info

Loads basic customer info by email address.

Create customer

Creates a new customer/user for shop frontend.

Example:

Delete Customers

This will delete a customer by a given Id/Email, delete all customers or delete all customers in a range of Ids.

Examples:

Generate Dummy Customers

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

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).

Change customer password

  • Website parameter must only be given if more than one websites are available.

Print database information

Arguments

setting Only output value of named setting

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

Only the mysqldump command:

Or directly to stdout:

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

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

Available Table Groups:

  • @log Log tables
  • @dataflowtemp Temporary tables of the dataflow import/export tool
  • @stripped Standard definition for a stripped dump (logs, sessions 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.
  • @search Search related tables (catalogsearch)
  • @development Removes logs, sessions 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

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

Optimize "human readable" dump:

Database Console / MySQL Client

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

  • Requires MySQL CLI tools

Database Create

Create currently configured database

Database Drop

Drops the database configured in local.xml.

  • Requires MySQL CLI tools

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

Database Variables

See the most important MySQL variables of your Magento instance.

Database Status

This command is useful to print important server status information about the current database.

Dump Media folder

Creates a ZIP archive with media folder content.

If strip option is set, the following folders are excluded:

  • js (combined js files)
  • css (combined css files)
  • catalog/product/cache

List Indexes

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.

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

i.e.

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.

Generate local.xml file

Config Dump

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

Examples

Config of catalog module:

See module order in XML:

Write output to file:

Set Config

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

Arguments:

path The config path

Options:

--scope The config value's scope (default, websites, stores) --scope-id The config value's scope ID --decrypt Decrypt the config value using local.xml's crypt key --update-script Output as update script lines --magerun-script Output for usage with config:set --format Output as json, xml or csv

Help:

If path is not set, all available config items will be listed. path may contain wildcards (*)

Example:

Delete Config

Arguments:

path The config path

Options:

--scope The config scope (default, websites, stores) --scope-id The config value's scope ID --all Deletes all entries of a path (ignores --scope and --scope-id)

Search system configuration descriptions.

List Magento cache status

Clean Magento cache

Cleans expired cache entries.

If you would like to clean only one cache type:

If you would like to clean multiple cache types at once:

If you would like to remove all cache entries use cache:flush

Run cache:list command to see all codes.

Remove all cache entries

List Magento caches

Disable Magento cache

If no code is specified, all cache types will be disabled. Run cache:list command to see all codes.

Enable Magento cache

If no code is specified, all cache types will be enabled. Run cache:list command to see all codes.

Cache Report

This command let you investigate what's stored inside your cache. It prints out a table with cache IDs.

Cache View

Prints stored cache entry by ID.

If value is serialized you can force a pretty output with --unserialize option.

Demo Notice

Toggle demo store notice

List admin users

Create admin user

Change admin user password

Delete admin user

ID can be e-mail or username. The command will attempt to find the user by username first and if it cannot be found it will attempt to find the user by e-mail. If ID is omitted you will be prompted for it. If the force parameter "-f" is omitted you will be prompted for confirmation.

Unlock admin user

Releases the password lock on an admin (leave blank to unlock all admins)

Disable admin notifications

Toggle admin notifications.

Maintenance mode

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

Magento system info

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

Magento Stores

Lists all store views.

Magento Store Config - BaseURLs

Lists base urls for each store.

Magento Websites

Lists all websites.

List Cronjobs

Lists all cronjobs defined in config.xml files.

Run Cronjob

Runs a cronjob by code.

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.

List URLs

Examples:

  • Create a list of product urls only:
  • 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):
  • 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.

Run Setup Scripts Incrementally

Runs setup scripts incrementally. (no need to call frontend). This command runs each new setup script individually in order to increase the transparency of the setup resource system, and reduce the chances of a PHP failure creating an invalid database state.

Compare Setup Versions

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

  • If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.

Change Setup Version

Changes the version of one or all module resource setups. This command is useful if you want to re-run an upgrade script again possibly due to debugging. Alternatively you would have to alter the row in the database manually.

Setup argument default is "all resources" for the given module.

Remove Setup Version

Removes the entry for one or all module resource setups. This command is useful if you want to re-run an install script again possibly due to debugging. Alternatively you would have to remove the row from the database manually.

Setup argument default is "all resources" for the given module.

System Check

  • Checks missing files and folders
  • Security
  • PHP Extensions (Required and Bytecode Cache)
  • MySQL InnoDB Engine

CMS: Toggle Banner

Hide/Show CMS Banners

CMS: Publish a page

Publishes a page by page id and revision.

Useful to automatically publish a page by a cron job.

Interactive Development Console

Opens PHP interactive shell with initialized Magento Admin-Store.

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

Template Hints Blocks

Toggle debug template hints blocks settings of a store

Inline Translation

Toggle settings for shop frontend:

Toggle for admin area:

Export Inline Translation

Exports saved database translation data into a file.

Profiler

Toggle profiler for debugging a store:

Development Logs

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

Show size of a log file:

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

Setup Script Generation

Generate Script for attributes:

i.e.

Currently only catalog_product entity type is supported.

EAV Attributes

List all EAV attributes:

View the data for a particular attribute:

Remove an attribute:

You can also remove multiple attributes in one go if they are of the same type

Development IDE Support

PhpStorm Code Completion -> Meta file generation.

Reports

Prints count of reports in var/reports folder.

Resolve/Lookup Class Names

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

Example:

Allow usage of symlinks for a store-view:

Global scope can be set by not permitting store_code parameter:

Create Module Skel

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

Code-Pool defaults to local.

Example:

* --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.

Enable/Disable Module in Declaration

Enable or disable a module in app/etc/modules/*.xml by name or codePool:

Examples:

Hint

If --codepool option is specified all modules in the codepool are affected.

List Modules

Lists all installed modules with codepool and version

Rewrite List

Lists all registered class rewrites.

sh

$ n98-magerun.phar dev:module:rewrite:list [--format[="..."]]

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.

  • If a filename with --log-junit option is set the tool generates an XML file and no output to stdout.

Module Dependencies

Show list of modules which given module depends on

Show list of modules which depend from module

Observer List

Lists all registered observer by type.

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

Theme List

Lists all frontend themes

Find Duplicates in your theme

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

  • originTheme default is "base/default".

Example:

  • 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:

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

Install Extensions

Installs a connect extension by 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:

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

Upgrade Extensions

Upgrade connect extensions by package key:

  • 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:

  • Downloads Magento by a list of git repos and zip files (mageplus, magelte, official community packages).
  • Tries 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:

Unattended installation:

Example of an unattended Magento CE 1.7.0.2 installation:

Additionally, with --noDownload option you can install Magento working copy already stored in --installationFolder on the given database.

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

Magento Uninstaller

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

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

--installationFolder is required and if you do not enter it you will be prompted for it. This should be your project root, not the Magento root. For example, If your project root is /var/www/site and Magento src is located at /var/www/site/htdocs, you should pass /var/www/site to the command, or if you are currently in that particular directory you can just pass "." Eg:

If you omit the -f, you will be prompted for confirmation.

n98-magerun Shell

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

n98-magerun Script

Run multiple commands from a script file.

Example:

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

# Set with multiline values with "\n"
config:set "general/store_information/address" "First line\nSecond line\nThird line"

# This is a comment
cache:flush

Optionally you can work with unix pipes.

It is even possible to create executable scripts:

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

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
  • ${script.file} -> Current script file path
  • ${script.dir} -> Current script file dir

Variables can be passed to a script with "--define (-d)" option.

Example:

It's possible to define multiple values by passing more than one option.

n98-magerun Script Repository

You can organize your scripts in a repository. Simply place a script in folder /usr/local/share/n98-magerun/scripts or in your home dir in folder <HOME>/.n98-magerun/scripts.

Scripts must have the file extension .magerun.

After that you can list all scripts with the script:repo:list command. The first line of the script can contain a comment (line prefixed with #) which will be displayed as description.

If you want to execute a script from the repository this can be done by script:repo:run command.

Script argument is optional. If you don't specify any you can select one from a list.

Autocompletion

Bash

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

PHPStorm

A commandline tool autocompletion XML file for PHPStorm exists in subfolder autocompletion/phpstorm. Copy n98_magerun.xml into 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:

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 your repo. The keys in the config file follow 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.

Bitdeli badge