<?php
/**
* About this file
* https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/MigrationBundle/README.md
*
* About extra options for this file
* https://github.com/orocrm/platform/tree/master/src/Oro/Bundle/EntityExtendBundle
*
* // Dispay current database structure
* php app/console oro:migration:dump
*
* // See what is going to happen when executing the migration script with list of database queries for each migration file in the bundle
* php app/console oro:migration:load --dry-run --show-queries --bundles AcmeMyBundle
*
* // Execute the migration script with list of database queries for each migration file in the bundle
* php app/console oro:migration:load --force --show-queries --bundles AcmeMyBundle
*
* How to revert migration version to execute this again
* => Update the table oro_migrations
*/
namespace Acme\Bundle\MyBundle\Migrations\Schema\v1_1;
use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;
use Oro\Bundle\EntityExtendBundle\Migration\ExtendOptionsManager;
class OroUserBundle implements Migration, ExtendExtensionAwareInterface
{
/** @var ExtendExtension */
protected $extendExtension;
/**
* {@inheritdoc}
*/
public function setExtendExtension(ExtendExtension $extendExtension)
{
$this->extendExtension = $extendExtension;
}
/**
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function up(Schema $schema, QueryBag $queries)
{
// @codingStandardsIgnoreStart
/** Extend table oro_user **/
$table = $schema->getTable('oro_user');
/**
* Delete pre-existing field
*
* I wish I could "update" instead of "delete and add" here.
* I tried to do $this->extendExtension->extendOptionsManager->setColumnOptions()
* and realized the property $extendOptionsManager in $this->extendExtension is Private
* and there is no Getter Method to refer the class
* (I don't know if it works by just executing setColumnOptions(), though).
*/
if ($table->hasColumn('branch_id')) {
$table->dropColumn('branch_id');
}
$this->extendExtension->addManyToOneRelation(
$schema,
$table,
'branch',
'acme_branches',
'name',
[
'extend' => [
'is_extend' => true,
'owner' => ExtendScope::OWNER_CUSTOM,
'without_default' => true,
]
]
);
/** End of generate table orocrm_account **/
// @codingStandardsIgnoreEnd
}
}