Skip to content

Commit

Permalink
Merge branch '1.0' of https://github.com/laboro/commerce into 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anyt committed Jan 17, 2017
2 parents 357ca21 + 2d43c06 commit 20e1a5a
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,69 @@ private function renameCustomer(Schema $schema, QueryBag $queries)
$query->setFieldName($relation);
$queries->addPostQuery($query);
}

$this->migrateConfig(
$configManager,
'Oro\Bundle\NoteBundle\Entity\Note',
'Oro\Bundle\CustomerBundle\Entity\Customer',
$relation,
'customer_71cbb705',
RelationType::MANY_TO_MANY
);
}

$possibleTableNames = [
'oro_rel_c3990ba6b28b6f382b5af2',
'oro_rel_c3990ba6b28b6f383f1392',
];
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
$table = $schema->getTable($tableName);
$table->removeForeignKey($this->getConstraintName($table, "account_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['account_id']) {
$table->dropIndex($index->getName());
if ($schema->hasTable('oro_rel_c3990ba6784fec5f6e321b')) {
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
$schema->dropTable($tableName);
}
}
$table = $schema->getTable('oro_rel_c3990ba6784fec5f6e321b');
$table->removeForeignKey($this->getConstraintName($table, "account_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['account_id']) {
$table->dropIndex($index->getName());
}
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'account_id',
'customer_id'
);
} else {
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
if (!$schema->hasTable('oro_rel_c3990ba6784fec5f6e321b')) {
$schema->dropTable($tableName);
} else {
$table = $schema->getTable($tableName);
$table->removeForeignKey($this->getConstraintName($table, "account_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['account_id']) {
$table->dropIndex($index->getName());
}
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'account_id',
'customer_id'
);
$this->renameExtension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba6784fec5f6e321b'
);
}
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'account_id',
'customer_id'
);
$this->renameExtension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba6784fec5f6e321b'
);
}
}
if ($schema->hasTable('oro_rel_6f8f552ab28b6f38cd148c')) {
Expand Down Expand Up @@ -281,6 +316,8 @@ private function renameCustomer(Schema $schema, QueryBag $queries)
/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @param Schema $schema
* @param QueryBag $queries
*/
Expand Down Expand Up @@ -323,30 +360,67 @@ private function renameCustomerUserRole(Schema $schema, QueryBag $queries)
'oro_rel_c3990ba69df6f4d8894a76',
'oro_rel_c3990ba69df6f4d84415b1',
];
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
$table = $schema->getTable($tableName);
$table->removeForeignKey($this->getConstraintName($table, "accountuserrole_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['accountuserrole_id']) {
$table->dropIndex($index->getName());
if ($schema->hasTable('oro_rel_c3990ba6d7fa01cd30d950')) {
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
$schema->dropTable($tableName);
}
}
$table = $schema->getTable('oro_rel_c3990ba6d7fa01cd30d950');
$table->removeForeignKey($this->getConstraintName($table, "accountuserrole_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['accountuserrole_id']) {
$table->dropIndex($index->getName());
}
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'accountuserrole_id',
'customeruserrole_id'
);
} else {
$renamed = false;
foreach ($possibleTableNames as $tableName) {
if ($schema->hasTable($tableName)) {
if ($renamed) {
$schema->dropTable($tableName);
continue;
}
$table = $schema->getTable($tableName);
$table->removeForeignKey($this->getConstraintName($table, "accountuserrole_id"));
foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['accountuserrole_id']) {
$table->dropIndex($index->getName());
}
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'accountuserrole_id',
'customeruserrole_id'
);
$this->renameExtension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba6d7fa01cd30d950'
);
$renamed = true;
}
$this->renameExtension->renameColumn(
$schema,
$queries,
$table,
'accountuserrole_id',
'customeruserrole_id'
);
$this->renameExtension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba6d7fa01cd30d950'
);
}
}
if ($schema->hasTable('oro_rel_6f8f552a9df6f4d81e2432') && $schema->getTable('oro_rel_6f8f552a9df6f4d81e2432')
->hasColumn('accountuserrole_id')
) {
$table = $schema->getTable('oro_rel_6f8f552a9df6f4d81e2432');
$fk = $this->getConstraintName($table, 'accountuserrole_id');
$table->removeForeignKey($fk);
$this->renameExtension
->renameColumn($schema, $queries, $table, 'accountuserrole_id', 'customeruserrole_id');
}

