Version20170625143000::up()   F
last analyzed

Complexity

Conditions 27
Paths > 20000

Size

Total Lines 158
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 27
eloc 75
nc 67108864
nop 1
dl 0
loc 158
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20170625143000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'c_thematic changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $table = $schema->getTable('c_thematic');
22
        if (false === $table->hasColumn('resource_node_id')) {
23
            $this->addSql('ALTER TABLE c_thematic ADD resource_node_id INT DEFAULT NULL');
24
            $this->addSql(
25
                'ALTER TABLE c_thematic ADD CONSTRAINT FK_6D8F59B91BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
26
            );
27
            $this->addSql('CREATE UNIQUE INDEX UNIQ_6D8F59B91BAD783F ON c_thematic (resource_node_id)');
28
        }
29
30
        if ($table->hasIndex('course')) {
31
            $this->addSql('DROP INDEX course ON c_thematic');
32
        }
33
        if ($table->hasIndex('active')) {
34
            $this->addSql('DROP INDEX active ON c_thematic');
35
        }
36
37
        if ($table->hasColumn('c_id')) {
38
            // $this->addSql('ALTER TABLE c_thematic DROP c_id');
39
        }
40
41
        if ($table->hasColumn('session_id')) {
42
            // $this->addSql('ALTER TABLE c_thematic DROP session_id');
43
        }
44
45
        if ($table->hasIndex('active')) {
46
            $this->addSql('CREATE INDEX active ON c_thematic (active);');
47
        }
48
49
        $table = $schema->getTable('c_thematic_advance');
50
        if ($table->hasIndex('course')) {
51
            $this->addSql('DROP INDEX course ON c_thematic_advance');
52
        }
53
54
        if ($table->hasColumn('c_id')) {
55
            // $this->addSql('ALTER TABLE c_thematic_advance DROP c_id;');
56
        }
57
58
        if ($table->hasIndex('thematic_id')) {
59
            $this->addSql('DROP INDEX thematic_id ON c_thematic_advance');
60
        }
61
62
        if (false === $table->hasIndex('IDX_62798E972395FCED')) {
63
            $this->addSql('CREATE INDEX IDX_62798E972395FCED ON c_thematic_advance (thematic_id)');
64
        }
65
66
        $this->addSql(
67
            'ALTER TABLE c_thematic_advance CHANGE thematic_id thematic_id INT DEFAULT NULL, CHANGE attendance_id attendance_id INT DEFAULT NULL'
68
        );
69
70
        if (false === $table->hasForeignKey('FK_62798E972395FCED')) {
71
            $this->addSql(
72
                'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E972395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
73
            );
74
        }
75
        /*        if (false === $table->hasForeignKey('FK_62798E97163DDA15')) {
76
                    $this->addSql(
77
                        'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid) ON DELETE CASCADE'
78
                    );
79
                }*/
80
        if (false === $table->hasIndex('IDX_62798E97163DDA15')) {
81
            $this->addSql('CREATE INDEX IDX_62798E97163DDA15 ON c_thematic_advance (attendance_id);');
82
        }
83
84
        /*
85
         * if (false === $table->hasColumn('resource_node_id')) {
86
         * $this->addSql('ALTER TABLE c_thematic_advance ADD resource_node_id INT DEFAULT NULL');
87
         * //$this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E971BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
88
         * $this->addSql('CREATE UNIQUE INDEX UNIQ_62798E971BAD783F ON c_thematic_advance (resource_node_id)');
89
         * }*/
90
        $table = $schema->getTable('c_thematic_plan');
91
        $this->addSql('ALTER TABLE c_thematic_plan CHANGE thematic_id thematic_id INT DEFAULT NULL');
92
93
        if ($table->hasIndex('course')) {
94
            $this->addSql('DROP INDEX course ON c_thematic_plan');
95
        }
96
97
        if ($table->hasColumn('c_id')) {
98
            // $this->addSql('ALTER TABLE c_thematic_plan DROP c_id;');
99
        }
