Passed
Push — master ( 4c4023...2b0e92 )
by Julito
07:08
created

Version20170625144000::up()   F

Complexity

Conditions 36
Paths 0

Size

Total Lines 217
Code Lines 114

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 36
eloc 114
nc 0
nop 1
dl 0
loc 217
rs 3.3333
c 1
b 1
f 1

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
/**
13
 * c_student_publication.
14
 */
15
class Version20170625144000 extends AbstractMigrationChamilo
16
{
17
    public function up(Schema $schema): void
18
    {
19
        $table = $schema->getTable('c_student_publication');
20
21
        $this->addSql('UPDATE c_student_publication SET user_id = NULL WHERE user_id = 0');
22
        $this->addSql('ALTER TABLE c_student_publication CHANGE user_id user_id INT DEFAULT NULL');
23
24
        if (false === $table->hasForeignKey('FK_5246F746A76ED395')) {
25
            $this->addSql(
26
                'ALTER TABLE c_student_publication ADD CONSTRAINT FK_5246F746A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);'
27
            );
28
        }
29
30
        if ($table->hasIndex('idx_csp_u')) {
31
            $this->addSql('DROP INDEX idx_csp_u ON c_student_publication');
32
        }
33
34
        if (false === $table->hasIndex('IDX_5246F746A76ED395')) {
35
            $this->addSql('CREATE INDEX IDX_5246F746A76ED395 ON c_student_publication (user_id);');
36
        }
37
38
        $this->addSql('UPDATE c_student_publication SET parent_id = NULL WHERE parent_id = 0');
39
        $this->addSql('ALTER TABLE c_student_publication CHANGE parent_id parent_id INT DEFAULT NULL');
40
41
        if (false === $table->hasForeignKey('FK_5246F746727ACA70')) {
42
            $this->addSql(
43
                'ALTER TABLE c_student_publication ADD CONSTRAINT FK_5246F746727ACA70 FOREIGN KEY (parent_id) REFERENCES c_student_publication (iid);'
44
            );
45
        }
46
47
        if (false === $table->hasIndex('IDX_5246F746727ACA70')) {
48
            $this->addSql('CREATE INDEX IDX_5246F746727ACA70 ON c_student_publication (parent_id)');
49
        }
50
51
        if (false === $table->hasColumn('filesize')) {
52
            $this->addSql('ALTER TABLE c_student_publication ADD filesize INT DEFAULT NULL');
53
        }
54
55
        if ($table->hasForeignKey('FK_5246F746613FECDF')) {
56
            $this->addSql('ALTER TABLE c_student_publication DROP FOREIGN KEY FK_5246F746613FECDF;');
57
        }
58
59
        if ($table->hasIndex('course')) {
60
            $this->addSql('DROP INDEX course ON c_student_publication;');
61
        }
62
63
        $this->addSql('ALTER TABLE c_student_publication CHANGE url url VARCHAR(500) DEFAULT NULL');
64
        $this->addSql(
65
            'ALTER TABLE c_student_publication CHANGE url_correction url_correction VARCHAR(500) DEFAULT NULL'
66
        );
67
        $this->addSql('ALTER TABLE c_student_publication CHANGE active active INT DEFAULT NULL');
68
69
        if (false === $table->hasColumn('resource_node_id')) {
70
            $this->addSql('ALTER TABLE c_student_publication ADD resource_node_id INT DEFAULT NULL');
71
            $this->addSql(
72
                'ALTER TABLE c_student_publication ADD CONSTRAINT FK_5246F7461BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
73
            );
74
            $this->addSql('CREATE UNIQUE INDEX UNIQ_5246F7461BAD783F ON c_student_publication (resource_node_id)');
75
        }
76
77
        $table = $schema->getTable('c_student_publication_assignment');
78
79
        if ($table->hasIndex('course')) {
80
            $this->addSql('DROP INDEX course ON c_student_publication_assignment;');
81
        }
82
83
        /*
84
        if (false === $table->hasColumn('resource_node_id')) {
85
            $this->addSql('ALTER TABLE c_student_publication_assignment ADD resource_node_id INT DEFAULT NULL');
86
            $this->addSql(
87
                'ALTER TABLE c_student_publication_assignment ADD CONSTRAINT FK_25687EB81BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
88
            );
89
            $this->addSql(
90
                'CREATE UNIQUE INDEX UNIQ_25687EB81BAD783F ON c_student_publication_assignment (resource_node_id)'
91
            );
92
        }
93
        */
94
95
        $this->addSql('UPDATE c_student_publication_assignment SET publication_id = NULL WHERE publication_id = 0');
96
        $this->addSql(
97
            'ALTER TABLE c_student_publication_assignment CHANGE publication_id publication_id INT DEFAULT NULL'
98
        );
99
100
        if (false === $table->hasForeignKey('FK_25687EB838B217A7')) {
101
            $this->addSql(
102
                'ALTER TABLE c_student_publication_assignment ADD CONSTRAINT FK_25687EB838B217A7 FOREIGN KEY (publication_id) REFERENCES c_student_publication (iid) ON DELETE CASCADE;'
103
            );
104
        }
105
106
        if (false === $table->hasIndex('UNIQ_25687EB838B217A7')) {
107
            $this->addSql(
108
                'ALTER TABLE c_student_publication_assignment ADD UNIQUE INDEX UNIQ_25687EB838B217A7 (publication_id)'
109
            );
110
        }
111
112
        if (false === $schema->hasTable('c_student_publication_correction')) {
113
            $this->addSql(
114
                'CREATE TABLE c_student_publication_correction (id INT AUTO_INCREMENT NOT NULL, resource_node_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_B7309BBA1BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC'
115
            );
116
            $this->addSql(
117
                'ALTER TABLE c_student_publication_correction ADD CONSTRAINT FK_B7309BBA1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
118
            );
119
        }
120
121
        $table = $schema->getTable('c_student_publication_comment');
122
        if (false === $table->hasColumn('resource_node_id')) {
123
            $this->addSql('ALTER TABLE c_student_publication_comment ADD resource_node_id INT DEFAULT NULL');
124
            $this->addSql(
125
                'ALTER TABLE c_student_publication_comment ADD CONSTRAINT FK_35C509F61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
126
            );
127
            $this->addSql(
128
                'CREATE UNIQUE INDEX UNIQ_35C509F61BAD783F ON c_student_publication_comment (resource_node_id)'
129
            );
130
        }
131
132
        if ($table->hasIndex('course')) {
133
            $this->addSql('DROP INDEX course ON c_student_publication_comment');
134
        }
135
136
        $this->addSql('UPDATE c_student_publication_comment SET work_id = NULL WHERE work_id = 0');
137
        $this->addSql('UPDATE c_student_publication_comment SET user_id = NULL WHERE user_id = 0');
138
139
        $this->addSql('ALTER TABLE c_student_publication_comment CHANGE work_id work_id INT DEFAULT NULL');
140
        $this->addSql('ALTER TABLE c_student_publication_comment CHANGE user_id user_id INT DEFAULT NULL;');
141
142
        if (!$table->hasForeignKey('FK_35C509F6BB3453DB')) {
143
            $this->addSql(
144
                'ALTER TABLE c_student_publication_comment ADD CONSTRAINT FK_35C509F6BB3453DB FOREIGN KEY (work_id) REFERENCES c_student_publication (iid) ON DELETE CASCADE;'
145
            );
146
        }
147
148
        if (!$table->hasForeignKey('FK_35C509F6A76ED395')) {
149
            $this->addSql(
150
                'ALTER TABLE c_student_publication_comment ADD CONSTRAINT FK_35C509F6A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;'
151
            );
152
        }
153
154
        if ($table->hasIndex('work')) {
155
            $this->addSql('DROP INDEX work ON c_student_publication_comment;');
156
        }
157
158
        if ($table->hasIndex('user')) {
159
            $this->addSql('DROP INDEX user ON c_student_publication_comment;');
160
        }
161
162
        if (!$table->hasIndex('IDX_35C509F6BB3453DB')) {
163
            $this->addSql('CREATE INDEX IDX_35C509F6BB3453DB ON c_student_publication_comment (work_id);');
164
        }
165
166
        if (!$table->hasIndex('IDX_35C509F6A76ED395')) {
167
            $this->addSql('CREATE INDEX IDX_35C509F6A76ED395 ON c_student_publication_comment (user_id);');
168
        }
169
170
        $table = $schema->getTable('c_student_publication_rel_document');
171
172
        if ($table->hasIndex('course')) {
173
            $this->addSql('DROP INDEX course ON c_student_publication_rel_document;');
174
        }
175
        if ($table->hasIndex('work')) {
176
            $this->addSql('DROP INDEX work ON c_student_publication_rel_document;');
177
        }
178
        if ($table->hasIndex('document')) {
179
            $this->addSql('DROP INDEX document ON c_student_publication_rel_document;');
180
        }
181
182
        $this->addSql('ALTER TABLE c_student_publication_rel_document CHANGE work_id work_id INT DEFAULT NULL');
183
        $this->addSql('ALTER TABLE c_student_publication_rel_document CHANGE document_id document_id INT DEFAULT NULL');
184
185
        if (!$table->hasForeignKey('FK_BD6672A5BB3453DB')) {
186
            $this->addSql(
187
                'ALTER TABLE c_student_publication_rel_document ADD CONSTRAINT FK_BD6672A5BB3453DB FOREIGN KEY (work_id) REFERENCES c_student_publication (iid) ON DELETE CASCADE'
188
            );
189
        }
190
191
        if (!$table->hasForeignKey('FK_BD6672A5C33F7837')) {
192
            $this->addSql(
193
                'ALTER TABLE c_student_publication_rel_document ADD CONSTRAINT FK_BD6672A5C33F7837 FOREIGN KEY (document_id) REFERENCES c_document (iid) ON DELETE CASCADE'
194
            );
195
        }
196
197
        if (!$table->hasIndex('IDX_BD6672A5BB3453DB')) {
198
            $this->addSql('CREATE INDEX IDX_BD6672A5BB3453DB ON c_student_publication_rel_document (work_id);');
199
        }
200
201
        if (!$table->hasIndex('IDX_BD6672A5C33F7837')) {
202
            $this->addSql('CREATE INDEX IDX_BD6672A5C33F7837 ON c_student_publication_rel_document (document_id);');
203
        }
204
205
        $table = $schema->getTable('c_student_publication_rel_user');
206
        if ($table->hasIndex('course')) {
207
            $this->addSql('DROP INDEX course ON c_student_publication_rel_user');
208
        }
209
        if ($table->hasIndex('work')) {
210
            $this->addSql('DROP INDEX work ON c_student_publication_rel_user');
211
        }
212
        if ($table->hasIndex('user')) {
213
            $this->addSql('DROP INDEX user ON c_student_publication_rel_user');
214
        }
215
216
        $this->addSql('ALTER TABLE c_student_publication_rel_user CHANGE work_id work_id INT DEFAULT NULL');
217
        $this->addSql('ALTER TABLE c_student_publication_rel_user CHANGE user_id user_id INT DEFAULT NULL');
218
219
        if (!$table->hasForeignKey('FK_2B007FA9BB3453DB')) {
220
            $this->addSql(
221
                'ALTER TABLE c_student_publication_rel_user ADD CONSTRAINT FK_2B007FA9BB3453DB FOREIGN KEY (work_id) REFERENCES c_student_publication (iid) ON DELETE CASCADE;'
222
            );
223
        }
224
        if (!$table->hasForeignKey('FK_2B007FA9A76ED395')) {
225
            $this->addSql(
226
                'ALTER TABLE c_student_publication_rel_user ADD CONSTRAINT FK_2B007FA9A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;'
227
            );
228
        }
229
        if (!$table->hasIndex('IDX_2B007FA9BB3453DB')) {
230
            $this->addSql('CREATE INDEX IDX_2B007FA9BB3453DB ON c_student_publication_rel_user (work_id)');
231
        }
232
        if (!$table->hasIndex('IDX_2B007FA9A76ED395')) {
233
            $this->addSql('CREATE INDEX IDX_2B007FA9A76ED395 ON c_student_publication_rel_user (user_id)');
234
        }
235
    }
236
237
    public function down(Schema $schema): void
238
    {
239
    }
240
}
241