$possibleActivityRelations = [
'account_user_role_a5e27440',
Expand Down Expand Up @@ -537,6 +611,9 @@ private function renameAccountAddressTable(Schema $schema, QueryBag $queries)
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @param Schema $schema
* @param QueryBag $queries
*/
Expand Down Expand Up @@ -575,6 +652,14 @@ public function renameCustomerGroup(Schema $schema, QueryBag $queries)
$query->setTargetClass('CustomerGroup');
$queries->addPostQuery($query);
}
$this->migrateConfig(
$configManager,
'Oro\Bundle\NoteBundle\Entity\Note',
'Oro\Bundle\CustomerBundle\Entity\CustomerGroup',
$relation,
'customer_group_4f9aa384',
RelationType::MANY_TO_MANY
);
$this->migrateConfig(
$configManager,
'Oro\Bundle\ActivityListBundle\Entity\ActivityList',
Expand All @@ -589,20 +674,39 @@ public function renameCustomerGroup(Schema $schema, QueryBag $queries)
'oro_rel_c3990ba665864788b74044',
'oro_rel_c3990ba6658647885abb70',
];
foreach ($tables as $tableName) {
if ($schema->hasTable($tableName)) {
$table = $schema->getTable($tableName);
$fk = $this->getConstraintName($table, 'accountgroup_id');
$table->removeForeignKey($fk);
$extension->renameColumn($schema, $queries, $table, 'accountgroup_id', 'customergroup_id');
$extension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba616cbf45899499b'
);
if ($schema->hasTable('oro_rel_c3990ba616cbf45899499b')) {
foreach ($tables as $tableName) {
if ($schema->hasTable($tableName)) {
$schema->dropTable($tableName);
}
}
$table = $schema->getTable('oro_rel_c3990ba616cbf45899499b');
$fk = $this->getConstraintName($table, 'accountgroup_id');
$table->removeForeignKey($fk);
$extension->renameColumn($schema, $queries, $table, 'accountgroup_id', 'customergroup_id');
} else {
$renamed = false;
foreach ($tables as $tableName) {
if ($schema->hasTable($tableName)) {
if ($renamed) {
$schema->dropTable($tableName);
} else {
$table = $schema->getTable($tableName);
$fk = $this->getConstraintName($table, 'accountgroup_id');
$table->removeForeignKey($fk);
$extension->renameColumn($schema, $queries, $table, 'accountgroup_id', 'customergroup_id');
$extension->renameTable(
$schema,
$queries,
$tableName,
'oro_rel_c3990ba616cbf45899499b'
);
$renamed = true;
}
}
}
}

if ($schema->hasTable('oro_rel_6f8f552a65864788eebf8a')) {
$table = $schema->getTable('oro_rel_6f8f552a65864788eebf8a');
$fk = $this->getConstraintName($table, 'accountgroup_id');
Expand Down Expand Up @@ -806,6 +910,23 @@ private function renameCustomerUser(Schema $schema, QueryBag $queries)
);
}

if ($schema->hasTable('oro_rel_46a29d19a6adb604aeb863') && $schema->getTable('oro_rel_46a29d19a6adb604aeb863')
->hasColumn('accountuser_id')
) {
$table = $schema->getTable('oro_rel_46a29d19a6adb604aeb863');
$fk = $this->getConstraintName($table, 'accountuser_id');
$table->removeForeignKey($fk);
$extension->renameColumn($schema, $queries, $table, 'accountuser_id', 'customeruser_id');
}
if ($schema->hasTable('oro_rel_c3990ba6a6adb604193652') && $schema->getTable('oro_rel_c3990ba6a6adb604193652')
->hasColumn('accountuser_id')
) {
$table = $schema->getTable('oro_rel_c3990ba6a6adb604193652');
$fk = $this->getConstraintName($table, 'accountuser_id');
$table->removeForeignKey($fk);
$extension->renameColumn($schema, $queries, $table, 'accountuser_id', 'customeruser_id');
}

