Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.4' into 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Dec 1, 2014
2 parents 9c4d1e5 + 31e1911 commit 52a87e5
Show file tree
Hide file tree
Showing 51 changed files with 1,806 additions and 422 deletions.
2 changes: 1 addition & 1 deletion src/Oro/Bundle/AddressBundle/Entity/AbstractAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ abstract class AbstractAddress implements EmptyItem, FullNameInterface, AddressI
/**
* @var string
*
* @ORM\Column(name="postal_code", type="string", length=20, nullable=true)
* @ORM\Column(name="postal_code", type="string", length=255, nullable=true)
* @Soap\ComplexType("string", nillable=true)
* @ConfigField(
* defaultValues={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
use Oro\Bundle\AddressBundle\Migrations\Schema\v1_0\OroAddressBundle;

class OroAddressBundleInstaller implements Installation
{
Expand All @@ -14,22 +13,193 @@ class OroAddressBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v1_1';
return 'v1_2';
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
OroAddressBundle::oroAddressTable($schema);
OroAddressBundle::oroAddressTypeTable($schema);
OroAddressBundle::oroAddressTypeTranslationTable($schema);
OroAddressBundle::oroDictionaryCountryTable($schema);
OroAddressBundle::oroDictionaryCountryTranslationTable($schema, 'oro_dictionary_country_trans');
OroAddressBundle::oroDictionaryRegion($schema);
OroAddressBundle::oroDictionaryRegionTranslationTable($schema, 'oro_dictionary_region_trans');
/** Tables generation **/
$this->createOroAddressTable($schema);
$this->createOroAddressTypeTable($schema);
$this->createOroAddressTypeTranslationTable($schema);
$this->createOroDictionaryCountryTable($schema);
$this->createOroDictionaryCountryTransTable($schema);
$this->createOroDictionaryRegionTable($schema);
$this->createOroDictionaryRegionTransTable($schema);

/** Foreign keys generation **/
$this->addOroAddressForeignKeys($schema);
$this->addOroDictionaryRegionForeignKeys($schema);
}

