n98-magerun2 – Project Update 2014-12

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.

Installer

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

1

2

3

4

5

6

7

8

9

10

11

12

13

/**

* @param \Symfony\Component\Console\Input\InputInterface $input

* @param \Symfony\Component\Console\Output\OutputInterface $output

* @throws \InvalidArgumentException

* @return void

*/

protectedfunctionexecute(InputInterface$input,OutputInterface$output)

{

// ...

$baseConfig=$this-&gt;getHelper('magento')-&gt;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”.

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.