$this->renameRelationTable(
$schema,
$queries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Oro\Bundle\CustomerBundle\Migrations\Schema\v1_10;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtension;
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtensionAwareInterface;
use Oro\Bundle\MigrationBundle\Migration\Extension\RenameExtension;
Expand Down Expand Up @@ -61,7 +62,7 @@ public function up(Schema $schema, QueryBag $queries)
'oro_note',
'oro_customer'
);
$this->alterScopes($schema, $queries);
$this->alterScopes($schema);
}

/**
Expand Down Expand Up @@ -96,6 +97,18 @@ private function renameAccountUserRole(Schema $schema)
['onDelete' => 'CASCADE', 'onUpdate' => null]
);

if ($schema->hasTable("oro_rel_6f8f552a9df6f4d81e2432") &&
!$this->fkExists($schema->getTable("oro_rel_6f8f552a9df6f4d81e2432"), 'customeruserrole_id')
) {
$table = $schema->getTable("oro_rel_6f8f552a9df6f4d81e2432");
$table->addForeignKeyConstraint(
$schema->getTable('oro_customer_user_role'),
['customeruserrole_id'],
['id'],
['onDelete' => 'CASCADE', 'onUpdate' => null]
);
}

$table = $schema->getTable("oro_rel_c3990ba6d7fa01cd30d950");
$table->addForeignKeyConstraint(
$schema->getTable('oro_customer_user_role'),
Expand Down Expand Up @@ -285,6 +298,10 @@ public function renameCustomer(Schema $schema)
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @param Schema $schema
*/
public function renameCustomerUser(Schema $schema)
Expand Down Expand Up @@ -373,13 +390,36 @@ public function renameCustomerUser(Schema $schema)
['id'],
['onDelete' => 'SET NULL', 'onUpdate' => null]
);

if ($schema->hasTable('oro_rel_46a29d19a6adb604aeb863') &&
!$this->fkExists($schema->getTable("oro_rel_46a29d19a6adb604aeb863"), 'customeruser_id')
) {
$schema->getTable('oro_rel_46a29d19a6adb604aeb863')
->addForeignKeyConstraint(
$schema->getTable('oro_customer_user'),
['customeruser_id'],
['id'],
['onDelete' => 'CASCADE', 'onUpdate' => null]
);
}

if ($schema->hasTable('oro_rel_c3990ba6a6adb604193652') &&
!$this->fkExists($schema->getTable("oro_rel_c3990ba6a6adb604193652"), 'customeruser_id')
) {
$schema->getTable('oro_rel_c3990ba6a6adb604193652')
->addForeignKeyConstraint(
$schema->getTable('oro_customer_user'),
['customeruser_id'],
['id'],
['onDelete' => 'CASCADE', 'onUpdate' => null]
);
}
}

/**
* @param Schema $schema
* @param QueryBag $queries
*/
private function alterScopes(Schema $schema, QueryBag $queries)
private function alterScopes(Schema $schema)
{
$table = $schema->getTable('oro_scope');
$table->addForeignKeyConstraint(
Expand Down Expand Up @@ -425,4 +465,22 @@ public function getOrder()
{
return 2;
}

/**
* @param Table $table
* @param $columnName
*
* @return bool
*/
protected function fkExists(Table $table, $columnName)
{
$foreignKeys = $table->getForeignKeys();
foreach ($foreignKeys as $key) {
if ($key->getLocalColumns() == [$columnName]) {
return true;
}
}

return false;
}
}

0 comments on commit 20e1a5a

Please sign in to comment.