Passed
Push — master ( 526730...ce0e49 )
by Julito
15:06 queued 06:42
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('ALTER TABLE c_thematic ADD CONSTRAINT FK_6D8F59B91BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
21
            $this->addSql('CREATE UNIQUE INDEX UNIQ_6D8F59B91BAD783F ON c_thematic (resource_node_id)');
22
        }
23
24
        $table = $schema->getTable('c_thematic_advance');
25
        $this->addSql('ALTER TABLE c_thematic_advance CHANGE thematic_id thematic_id INT DEFAULT NULL, CHANGE attendance_id attendance_id INT DEFAULT NULL');
26
        if (false === $table->hasColumn('resource_node_id')) {
27
            $this->addSql('ALTER TABLE c_thematic_advance ADD resource_node_id INT DEFAULT NULL');
28
            $this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E972395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)');
29
            $this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E97163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid)');
30
            $this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E971BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
31
            $this->addSql('CREATE UNIQUE INDEX UNIQ_62798E971BAD783F ON c_thematic_advance (resource_node_id)');
32
        }
33
34
        if ($table->hasIndex('IDX_62798E97163DDA15')) {
35
            $this->addSql('CREATE INDEX IDX_62798E97163DDA15 ON c_thematic_advance (attendance_id)');
36
        }
37
38
        $table = $schema->getTable('c_thematic_advance');
39
        $this->addSql('ALTER TABLE c_thematic_plan CHANGE thematic_id thematic_id INT DEFAULT NULL');