/**
* Create oro_address table
*
* @param Schema $schema
*/
protected function createOroAddressTable(Schema $schema)
{
$table = $schema->createTable('oro_address');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('country_code', 'string', ['notnull' => false, 'length' => 2]);
$table->addColumn('region_code', 'string', ['notnull' => false, 'length' => 16]);
$table->addColumn('label', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('street', 'string', ['notnull' => false, 'length' => 500]);
$table->addColumn('street2', 'string', ['notnull' => false, 'length' => 500]);
$table->addColumn('city', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('postal_code', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('organization', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('region_text', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('name_prefix', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('first_name', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('middle_name', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('last_name', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('name_suffix', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('created', 'datetime', []);
$table->addColumn('updated', 'datetime', []);
$table->setPrimaryKey(['id']);
$table->addIndex(['country_code'], 'IDX_C5E99957F026BB7C', []);
$table->addIndex(['region_code'], 'IDX_C5E99957AEB327AF', []);
}

/**
* Create oro_address_type table
*
* @param Schema $schema
*/
protected function createOroAddressTypeTable(Schema $schema)
{
$table = $schema->createTable('oro_address_type');
$table->addColumn('name', 'string', ['length' => 16]);
$table->addColumn('label', 'string', ['length' => 255]);
$table->setPrimaryKey(['name']);
$table->addUniqueIndex(['label'], 'UNIQ_8B3E52E3EA750E8');
}

/**
* Create oro_address_type_translation table
*
* @param Schema $schema
*/
protected function createOroAddressTypeTranslationTable(Schema $schema)
{
$table = $schema->createTable('oro_address_type_translation');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('foreign_key', 'string', ['length' => 16]);
$table->addColumn('content', 'string', ['length' => 255]);
$table->addColumn('locale', 'string', ['length' => 8]);
$table->addColumn('object_class', 'string', ['length' => 255]);
$table->addColumn('field', 'string', ['length' => 32]);
$table->setPrimaryKey(['id']);
$table->addIndex(['locale', 'object_class', 'field', 'foreign_key'], 'address_type_translation_idx', []);
}

/**
* Create oro_dictionary_country table
*
* @param Schema $schema
*/
protected function createOroDictionaryCountryTable(Schema $schema)
{
$table = $schema->createTable('oro_dictionary_country');
$table->addColumn('iso2_code', 'string', ['length' => 2]);
$table->addColumn('iso3_code', 'string', ['length' => 3]);
$table->addColumn('name', 'string', ['length' => 255]);
$table->setPrimaryKey(['iso2_code']);
$table->addIndex(['name'], 'country_name_idx', []);
}

/**
* Create oro_dictionary_country_trans table
*
* @param Schema $schema
*/
protected function createOroDictionaryCountryTransTable(Schema $schema)
{
$table = $schema->createTable('oro_dictionary_country_trans');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('foreign_key', 'string', ['length' => 2]);
$table->addColumn('content', 'string', ['length' => 255]);
$table->addColumn('locale', 'string', ['length' => 8]);
$table->addColumn('object_class', 'string', ['length' => 255]);
$table->addColumn('field', 'string', ['length' => 32]);
$table->setPrimaryKey(['id']);
$table->addIndex(['locale', 'object_class', 'field', 'foreign_key'], 'country_translation_idx', []);
}

/**
* Create oro_dictionary_region table
*
* @param Schema $schema
*/
protected function createOroDictionaryRegionTable(Schema $schema)
{
$table = $schema->createTable('oro_dictionary_region');
$table->addColumn('combined_code', 'string', ['length' => 16]);
$table->addColumn('country_code', 'string', ['notnull' => false, 'length' => 2]);
$table->addColumn('code', 'string', ['length' => 32]);
$table->addColumn('name', 'string', ['length' => 255]);
$table->setPrimaryKey(['combined_code']);
$table->addIndex(['country_code'], 'IDX_8C71325AF026BB7C', []);
$table->addIndex(['name'], 'region_name_idx', []);
}

OroAddressBundle::addForeignKeys($schema);
/**
* Create oro_dictionary_region_trans table
*
* @param Schema $schema
*/
protected function createOroDictionaryRegionTransTable(Schema $schema)
{
$table = $schema->createTable('oro_dictionary_region_trans');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
$table->addColumn('foreign_key', 'string', ['length' => 16]);
$table->addColumn('content', 'string', ['length' => 255]);
$table->addColumn('locale', 'string', ['length' => 8]);
$table->addColumn('object_class', 'string', ['length' => 255]);
$table->addColumn('field', 'string', ['length' => 32]);
$table->setPrimaryKey(['id']);
$table->addIndex(['locale', 'object_class', 'field', 'foreign_key'], 'region_translation_idx', []);
}

/**
* Add oro_address foreign keys.
*
* @param Schema $schema
*/
protected function addOroAddressForeignKeys(Schema $schema)
{
$table = $schema->getTable('oro_address');
$table->addForeignKeyConstraint(
$schema->getTable('oro_dictionary_country'),
['country_code'],
['iso2_code'],
['onDelete' => null, 'onUpdate' => null]
);
$table->addForeignKeyConstraint(
$schema->getTable('oro_dictionary_region'),
['region_code'],
['combined_code'],
['onDelete' => null, 'onUpdate' => null]
);
}

/**
* Add oro_dictionary_region foreign keys.
*
* @param Schema $schema
*/
protected function addOroDictionaryRegionForeignKeys(Schema $schema)
{
$table = $schema->getTable('oro_dictionary_region');
$table->addForeignKeyConstraint(
$schema->getTable('oro_dictionary_country'),
['country_code'],
['iso2_code'],
['onDelete' => null, 'onUpdate' => null]
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Oro\Bundle\AddressBundle\Migrations\Schema\v1_2;

use Doctrine\DBAL\Schema\Schema;

use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class ChangeAddressPostalCodeLength implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$table = $schema->getTable('oro_address');
$table->changeColumn('postal_code', ['length' => 255]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Oro\Bundle\AddressBundle\Entity\AbstractAddress:

postalCode:
- Length:
max: 20
max: 255

country:
- NotBlank: ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ public function testPreUpdate($fieldType)
]
)
);
$extendConfigProvider->expects($this->once())
->method('persist')
->with($this->identicalTo($entityConfig));

$this->configManager->expects($this->once())
->method('getProvider')
Expand All @@ -94,6 +91,9 @@ public function testPreUpdate($fieldType)
$fieldName,
'id',
[
'extend' => [
'cascade' => ['persist']
],
'importexport' => [
'process_as_scalar' => true
]
Expand All @@ -103,11 +103,63 @@ public function testPreUpdate($fieldType)
->will($this->returnValue($relationKey));

$this->extension->preUpdate();
}

$this->assertEquals(
['persist'],
$entityConfig->get('relation')[$relationKey]['cascade']
);
/**
* @dataProvider preUpdateProvider
*/
public function testPreUpdateWithCascade($fieldType)
{
$entityClass = 'Test\Entity';
$fieldName = 'test_field';

$entityConfig = new Config(new EntityConfigId('extend', $entityClass));
$entityConfig->set('is_extend', true);

$fieldConfig = new Config(new FieldConfigId('extend', $entityClass, $fieldName, $fieldType));
$fieldConfig->set('state', ExtendScope::STATE_NEW);
$fieldConfig->set('cascade', ['persist', 'remove']);

$extendConfigProvider = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider')
->disableOriginalConstructor()
->getMock();
$extendConfigProvider->expects($this->exactly(2))
->method('getConfigs')
->will(
$this->returnValueMap(
[
[null, false, [$entityConfig]],
[$entityClass, false, [$fieldConfig]],
]
)
);

$this->configManager->expects($this->once())
->method('getProvider')
->with('extend')
->will($this->returnValue($extendConfigProvider));

$relationKey = 'test_relation_key';
$this->relationBuilder->expects($this->once())
->method('addManyToOneRelation')
->with(
$this->identicalTo($entityConfig),
'Oro\Bundle\AttachmentBundle\Entity\File',
$fieldName,
'id',
[
'extend' => [
'cascade' => ['persist', 'remove']
],
'importexport' => [
'process_as_scalar' => true
]
],
$fieldType
)
->will($this->returnValue($relationKey));

$this->extension->preUpdate();
}

public function preUpdateProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,25 @@ public function preUpdate()
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $fieldConfig->getId();
if (in_array($fieldConfigId->getFieldType(), ['file', 'image'])) {
// create a relation
$relationKey = $this->relationBuilder->addManyToOneRelation(
$cascade = $fieldConfig->get('cascade', false, []);
if (!in_array('persist', $cascade, true)) {
$cascade[] = 'persist';
}
$this->relationBuilder->addManyToOneRelation(
$entityConfig,
'Oro\Bundle\AttachmentBundle\Entity\File',
$fieldConfigId->getFieldName(),
'id',
[
'extend' => [
'cascade' => $cascade
],
'importexport' => [
'process_as_scalar' => true
]
],
$fieldConfigId->getFieldType()
);

// set cascade persist
$relations = $entityConfig->get('relation');
$cascade = isset($relations[$relationKey]['cascade'])
? $relations[$relationKey]['cascade']
: [];
$cascade[] = 'persist';
$relations[$relationKey]['cascade'] = $cascade;
$entityConfig->set('relation', $relations);
$extendConfigProvider->persist($entityConfig);
}
}
}
Expand Down
Loading

0 comments on commit 52a87e5

Please sign in to comment.