Skip over navigation
Documentation
You are currently viewing documentation for a previously released version of OroCommerce. See the latest long-term support version.

Customizing the Installation Process

To customize the installation process and modify the database structure and/or data that are loaded in the OroCommerce after installation, you can:

Execute Custom Migrations

You can create your own migrations that can be executed during the installation. A migration is a class which implements the Migration interface:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// src/Acme/DemoBundle/Migration/CustomMigration.php
namespace Acme\DemoBundle\Migration;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class CustomMigration implements Migration
{
    public function up(Schema $schema, QueryBag $queries)
    {
        // ...
    }
}

In the up(), you can modify the database schema and/or add additional SQL queries that are executed before and after the schema changes.

The MigrationsLoader dispatches two events when migrations are being executed, oro_migration.pre_up and oro_migration.post_up. You can listen to either event and register your own migrations in your event listener. Use the addMigration() method of the passed event instance to register your custom migrations:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// src/Acme/DemoBundle/EventListener/RegisterCustomMigrationListener.php
namespace Acme\DemoBundle\EventListener;

use Acme\DemoBundle\Migration\CustomMigration;
use Oro\Bundle\MigrationBundle\Event\PostMigrationEvent;
use Oro\Bundle\MigrationBundle\Event\PreMigrationEvent;

class RegisterCustomMigrationListener
{
    // listening to the oro_migration.pre_up event
    public function preUp(PreMigrationEvent $event)
    {
        $event->addMigration(new CustomMigration());
    }

    // listening to the oro_migration.post_up event
    public function postUp(PostMigrationEvent $event)
    {
        $event->addMigration(new CustomMigration());
    }
}

Tip

You can learn more about custom event listeners in the Symfony documentation.

Migrations registered in the oro_migration.pre_up event are executed before the main migrations while migrations registered in the oro_migration.post_up event are executed after the main migrations have been processed.

Load Custom Data Fixtures

To load your own data fixtures, you will need to implement Doctrine’s “FixtureInterface”:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// src/Acme/DemoBundle/Migrations/Data/ORM/CustomFixture.php
namespace Acme\DemoBundle\Migrations\Data\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class CustomFixture implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        // ...
    }
}

Caution

Your data fixture classes must reside in the “Migrations/Data/ORM” sub-directory of your bundle to be loaded automatically during the installation.

Tip

Read the doctrine data fixtures documentation to learn more about the Doctrine Data Fixtures extension.

ForumsForums
Back to top