100
        if (false === $table->hasForeignKey('FK_1197487C2395FCED')) {
101
            $this->addSql(
102
                'ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid) ON DELETE CASCADE'
103
            );
104
        }
105
106
        if (false === $table->hasIndex('IDX_1197487C2395FCED')) {
107
            $this->addSql('CREATE INDEX IDX_1197487C2395FCED ON c_thematic_plan (thematic_id)');
108
        }
109
110
        /*
111
         * if (false === $table->hasColumn('resource_node_id')) {
112
         * $this->addSql('ALTER TABLE c_thematic_plan ADD resource_node_id INT DEFAULT NULL');
113
         * $this->addSql('ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
114
         * $this->addSql('CREATE UNIQUE INDEX UNIQ_1197487C1BAD783F ON c_thematic_plan (resource_node_id)');
115
         * }*/
116
117
        // CLink
118
        $table = $schema->getTable('c_link');
119
        if (false === $table->hasColumn('resource_node_id')) {
120
            $this->addSql('ALTER TABLE c_link ADD resource_node_id INT DEFAULT NULL;');
121
            $this->addSql(
122
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A01BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
123
            );
124
            $this->addSql('CREATE UNIQUE INDEX UNIQ_9209C2A01BAD783F ON c_link (resource_node_id);');
125
        }
126
127
        if ($table->hasIndex('session_id')) {
128
            $this->addSql('DROP INDEX session_id ON c_link');
129
        }
130
        if ($table->hasIndex('course')) {
131
            $this->addSql('DROP INDEX course ON c_link');
132
        }
133
134
        // $this->addSql('ALTER TABLE c_link CHANGE on_homepage on_homepage VARCHAR(10) DEFAULT NULL');
135
        $this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id = 0');
136
        $this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id NOT IN (SELECT iid FROM c_link_category)');
137
138
        if (false === $table->hasForeignKey('FK_9209C2A012469DE2')) {
139
            $this->addSql(
140
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A012469DE2 FOREIGN KEY (category_id) REFERENCES c_link_category (iid) ON DELETE SET NULL'
141
            );
142
            $this->addSql('CREATE INDEX IDX_9209C2A012469DE2 ON c_link (category_id)');
143
        }
144
145
        $table = $schema->getTable('c_link_category');
146
        if (false === $table->hasColumn('resource_node_id')) {
147
            $this->addSql('ALTER TABLE c_link_category ADD resource_node_id INT DEFAULT NULL');
148
            $this->addSql(
149
                'ALTER TABLE c_link_category ADD CONSTRAINT FK_319D6C9C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
150
            );
151
            $this->addSql('CREATE UNIQUE INDEX UNIQ_319D6C9C1BAD783F ON c_link_category (resource_node_id)');
152
        }
153
154
        if ($table->hasIndex('session_id')) {
155
            $this->addSql('DROP INDEX session_id ON c_link_category');
156
        }
157
        if ($table->hasIndex('course')) {
158
            $this->addSql('DROP INDEX course ON c_link_category');
159
        }
160
161
        $table = $schema->getTable('c_glossary');
162
163
        if ($table->hasIndex('course')) {
164
            $this->addSql('DROP INDEX course ON c_glossary');
165
        }
166
167
        if ($table->hasIndex('session_id')) {
168
            $this->addSql('DROP INDEX session_id ON c_glossary');
169
        }
170
171
        if (false === $table->hasColumn('resource_node_id')) {
172
            $this->addSql('ALTER TABLE c_glossary ADD resource_node_id INT DEFAULT NULL');
173
            $this->addSql(
174
                'ALTER TABLE c_glossary ADD CONSTRAINT FK_A1168D881BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
175
            );
176
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A1168D881BAD783F ON c_glossary (resource_node_id)');
177
        }
178
    }
179
180
    public function down(Schema $schema): void {}
181
}
182