40
        if (false === $table->hasColumn('resource_node_id')) {
41
            $this->addSql('ALTER TABLE c_thematic_plan ADD resource_node_id INT DEFAULT NULL');
42
            $this->addSql('ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)');
43
            $this->addSql('ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
44
            $this->addSql('CREATE INDEX IDX_1197487C2395FCED ON c_thematic_plan (thematic_id)');
45
            $this->addSql('CREATE UNIQUE INDEX UNIQ_1197487C1BAD783F ON c_thematic_plan (resource_node_id)');
46
        }
47
48
        // CLink
49
        $table = $schema->getTable('c_link');
50
        if (false === $table->hasColumn('resource_node_id')) {
51
            $this->addSql('ALTER TABLE c_link ADD resource_node_id INT DEFAULT NULL;');
52
            $this->addSql(
53
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A01BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
54
            );
55
            $this->addSql('CREATE UNIQUE INDEX UNIQ_9209C2A01BAD783F ON c_link (resource_node_id);');
56
        }
57
58
        if ($table->hasIndex('session_id')) {
59
            $this->addSql('DROP INDEX session_id ON c_link');
60
        }
61
        if ($table->hasIndex('course')) {
62
            $this->addSql('DROP INDEX course ON c_link');
63
        }
64
65
        if (false === $table->hasForeignKey('FK_9209C2A012469DE2')) {
66
            $this->addSql(
67
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A012469DE2 FOREIGN KEY (category_id) REFERENCES c_link_category (iid)'
68
            );
69
            $this->addSql('CREATE INDEX IDX_9209C2A012469DE2 ON c_link (category_id)');
70
        }
71
72
        $table = $schema->getTable('c_link_category');
73
        if (false === $table->hasColumn('resource_node_id')) {
74
            $this->addSql(
75
                'ALTER TABLE c_link_category ADD resource_node_id INT DEFAULT NULL, DROP c_id, DROP id, DROP session_id'
76
            );
77
            $this->addSql(
78
                'ALTER TABLE c_link_category ADD CONSTRAINT FK_319D6C9C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
79
            );
80
            $this->addSql('CREATE UNIQUE INDEX UNIQ_319D6C9C1BAD783F ON c_link_category (resource_node_id)');
81
        }
82
        if ($table->hasIndex('session_id')) {
83
            $this->addSql('DROP INDEX session_id ON c_link_category');
84
        }
85
        if ($table->hasIndex('course')) {
86
            $this->addSql('DROP INDEX course ON c_link_category');
87
        }
88
89
        $table = $schema->getTable('c_glossary');
90
        if (false === $table->hasColumn('resource_node_id')) {
91
            $this->addSql('ALTER TABLE c_glossary ADD resource_node_id INT DEFAULT NULL');
92
            $this->addSql(
93
                'ALTER TABLE c_glossary ADD CONSTRAINT FK_A1168D881BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
94
            );
95
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A1168D881BAD783F ON c_glossary (resource_node_id)');
96
        }
97
98
        $table = $schema->getTable('c_student_publication');
99
        if (false === $table->hasColumn('filesize')) {
100
            $this->addSql('ALTER TABLE c_student_publication ADD filesize INT DEFAULT NULL');
101
        }
102
        $this->addSql('ALTER TABLE c_student_publication CHANGE url url VARCHAR(500) DEFAULT NULL');
103
        $this->addSql(
104
            'ALTER TABLE c_student_publication CHANGE url_correction url_correction VARCHAR(500) DEFAULT NULL'
105
        );
106
        $this->addSql('ALTER TABLE c_student_publication CHANGE active active INT DEFAULT NULL');
107
108
        if (false === $table->hasColumn('resource_node_id')) {
109
            $this->addSql(
110
                'ALTER TABLE c_student_publication ADD CONSTRAINT FK_5246F7461BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
111
            );
112
            $this->addSql('CREATE UNIQUE INDEX UNIQ_5246F7461BAD783F ON c_student_publication (resource_node_id)');
113
        }
114
115
        $table = $schema->getTable('c_student_publication_assignment');
116
        if (false === $table->hasColumn('resource_node_id')) {
117
            $this->addSql('ALTER TABLE c_student_publication_assignment ADD resource_node_id INT DEFAULT NULL');
118
            $this->addSql(
119
                'ALTER TABLE c_student_publication_assignment ADD CONSTRAINT FK_25687EB81BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
120
            );
121
            $this->addSql(
122
                'CREATE UNIQUE INDEX UNIQ_25687EB81BAD783F ON c_student_publication_assignment (resource_node_id)'
123
            );
124
        }
125
126
        $table = $schema->getTable('c_student_publication_comment');
127
        if (false === $table->hasColumn('resource_node_id')) {
128
            $this->addSql('ALTER TABLE c_student_publication_comment ADD resource_node_id INT DEFAULT NULL');
129
            $this->addSql(
130
                'ALTER TABLE c_student_publication_comment ADD CONSTRAINT FK_35C509F61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
131
            );
132
            $this->addSql(
133
                'CREATE UNIQUE INDEX UNIQ_35C509F61BAD783F ON c_student_publication_comment (resource_node_id)'
134
            );
135
        }
136
        $table = $schema->getTable('c_calendar_event');
137
        if (false === $table->hasColumn('resource_node_id')) {
138
            $this->addSql('ALTER TABLE c_calendar_event ADD resource_node_id INT DEFAULT NULL');
139
            $this->addSql(
140
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A0622581EE3A445A FOREIGN KEY (parent_event_id) REFERENCES c_calendar_event (iid)'
141
            );
142
            $this->addSql(
143
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A06225811BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
144
            );
145
            $this->addSql('CREATE INDEX IDX_A0622581EE3A445A ON c_calendar_event (parent_event_id)');
146
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A06225811BAD783F ON c_calendar_event (resource_node_id)');
147
        }
148
149
        $table = $schema->getTable('c_calendar_event_attachment');
150
        if (false === $table->hasColumn('resource_node_id')) {
151
            $this->addSql('ALTER TABLE c_calendar_event_attachment ADD id resource_node_id INT DEFAULT NULL');
152
            $this->addSql(
153
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A6EA67784A FOREIGN KEY (agenda_id) REFERENCES c_calendar_event (iid) ON DELETE CASCADE'
154
            );
155
            $this->addSql(
156
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
157
            );
158
            $this->addSql('CREATE INDEX IDX_DDD745A6EA67784A ON c_calendar_event_attachment (agenda_id)');
159
            $this->addSql(
160
                'CREATE UNIQUE INDEX UNIQ_DDD745A61BAD783F ON c_calendar_event_attachment (resource_node_id)'
161
            );
162
        }
163
164
        $table = $schema->getTable('c_calendar_event_repeat');
165
        $this->addSql('ALTER TABLE c_calendar_event_repeat CHANGE cal_id cal_id INT DEFAULT NULL');
166
        if (false === $table->hasForeignKey('FK_86FD1CA87300D633')) {
167
            $this->addSql(
168
                'ALTER TABLE c_calendar_event_repeat ADD CONSTRAINT FK_86FD1CA87300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
169
            );
170
        }
171
        if (false === $table->hasIndex('IDX_86FD1CA87300D633')) {
172
            $this->addSql('CREATE INDEX IDX_86FD1CA87300D633 ON c_calendar_event_repeat (cal_id)');
173
        }
174
175
        $this->addSql('ALTER TABLE c_calendar_event_repeat_not CHANGE cal_id cal_id INT DEFAULT NULL');
176
        if (false === $table->hasForeignKey('FK_7D4436947300D633')) {
177
            $this->addSql(
178
                'ALTER TABLE c_calendar_event_repeat_not ADD CONSTRAINT FK_7D4436947300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
179
            );
180
        }
181
        if (false === $table->hasIndex('IDX_7D4436947300D633')) {
182
            $this->addSql('CREATE INDEX IDX_7D4436947300D633 ON c_calendar_event_repeat_not (cal_id)');
183
        }
184
    }
185
186
    public function down(Schema $schema): void
187
    {
188
    }
189
}
190