Addon modules for n98-magerun
Some additional commands for the excellent N98-MageRun Magento command-line tool.
The purpose of this project is just to have an easy way to deploy new, custom commands that I need to use in various places. It's easier for me to do this than to maintain a fork of n98-magerun, but I'd be happy to merge any of these commands into the main n98-magerun project if desired.
There are a few options. You can check out the different options in the MageRun docs.
Here's the easiest:
Create ~/.n98-magerun/modules/ if it doesn't already exist.
mkdir -p ~/.n98-magerun/modules/
Clone the magerun-addons repository in there
cd ~/.n98-magerun/modules/ && git clone https://github.com/peterjaap/magerun-addons.git pj-addons
It should be installed. To see that it was installed, check to see if one of the new commands is in there, like media:sync.
n98-magerun.phar media:syncThis command lets you sync the /media folder over SSH (requires rsync) or FTP (requires ncftpget). You can choose to run this command either interactively or non-interactively.
$ n98-magerun.phar media:syncThis will spawn a few CLI dialogs asking you to synchronize using either SSH or FTP. After, that a few runtime options are asked for, of which SSH requires (obligatory) at least the following: host and username. When using the FTP mode, at least host, username and password are required.
The SSH mode does not allow a password values. Besides it not being supported by rsync, you should definitely set up SSH to function with key based authorization.
Additionally, you can set an alternative port for SSH, a path (both SSH and FTP) on the remote host to synchronize from (/media will be appended) and a comma-separated list with paths to exclude. Any *cache* directories will be excluded by default. Sadly, ncftpget does not support directory exclusion. Therefore - also due to security concerns of supplying a password on a CLI - using the SSH mode is recommended.
$ n98-magerun.phar media:sync --mode=[ssh|ftp]Non-interactive mode is similar to the interactive mode, except that all listed runtime options as described above, have to be supplied as command options. For example:
$ n98-magerun.phar media:sync --mode=ssh --host=yourhost.com --username=yourusername
$ n98-magerun.phar media:sync --mode=ftp --host=yourhost.com --username=yourusername --password=yourpassword --ignore-permissions=true --path=public_htmlNon-interactive mode is useful in, for example, a deployment or synchronization script which is executed automatically.
It is possible to have persistent configuration to further simplify the execution of the command. Both the interactive and non-interactive mode will first check the app/etc/local.xml file whether any configuration is present.
Configuration can be supplied in the following format:
...
yourhost.com
yourusername
public_html
true
... OR ...
yourhost.com
yourusername
yourpassword
public_html
...This commands gives you an easy tool to quickly add an attribute to an attribute set, or even multiple (and all).
$ n98-magerun.phar eav:attributes:add-to-setThis will allow you to merge two existing product attributes together; all product values will be updated accordingly.
$ n98-magerun.phar eav:attributes:mergeThis will automatically find duplicate attribute options for a given attribute (for example, merge option Blue into a different option with the same name Blue for attribute color).
Beware; this will ignore any translated option values as it will just pick the last attribute option from the query to keep.
$ n98-magerun.phar eav:attributes:undupe-optionsMagerun already has an option to show a list of set base URL's but no way to set them easily. It is possible through config:set but this is cumbersome. This command gives you a list of storeviews to choose from and asks you for your base URL. You have the option to set both the unsecure and the secure base URL.
$ n98-magerun.phar sys:store:config:base-url:setClean media tables by deleting rows with references to non-existing image.
$ n98-magerun.phar media:images:cleantablesSet the default for a product where an image is available but isn't selected.
$ n98-magerun.phar media:images:defaultimageRemove duplicate image files from disk and database. This command compares files using the fdupes library.
$ n98-magerun.phar media:images:removeduplicatesRemove orphaned files from disk. Orphans are files which do exist on the disk but are not found the database.
$ n98-magerun.phar media:images:removeorphansA large number of customers enter their Tax/VAT number incorrectly. Common mistakes are prefixing the country code and using dots and/or spaces. This command loops through the taxvat fields already in the database and cleans them up. So 'nl 01.23.45.67 b01' (which won't validate) will become '01234567B01' (which will validate). This is useful for future purchases by these customers.
$ n98-magerun.phar customer:clean-taxvatThanks to @timvroom for the bulk of the code.
dev:template-vars [--addblocks[="true|false"]] [--addvariables[="true|false"]]$ n98-magerun.phar dev:old-admin-routing$ n98-magerun.phar dev:possible-sql-injection$ n98-magerun.phar dev:entity:inspect --order 1234 [--filter="shipping"]This will give you all getData() parameters from the requested order object, along with invoices & creditmemos that belong to that order in a nice table format. Optional filter parameter to filter output on parameter name. Might be extended in the future to be more abstract and be able to load any given entity in Magento.
Example output;
… $ n98-magerun.phar dev:events:listThis will give you a list of all events that are listened to by observers, by which module and by which class & method. Example output;
customer_login (catalog) catalog/product_compare_item::bindCustomerLogin
customer_login (loadCustomerQuote) checkout/observer::loadCustomerQuote
customer_login (log) log/visitor::bindCustomerLogin
customer_login (reports) reports/event_observer::customerLogin
customer_login (wishlist) wishlist/observer::customerLogin
customer_login (persistent) persistent/observer_session::synchronizePersistentOnLoginIt will also give a warning if an event is listened to that contains an uppercased letter, since this has changed in SUPEE-7405 / Magento 1.9.2.3. See http://magento.stackexchange.com/questions/98220/security-patch-supee-7405-possible-problems for more info.
$ n98-magerun.phar dev:events:listenWhen running this command, magerun will edit app/Mage.php to log the events to a temporary log file. This file will consequently being 'tailed'. When hitting CTRL-C the command will revert the adjustment to app/Mage.php and clean up the log file.
When building extensions, you often need to fire a certain event to trigger a function. With this command, you can choose one of the default events that can be found in the Magento core, or type in the name of another (custom) event. The command will also ask for any parameters.
You can instantiate an object and load a record into that object. You do this by using as parameter value 'Mage_Catalog_Model_Product:1337'. This will instantiate the model Mage_Catalog_Model_Product and load entity 1337 in that model.
$ n98-magerun.phar dev:events:fireIt is also possible to give command line arguments. These are '--event' (-e for shortcut) and '--parameters' (-p for shortcut). Parameters can contain multiple parameters, in which the various parameters should be stringed together with ';' and the name/value pair should be stringed together with '::'. Be sure to enclose this in double quotes.
$ n98-magerun.phar dev:events:fire --event your_event_that_will_fire --parameters "product::Mage_Catalog_Model_Product:1337;testparam::testvalue"
Event your_event_that_will_fire has been fired with parameters;
- object product: Mage_Catalog_Model_Product ID 196744
- testparam: testvalueThis command lets you choose a language code and an installed extension. It will then look for translatable strings (strings that are run through __()) and look for its translation in the set language. It shows a table with the (un)translated strings and generates a pre-structured (and pre-filled, if applicable) locale (csv) file.
$ n98-magerun.phar extension:translationsSome core_url_rewrite tables get very large due to various reasons. With this command, you can export the custom core rewrite URLs to an Apache or nginx configuration file to offload rewriting these URLs to the server instead of application level, giving you the chance to remove these rewrites from the database.
$ n98-magerun.phar sys:store:url:rewrites:exportThe migrate:delta command that is part of the Magento 2 Data Migration tool works a little bit different than I expected; it needs a constant connection to the Magento 1 database (from the Magento 2 server). This assumes a few things;
This magerun command fills the changelog tables in your Magento 1 database in hindsight; it compares what already is in the Magento 2 database and creates entries for the missing entities. This allows you to run the delta import locally with a fresh database dump from the production server.
$ n98-magerun.phar m2-migration:delta-update-changelogThanks to Netz98 for creating the awesome Swiss army knife for Magento, magerun. And thanks to Kalen Jordan for showing me a blueprint on how to create modules for magerun by looking at [his addons](https://github.com/kal
No open issues yet, or sync has not completed.