n98-magerun2 – Project Update 2014-12

Published by Christian Münch on

n98-magerun2 Updated

Last month we started the development of Version 2 of n98-magerun which will only run with Magento 2.
After the official release of Magento 2 Dev-Beta 1 we must change some parts of the tool according to some refactored stuff in Magento 2.
If you checkout the code on github please note that we port any command one at a time.
This is why we don’t only add the same features, we also refactor all the code we put into the n98-magerun2 code base.

As one of the first thing we did a complete refactor of the “install” command.


The new installer got a big refactoring. All the code is now organized in sub-commands. Sub-Commands are a new feature which should help us to cluster code of big commands (like the installer) into peaces of small code which is much better to extend and maintain.

The sub-command classes can be found in new namespace N98\Magento\Command\SubCommand.
There is an interface which must be implemented and a Abstract class which does the most the of work for you.


The main installer commands like like this now:

 * @param InputInterface $input
 * @param OutputInterface $output
 * @throws \RuntimeException
 * @return int|null|void
protected function execute(InputInterface $input, OutputInterface $output)
    $this->commandConfig = $this->getCommandConfig();
    $this->writeSection($output, 'Magento 2 Installation');

    $subCommandFactory = $this->createSubCommandFactory(
        'N98\Magento\Command\Installer\SubCommand' // sub-command namespace

    // @todo load commands from config
    $output->writeln('<info>Successfully installed magento</info>');

Is that great? I hope you can see the difference.

The new installer command works like in Version 1 with one big difference. The main repository will be cloned and
all depencies are now fetched by composer. If you have composer installed on your system and n98-magerun2 can find
it we use the existing composer to install packages. If composer cannot be found we download and install composer
automatically in the new created Magento 2 root folder. So you can use composer after the installation.

Currently we found an issue in the sample data composer package. We hope the issue will be resolved soon.

Test System

We setup Travis for our QA. Like Magento 2 we dropped support for 5.3 and test only PHP 5.4 and PHP 5.5.
Magento 2 requires also at least MySQL 5.6. This is not available on Travis servers. How can we test now with Travis?
We looked at Magento 2 Travis file and found the solution. Travis supports installing 3rd party packages on testing platform.
This can be done, because after every build a snapshot of the system (before the test) will be restored.
So we copied the travis file code into ours and now we are able to test the complete n98-magerun installation.
Thanks to the Magento 2 core developers for the great setup.

The unit test framework is now also up to date to start test driven development.


DB Commands

We already ported all DB related commands from Version 1.

  • db:console
  • db:create
  • db:drop
  • db:dump
  • db:import
  • db:info
  • db:maintain:check-tables
  • db:query
  • db:status
  • db:variables

There are some changes from Magento 1 to Magento 2. The first thing we investigated was the removed app/etc/local.xml file.
The config is now saved in the new file app/etc/config.php. This change to PHP offers us some new capabilities. The config can now contain ENV vars which is great in combination with i.e. docker.
The bad part is that other systems cannot process them like the old XML file.

In n98-magerun2 we changed the DatabaseHelper. The base config is now loaded in MagentoHelper.
If you need the base config you can load the config array in a command without Magento initalization.

 * @param \Symfony\Component\Console\Input\InputInterface   $input
 * @param \Symfony\Component\Console\Output\OutputInterface $output
 * @throws \InvalidArgumentException
 * @return void
protected function execute(InputInterface $input, OutputInterface $output)
    // ...
    $baseConfig = $this->getHelper('magento')->getBaseConfig();
    // ...

The DB part could be refactored so that no code-change is needed.
The DB settings can be loaded like in “n98-magerun 1”.

 * @param \Symfony\Component\Console\Input\InputInterface   $input
 * @param \Symfony\Component\Console\Output\OutputInterface $output
 * @throws \InvalidArgumentException
 * @return void
protected function execute(InputInterface $input, OutputInterface $output)
    // ...
    $database = $this->getHelper('database'); /* @var $database DatabaseHelper */

    $settings = $database->getDbSettings();
    // ...

If you are wondering where the tests are located… we added a new “dev” folder in the project root.

Please help us to test the n98-magerun2 code. We also accept pull requests for the develop branch. Please don’t update
the phar file. The phar file only exists in the master branch. We don’t build it in the develop branch.

If you search for the new features in master branch… We have not merged it yet. The phar file is not up to date.
Please use the develop branch to test the new features.


n98-magerun für Magento 2 am Start · January 3, 2015 at 15:10

[…] Wer es schon kennt und sich das Thema Magento 2 und CLI Tool mal genauer anschauen möchte (Ich schaue in die Runde der Administratoren und Magento-Entwickler!): http://magerun.net/n98-magerun2-project-update-2014-12/ […]

Magento-Neuigkeiten #29 · January 11, 2015 at 19:11

[…] n98-magerun2 wird fleißig gearbeitet. Christian Münch gab dazu ein Project-Update. Am 28.12. waren bereits 11% der Befehle […]

n98-magerun für Magento 2 am Start - Ralf Lieser · January 31, 2020 at 16:44

[…] Wer es schon kennt und sich das Thema Magento 2 und CLI Tool mal genauer anschauen möchte (Ich schaue in die Runde der Administratoren und Magento-Entwickler!): http://magerun.net/n98-magerun2-project-update-2014-12/ […]

Leave a Reply

Avatar placeholder

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.