Passed
Push — master ( fc13ff...4dcdf9 )
by Julito
12:40
created

Version20170625143000::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 0
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
/**
11
 * c_thematic.
12
 */
13
class Version20170625143000 extends AbstractMigrationChamilo
14
{
15
    public function up(Schema $schema): void
16
    {
17
        $table = $schema->getTable('c_thematic');
18
        if (false === $table->hasColumn('resource_node_id')) {
19
            $this->addSql('ALTER TABLE c_thematic ADD resource_node_id INT DEFAULT NULL');
20
            $this->addSql(
21
                'ALTER TABLE c_thematic ADD CONSTRAINT FK_6D8F59B91BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
22
            );
23
            $this->addSql('CREATE UNIQUE INDEX UNIQ_6D8F59B91BAD783F ON c_thematic (resource_node_id)');
24
        }
25
26
        if ($table->hasIndex('course')) {
27
            $this->addSql('DROP INDEX course ON c_thematic');
28
        }
29
        if ($table->hasIndex('active')) {
30
            $this->addSql('DROP INDEX active ON c_thematic');
31
        }
32
33
        if ($table->hasColumn('c_id')) {
34
            //$this->addSql('ALTER TABLE c_thematic DROP c_id');
35
        }
36
37
        if ($table->hasColumn('session_id')) {
38
            //$this->addSql('ALTER TABLE c_thematic DROP session_id');
39
        }
40
41
        if ($table->hasIndex('active')) {
42
            $this->addSql('CREATE INDEX active ON c_thematic (active);');
43
        }
44
45
        $table = $schema->getTable('c_thematic_advance');
46
        if ($table->hasIndex('course')) {
47
            $this->addSql('DROP INDEX course ON c_thematic_advance');
48
        }
49
50
        if ($table->hasColumn('c_id')) {
51
            //$this->addSql('ALTER TABLE c_thematic_advance DROP c_id;');
52
        }
53
54
        if ($table->hasIndex('thematic_id')) {
55
            $this->addSql('DROP INDEX thematic_id ON c_thematic_advance');
56
        }
57
58
        if (false === $table->hasIndex('IDX_62798E972395FCED')) {
59
            $this->addSql('CREATE INDEX IDX_62798E972395FCED ON c_thematic_advance (thematic_id)');
60
        }
61
62
        $this->addSql(
63
            'ALTER TABLE c_thematic_advance CHANGE thematic_id thematic_id INT DEFAULT NULL, CHANGE attendance_id attendance_id INT DEFAULT NULL'
64
        );
65
66
        if (false === $table->hasForeignKey('FK_62798E972395FCED')) {
67
            $this->addSql(
68
                'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E972395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
69
            );
70
        }
71
        if (false === $table->hasForeignKey('FK_62798E97163DDA15')) {
72
            $this->addSql(
73
                'ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid)'
74
            );
75
        }
76
        if (false === $table->hasIndex('IDX_62798E97163DDA15')) {
77
            $this->addSql('CREATE INDEX IDX_62798E97163DDA15 ON c_thematic_advance (attendance_id);');
78
        }
79
80
        /*
81
        if (false === $table->hasColumn('resource_node_id')) {
82
            $this->addSql('ALTER TABLE c_thematic_advance ADD resource_node_id INT DEFAULT NULL');
83
84
            //$this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E971BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
85
            $this->addSql('CREATE UNIQUE INDEX UNIQ_62798E971BAD783F ON c_thematic_advance (resource_node_id)');
86
        }*/
87
88
        $table = $schema->getTable('c_thematic_plan');
89
        $this->addSql('ALTER TABLE c_thematic_plan CHANGE thematic_id thematic_id INT DEFAULT NULL');
90
91
        if ($table->hasIndex('course')) {
92
            $this->addSql('DROP INDEX course ON c_thematic_plan');
93
        }
94
95
        if ($table->hasColumn('c_id')) {
96
            //$this->addSql('ALTER TABLE c_thematic_plan DROP c_id;');
97
        }
98
        if (false === $table->hasForeignKey('FK_1197487C2395FCED')) {
99
            $this->addSql(
100
                'ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
101
            );
102
        }
103
104
        if (false === $table->hasIndex('IDX_1197487C2395FCED')) {
105
            $this->addSql('CREATE INDEX IDX_1197487C2395FCED ON c_thematic_plan (thematic_id)');
106
        }
107
108
        /*
109
        if (false === $table->hasColumn('resource_node_id')) {
110
            $this->addSql('ALTER TABLE c_thematic_plan ADD resource_node_id INT DEFAULT NULL');
111
112
            $this->addSql('ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
113
            $this->addSql('CREATE UNIQUE INDEX UNIQ_1197487C1BAD783F ON c_thematic_plan (resource_node_id)');
114
        }*/
115
116
        // CLink
117
        $table = $schema->getTable('c_link');
118
        if (false === $table->hasColumn('resource_node_id')) {
119
            $this->addSql('ALTER TABLE c_link ADD resource_node_id INT DEFAULT NULL;');
120
            $this->addSql(
121
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A01BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
122
            );
123
            $this->addSql('CREATE UNIQUE INDEX UNIQ_9209C2A01BAD783F ON c_link (resource_node_id);');
124
        }
125
126
        if ($table->hasIndex('session_id')) {
127
            $this->addSql('DROP INDEX session_id ON c_link');
128
        }
129
        if ($table->hasIndex('course')) {
130
            $this->addSql('DROP INDEX course ON c_link');
131
        }
132
133
        $this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id = 0');
134
        if (false === $table->hasForeignKey('FK_9209C2A012469DE2')) {
135
            $this->addSql(
136
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A012469DE2 FOREIGN KEY (category_id) REFERENCES c_link_category (iid)'
137
            );
138
            $this->addSql('CREATE INDEX IDX_9209C2A012469DE2 ON c_link (category_id)');
139
        }
140
141
        $table = $schema->getTable('c_link_category');
142
        if (false === $table->hasColumn('resource_node_id')) {
143
            $this->addSql('ALTER TABLE c_link_category ADD resource_node_id INT DEFAULT NULL');
144
            $this->addSql(
145
                'ALTER TABLE c_link_category ADD CONSTRAINT FK_319D6C9C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
146
            );
147
            $this->addSql('CREATE UNIQUE INDEX UNIQ_319D6C9C1BAD783F ON c_link_category (resource_node_id)');
148
        }
149
        if ($table->hasIndex('session_id')) {
150
            $this->addSql('DROP INDEX session_id ON c_link_category');
151
        }
152
        if ($table->hasIndex('course')) {
153
            $this->addSql('DROP INDEX course ON c_link_category');
154
        }
155
156
        $table = $schema->getTable('c_glossary');
157
158
        if ($table->hasIndex('course')) {
159
            $this->addSql('DROP INDEX course ON c_glossary');
160
        }
161
162
        if ($table->hasIndex('session_id')) {
163
            $this->addSql('DROP INDEX session_id ON c_glossary');
164
        }
165
166
        if (false === $table->hasColumn('resource_node_id')) {
167
            $this->addSql('ALTER TABLE c_glossary ADD resource_node_id INT DEFAULT NULL');
168
            $this->addSql(
169
                'ALTER TABLE c_glossary ADD CONSTRAINT FK_A1168D881BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
170
            );
171
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A1168D881BAD783F ON c_glossary (resource_node_id)');
172
        }
173
174
        $table = $schema->getTable('c_student_publication');
175
        if (false === $table->hasColumn('filesize')) {
176
            $this->addSql('ALTER TABLE c_student_publication ADD filesize INT DEFAULT NULL');
177
        }
178
        $this->addSql('ALTER TABLE c_student_publication CHANGE url url VARCHAR(500) DEFAULT NULL');
179
        $this->addSql(
180
            'ALTER TABLE c_student_publication CHANGE url_correction url_correction VARCHAR(500) DEFAULT NULL'
181
        );
182
        $this->addSql('ALTER TABLE c_student_publication CHANGE active active INT DEFAULT NULL');
183
184
        if (false === $table->hasColumn('resource_node_id')) {
185
            $this->addSql('ALTER TABLE c_student_publication ADD resource_node_id INT DEFAULT NULL');
186
            $this->addSql(
187
                'ALTER TABLE c_student_publication ADD CONSTRAINT FK_5246F7461BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
188
            );
189
            $this->addSql('CREATE UNIQUE INDEX UNIQ_5246F7461BAD783F ON c_student_publication (resource_node_id)');
190
        }
191
192
        /*$table = $schema->getTable('c_student_publication_assignment');
193
        if (false === $table->hasColumn('resource_node_id')) {
194
            $this->addSql('ALTER TABLE c_student_publication_assignment ADD resource_node_id INT DEFAULT NULL');
195
            $this->addSql(
196
                'ALTER TABLE c_student_publication_assignment ADD CONSTRAINT FK_25687EB81BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
197
            );
198
            $this->addSql(
199
                'CREATE UNIQUE INDEX UNIQ_25687EB81BAD783F ON c_student_publication_assignment (resource_node_id)'
200
            );
201
        }
202
        */
203
204
        if (false === $schema->hasTable('c_student_publication_correction')) {
205
            $this->addSql(
206
                'CREATE TABLE c_student_publication_correction (id INT AUTO_INCREMENT NOT NULL, resource_node_id INT DEFAULT NULL, title VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_B7309BBA1BAD783F (resource_node_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC'
207
            );
208
            $this->addSql(
209
                'ALTER TABLE c_student_publication_correction ADD CONSTRAINT FK_B7309BBA1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
210
            );
211
        }
212
213
        $table = $schema->getTable('c_student_publication_comment');
214
        if (false === $table->hasColumn('resource_node_id')) {
215
            $this->addSql('ALTER TABLE c_student_publication_comment ADD resource_node_id INT DEFAULT NULL');
216
            $this->addSql(
217
                'ALTER TABLE c_student_publication_comment ADD CONSTRAINT FK_35C509F61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
218
            );
219
            $this->addSql(
220
                'CREATE UNIQUE INDEX UNIQ_35C509F61BAD783F ON c_student_publication_comment (resource_node_id)'
221
            );
222
        }
223
224
        $table = $schema->getTable('c_calendar_event');
225
        if (false === $table->hasColumn('resource_node_id')) {
226
            $this->addSql('ALTER TABLE c_calendar_event ADD resource_node_id INT DEFAULT NULL');
227
            $this->addSql(
228
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A0622581EE3A445A FOREIGN KEY (parent_event_id) REFERENCES c_calendar_event (iid)'
229
            );
230
            $this->addSql(
231
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A06225811BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
232
            );
233
            $this->addSql('CREATE INDEX IDX_A0622581EE3A445A ON c_calendar_event (parent_event_id)');
234
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A06225811BAD783F ON c_calendar_event (resource_node_id)');
235
        }
236
237
        if ($table->hasIndex('course')) {
238
            $this->addSql('DROP INDEX course ON c_calendar_event');
239
        }
240
241
        if ($table->hasIndex('session_id')) {
242
            $this->addSql('DROP INDEX session_id ON c_calendar_event');
243
        }
244
245
246
        $table = $schema->getTable('c_calendar_event_attachment');
247
248
        if ($table->hasIndex('course')) {
249
            $this->addSql('DROP INDEX course ON c_calendar_event_attachment');
250
        }
251
252
        if (false === $table->hasColumn('resource_node_id')) {
253
            $this->addSql('ALTER TABLE c_calendar_event_attachment ADD resource_node_id INT DEFAULT NULL');
254
            $this->addSql(
255
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A6EA67784A FOREIGN KEY (agenda_id) REFERENCES c_calendar_event (iid) ON DELETE CASCADE'
256
            );
257
            $this->addSql(
258
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
259
            );
260
            $this->addSql('CREATE INDEX IDX_DDD745A6EA67784A ON c_calendar_event_attachment (agenda_id)');
261
            $this->addSql(
262
                'CREATE UNIQUE INDEX UNIQ_DDD745A61BAD783F ON c_calendar_event_attachment (resource_node_id)'
263
            );
264
        }
265
266
        $table = $schema->getTable('c_calendar_event_repeat');
267
        $this->addSql('ALTER TABLE c_calendar_event_repeat CHANGE cal_id cal_id INT DEFAULT NULL');
268
        if (false === $table->hasForeignKey('FK_86FD1CA87300D633')) {
269
            $this->addSql(
270
                'ALTER TABLE c_calendar_event_repeat ADD CONSTRAINT FK_86FD1CA87300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
271
            );
272
        }
273
        if (false === $table->hasIndex('IDX_86FD1CA87300D633')) {
274
            $this->addSql('CREATE INDEX IDX_86FD1CA87300D633 ON c_calendar_event_repeat (cal_id)');
275
        }
276
277
        $table = $schema->getTable('c_calendar_event_repeat_not');
278
279
        if ($table->hasIndex('course')) {
280
            $this->addSql('DROP INDEX course ON c_calendar_event_repeat_not;');
281
        }
282
283
        if (false === $table->hasForeignKey('FK_7D4436947300D633')) {
284
            $this->addSql(
285
                'ALTER TABLE c_calendar_event_repeat_not ADD CONSTRAINT FK_7D4436947300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
286
            );
287
        }
288
289
        $this->addSql('ALTER TABLE c_calendar_event_repeat_not CHANGE cal_id cal_id INT DEFAULT NULL');
290
291
        if (false === $table->hasIndex('IDX_7D4436947300D633')) {
292
            $this->addSql('CREATE INDEX IDX_7D4436947300D633 ON c_calendar_event_repeat_not (cal_id)');
293
        }
294
    }
295
296
    public function down(Schema $schema): void
297
    {
298
    }
299
}
300