Forest header image

Symfony Finland
Random things on PHP, Symfony and web development

eZ Platform data migrations with Doctrine

eZ Platform (and eZ Publish 5.x) use the Doctrine DBAL for connecting to the database. Using this commonly used layer and frameworks allows developers to use the same tools as for their custom applications implementations.

Learn more about Database Schema Migrations with Doctrine from this lightning talk from Diego Sapriza on Nomad PHP:

The DoctrineMigrationsBundle allows Symfony developers to perform migrations between environments using code. The eZPublishMigrationsBundle from Kreait adds eZ specific functionalities on top of that, but keeping the familiar migration interface.

Below is an example of using the bundle to create defined content:

namespace Application\Migrations;

use Kreait\EzPublish\MigrationsBundle\Migrations\EzPublishMigration;
use Doctrine\DBAL\Schema\Schema;

class Version20150610145137 extends EzPublishMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        $this->createContent(2, 'folder', 'eng-GB', [
            'name' => 'This is a new folder',
            'short_name' => 'New folder'
        ]);
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        // We probably should somehow delete the content again.
    }
}

Written by Jani Tarvainen on Tuesday March 15, 2016
Permalink -

« Debug emails in Symfony / eZ Platform / Publish with a file spool - Using the eZ Platform PHP API in Symfony Commands and Controllers »