Passed
Push — master ( 6c23c3...c1688f )
by Julito
09:45
created

Version20170625143000::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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)'
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
88
            //$this->addSql('ALTER TABLE c_thematic_advance ADD CONSTRAINT FK_62798E971BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
89
            $this->addSql('CREATE UNIQUE INDEX UNIQ_62798E971BAD783F ON c_thematic_advance (resource_node_id)');
90
        }*/
91
92
        $table = $schema->getTable('c_thematic_plan');
93
        $this->addSql('ALTER TABLE c_thematic_plan CHANGE thematic_id thematic_id INT DEFAULT NULL');
94
95
        if ($table->hasIndex('course')) {
96
            $this->addSql('DROP INDEX course ON c_thematic_plan');
97
        }
98
99
        if ($table->hasColumn('c_id')) {
100
            //$this->addSql('ALTER TABLE c_thematic_plan DROP c_id;');
101
        }
102
        if (false === $table->hasForeignKey('FK_1197487C2395FCED')) {
103
            $this->addSql(
104
                'ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C2395FCED FOREIGN KEY (thematic_id) REFERENCES c_thematic (iid)'
105
            );
106
        }
107
108
        if (false === $table->hasIndex('IDX_1197487C2395FCED')) {
109
            $this->addSql('CREATE INDEX IDX_1197487C2395FCED ON c_thematic_plan (thematic_id)');
110
        }
111
112
        /*
113
        if (false === $table->hasColumn('resource_node_id')) {
114
            $this->addSql('ALTER TABLE c_thematic_plan ADD resource_node_id INT DEFAULT NULL');
115
116
            $this->addSql('ALTER TABLE c_thematic_plan ADD CONSTRAINT FK_1197487C1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
117
            $this->addSql('CREATE UNIQUE INDEX UNIQ_1197487C1BAD783F ON c_thematic_plan (resource_node_id)');
118
        }*/
119
120
        // CLink
121
        $table = $schema->getTable('c_link');
122
        if (false === $table->hasColumn('resource_node_id')) {
123
            $this->addSql('ALTER TABLE c_link ADD resource_node_id INT DEFAULT NULL;');
124
            $this->addSql(
125
                'ALTER TABLE c_link ADD CONSTRAINT FK_9209C2A01BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE;'
126
            );
127
            $this->addSql('CREATE UNIQUE INDEX UNIQ_9209C2A01BAD783F ON c_link (resource_node_id);');
128
        }
129
130
        if ($table->hasIndex('session_id')) {
131
            $this->addSql('DROP INDEX session_id ON c_link');
132
        }
133
        if ($table->hasIndex('course')) {
134
            $this->addSql('DROP INDEX course ON c_link');
135
        }
136
137
        $this->addSql('UPDATE c_link SET category_id = NULL WHERE category_id = 0');
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)'
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
        if ($table->hasIndex('session_id')) {
154
            $this->addSql('DROP INDEX session_id ON c_link_category');
155
        }
156
        if ($table->hasIndex('course')) {
157
            $this->addSql('DROP INDEX course ON c_link_category');
158
        }
159
160
        $table = $schema->getTable('c_glossary');
161
162
        if ($table->hasIndex('course')) {
163
            $this->addSql('DROP INDEX course ON c_glossary');
164
        }
165
166
        if ($table->hasIndex('session_id')) {
167
            $this->addSql('DROP INDEX session_id ON c_glossary');
168
        }
169
170
        if (false === $table->hasColumn('resource_node_id')) {
171
            $this->addSql('ALTER TABLE c_glossary ADD resource_node_id INT DEFAULT NULL');
172
            $this->addSql(
173
                'ALTER TABLE c_glossary ADD CONSTRAINT FK_A1168D881BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
174
            );
175
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A1168D881BAD783F ON c_glossary (resource_node_id)');
176
        }
177
    }
178
179
    public function down(Schema $schema): void
180
    {
181
    }
182
}
183