Important
You are browsing the documentation for version 3.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
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 Oro\Bundle\MigrationBundle\Migration\Migration
interface:
1// src/Acme/DemoBundle/Migration/CustomMigration.php
2namespace Acme\DemoBundle\Migration;
3
4use Doctrine\DBAL\Schema\Schema;
5use Oro\Bundle\MigrationBundle\Migration\Migration;
6use Oro\Bundle\MigrationBundle\Migration\QueryBag;
7
8class CustomMigration implements Migration
9{
10 public function up(Schema $schema, QueryBag $queries)
11 {
12 // ...
13 }
14}
In the Oro\Bundle\MigrationBundle\Migration\Migration::up
, you can modify the database schema and/or add additional SQL queries that are executed before and after the schema changes.
you can modify the database schema and/or add additional SQL queries that
are executed before and after the schema changes.
The Oro\Bundle\MigrationBundle\Migration\Loader\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
Oro\Bundle\MigrationBundle\Event\MigrationEvent::addMigration()
method
of the passed event instance to register your custom migrations:
1// src/Acme/DemoBundle/EventListener/RegisterCustomMigrationListener.php
2namespace Acme\DemoBundle\EventListener;
3
4use Acme\DemoBundle\Migration\CustomMigration;
5use Oro\Bundle\MigrationBundle\Event\PostMigrationEvent;
6use Oro\Bundle\MigrationBundle\Event\PreMigrationEvent;
7
8class RegisterCustomMigrationListener
9{
10 // listening to the oro_migration.pre_up event
11 public function preUp(PreMigrationEvent $event)
12 {
13 $event->addMigration(new CustomMigration());
14 }
15
16 // listening to the oro_migration.post_up event
17 public function postUp(PostMigrationEvent $event)
18 {
19 $event->addMigration(new CustomMigration());
20 }
21}
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// src/Acme/DemoBundle/Migrations/Data/ORM/CustomFixture.php
2namespace Acme\DemoBundle\Migrations\Data\ORM;
3
4use Doctrine\Common\DataFixtures\FixtureInterface;
5use Doctrine\Common\Persistence\ObjectManager;
6
7class CustomFixture implements FixtureInterface
8{
9 public function load(ObjectManager $manager)
10 {
11 // ...
12 }
13}
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.