Completed
Push — master ( 535b09...0667cb )
by
unknown
56:23
created

RemoveLeadStatus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 38
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrder() 0 4 1
B up() 0 24 6
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_24;
4
5
use Doctrine\DBAL\Schema\Schema;
6
7
use Oro\Bundle\MigrationBundle\Migration\OrderedMigrationInterface;
8
9
use Oro\Bundle\MigrationBundle\Migration\Migration;
10
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
11
12
class RemoveLeadStatus implements Migration, OrderedMigrationInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getOrder()
18
    {
19
        return 3;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function up(Schema $schema, QueryBag $queries)
26
    {
27
        $table = $schema->getTable('orocrm_sales_lead');
28
        $statusColumnName = 'status_name';
29
30
        $leadForeignKeyList = $table->getForeignKeys();
31
        foreach ($leadForeignKeyList as $foreignKey) {
32
            $foreingKeyColumns = $foreignKey->getUnquotedLocalColumns();
33
            if (in_array($statusColumnName, $foreingKeyColumns, true)) {
34
                $table->removeForeignKey($foreignKey->getName());
35
            }
36
        }
37
38
        $leadIndexList = $table->getIndexes();
39
        foreach ($leadIndexList as $index) {
40
            if ($index->hasColumnAtPosition($statusColumnName, 0)) {
41
                $table->dropIndex($index->getName());
42
            }
43
        }
44
45
        if ($table->hasColumn($statusColumnName)) {
46
            $table->dropColumn($statusColumnName);
47
        }
48
    }
49
}
50