|
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_attendance. |
|
14
|
|
|
*/ |
|
15
|
|
|
class Version20170625123000 extends AbstractMigrationChamilo |
|
16
|
|
|
{ |
|
17
|
|
|
public function up(Schema $schema): void |
|
18
|
|
|
{ |
|
19
|
|
|
$em = $this->getEntityManager(); |
|
20
|
|
|
$container = $this->getContainer(); |
|
21
|
|
|
|
|
22
|
|
|
// CAttendance |
|
23
|
|
|
$table = $schema->getTable('c_attendance'); |
|
24
|
|
|
if ($table->hasIndex('course')) { |
|
25
|
|
|
$this->addSql('DROP INDEX course ON c_attendance'); |
|
26
|
|
|
} |
|
27
|
|
|
if ($table->hasIndex('session_id')) { |
|
28
|
|
|
$this->addSql('DROP INDEX session_id ON c_attendance'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->addSql('ALTER TABLE c_attendance CHANGE active active INT NOT NULL'); |
|
32
|
|
|
|
|
33
|
|
|
if (false === $table->hasColumn('resource_node_id')) { |
|
34
|
|
|
$this->addSql('ALTER TABLE c_attendance ADD resource_node_id INT DEFAULT NULL'); |
|
35
|
|
|
$this->addSql('ALTER TABLE c_attendance ADD CONSTRAINT FK_413634921BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'); |
|
36
|
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_413634921BAD783F ON c_attendance (resource_node_id)'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$table = $schema->getTable('c_attendance_calendar'); |
|
40
|
|
|
if ($table->hasIndex('course')) { |
|
41
|
|
|
$this->addSql('DROP INDEX course ON c_attendance_calendar'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($table->hasIndex('attendance_id')) { |
|
45
|
|
|
$this->addSql('DROP INDEX attendance_id ON c_attendance_calendar'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->addSql('ALTER TABLE c_attendance_calendar CHANGE attendance_id attendance_id INT DEFAULT NULL;'); |
|
49
|
|
|
|
|
50
|
|
|
if (false === $table->hasForeignKey('FK_AA3A9AB8163DDA15')) { |
|
51
|
|
|
$this->addSql('ALTER TABLE c_attendance_calendar ADD CONSTRAINT FK_AA3A9AB8163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid);'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (false === $table->hasIndex('IDX_AA3A9AB8163DDA15')) { |
|
55
|
|
|
$this->addSql('CREATE INDEX IDX_AA3A9AB8163DDA15 ON c_attendance_calendar (attendance_id);'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$table = $schema->getTable('c_attendance_sheet'); |
|
59
|
|
|
|
|
60
|
|
|
if ($table->hasIndex('course')) { |
|
61
|
|
|
$this->addSql('DROP INDEX course ON c_attendance_sheet;'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($table->hasIndex('user')) { |
|
65
|
|
|
$this->addSql('DROP INDEX user ON c_attendance_sheet;'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->addSql('UPDATE c_attendance_sheet SET attendance_calendar_id = NULL WHERE attendance_calendar_id = 0;'); |
|
69
|
|
|
$this->addSql('ALTER TABLE c_attendance_sheet CHANGE user_id user_id INT DEFAULT NULL, CHANGE attendance_calendar_id attendance_calendar_id INT DEFAULT NULL'); |
|
70
|
|
|
|
|
71
|
|
|
//ALTER TABLE c_attendance_sheet DROP c_id |
|
72
|
|
|
|
|
73
|
|
|
if (false === $table->hasForeignKey('FK_AD1394FAA76ED395')) { |
|
74
|
|
|
$this->addSql('ALTER TABLE c_attendance_sheet ADD CONSTRAINT FK_AD1394FAA76ED395 FOREIGN KEY (user_id) REFERENCES user (id);'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
if (false === $table->hasForeignKey('FK_AD1394FA19EA43C3')) { |
|
78
|
|
|
$this->addSql('ALTER TABLE c_attendance_sheet ADD CONSTRAINT FK_AD1394FA19EA43C3 FOREIGN KEY (attendance_calendar_id) REFERENCES c_attendance_calendar (iid);'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if (false === $table->hasIndex('IDX_AD1394FA19EA43C3')) { |
|
82
|
|
|
$this->addSql('CREATE INDEX IDX_AD1394FA19EA43C3 ON c_attendance_sheet (attendance_calendar_id);'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (false === $table->hasIndex('IDX_AD1394FAA76ED395')) { |
|
86
|
|
|
$this->addSql('CREATE INDEX IDX_AD1394FAA76ED395 ON c_attendance_sheet (user_id);'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$table = $schema->getTable('c_attendance_sheet_log'); |
|
90
|
|
|
|
|
91
|
|
|
if ($table->hasIndex('course')) { |
|
92
|
|
|
$this->addSql('DROP INDEX course ON c_attendance_sheet_log;'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if ($table->hasIndex('user')) { |
|
96
|
|
|
$this->addSql('DROP INDEX user ON c_attendance_sheet;'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$this->addSql('DELETE FROM c_attendance_sheet_log WHERE attendance_id = 0'); |
|
100
|
|
|
$this->addSql('DELETE FROM c_attendance_sheet_log WHERE lastedit_user_id = 0'); |
|
101
|
|
|
|
|
102
|
|
|
$this->addSql('ALTER TABLE c_attendance_sheet_log CHANGE attendance_id attendance_id INT DEFAULT NULL'); |
|
103
|
|
|
$this->addSql('ALTER TABLE c_attendance_sheet_log CHANGE lastedit_user_id lastedit_user_id INT DEFAULT NULL'); |
|
104
|
|
|
|
|
105
|
|
|
if (!$table->hasForeignKey('FK_181D0917163DDA15')) { |
|
106
|
|
|
$this->addSql( |
|
107
|
|
|
'ALTER TABLE c_attendance_sheet_log ADD CONSTRAINT FK_181D0917163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid) ON DELETE CASCADE' |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
if (!$table->hasForeignKey('FK_181D091731BA5DD')) { |
|
111
|
|
|
$this->addSql( |
|
112
|
|
|
'ALTER TABLE c_attendance_sheet_log ADD CONSTRAINT FK_181D091731BA5DD FOREIGN KEY (lastedit_user_id) REFERENCES user (id) ON DELETE CASCADE' |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
if (!$table->hasIndex('IDX_181D0917163DDA15')) { |
|
116
|
|
|
$this->addSql('CREATE INDEX IDX_181D0917163DDA15 ON c_attendance_sheet_log (attendance_id)'); |
|
117
|
|
|
} |
|
118
|
|
|
if (!$table->hasIndex('IDX_181D091731BA5DD')) { |
|
119
|
|
|
$this->addSql('CREATE INDEX IDX_181D091731BA5DD ON c_attendance_sheet_log (lastedit_user_id)'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$table = $schema->getTable('c_attendance_result'); |
|
123
|
|
|
|
|
124
|
|
|
if ($table->hasIndex('course')) { |
|
125
|
|
|
$this->addSql('DROP INDEX course ON c_attendance_result'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
if ($table->hasIndex('user_id')) { |
|
129
|
|
|
$this->addSql('DROP INDEX user_id ON c_attendance_result'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if ($table->hasIndex('attendance_id')) { |
|
133
|
|
|
$this->addSql('DROP INDEX attendance_id ON c_attendance_result;'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$this->addSql('UPDATE c_attendance_result SET attendance_id = NULL WHERE attendance_id = 0'); |
|
137
|
|
|
$this->addSql('UPDATE c_attendance_result SET user_id = NULL WHERE user_id = 0'); |
|
138
|
|
|
|
|
139
|
|
|
//ALTER TABLE c_attendance_result DROP c_id, ; |
|
140
|
|
|
$this->addSql('ALTER TABLE c_attendance_result CHANGE user_id user_id INT DEFAULT NULL, CHANGE attendance_id attendance_id INT DEFAULT NULL '); |
|
141
|
|
|
|
|
142
|
|
|
//ALTER TABLE c_attendance_sheet DROP c_id |
|
143
|
|
|
|
|
144
|
|
|
if (false === $table->hasForeignKey('FK_2C7640A76ED395')) { |
|
145
|
|
|
$this->addSql('ALTER TABLE c_attendance_result ADD CONSTRAINT FK_2C7640A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);'); |
|
146
|
|
|
} |
|
147
|
|
|
if (false === $table->hasForeignKey('FK_2C7640163DDA15')) { |
|
148
|
|
|
$this->addSql('ALTER TABLE c_attendance_result ADD CONSTRAINT FK_2C7640163DDA15 FOREIGN KEY (attendance_id) REFERENCES c_attendance (iid);'); |
|
149
|
|
|
} |
|
150
|
|
|
if (false === $table->hasIndex('IDX_2C7640A76ED395')) { |
|
151
|
|
|
$this->addSql('CREATE INDEX IDX_2C7640A76ED395 ON c_attendance_result (user_id);'); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if (false === $table->hasIndex('IDX_2C7640163DDA15')) { |
|
155
|
|
|
$this->addSql('CREATE INDEX IDX_2C7640163DDA15 ON c_attendance_result (attendance_id);'); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
$table = $schema->getTable('c_attendance_calendar_rel_group'); |
|
159
|
|
|
|
|
160
|
|
|
if ($table->hasIndex('course')) { |
|
161
|
|
|
$this->addSql('DROP INDEX course ON c_attendance_calendar_rel_group'); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
//ALTER TABLE c_attendance_calendar_rel_group DROP c_id, |
|
165
|
|
|
$this->addSql('UPDATE c_attendance_calendar_rel_group SET group_id = NULL WHERE group_id = 0'); |
|
166
|
|
|
$this->addSql('UPDATE c_attendance_calendar_rel_group SET calendar_id = NULL WHERE calendar_id = 0'); |
|
167
|
|
|
$this->addSql('ALTER TABLE c_attendance_calendar_rel_group CHANGE group_id group_id INT DEFAULT NULL, CHANGE calendar_id calendar_id INT DEFAULT NULL;'); |
|
168
|
|
|
|
|
169
|
|
|
if (false === $table->hasForeignKey('FK_C2AB1FACFE54D947')) { |
|
170
|
|
|
if ($table->hasIndex('group')) { |
|
171
|
|
|
$this->addSql('DROP INDEX `group` ON c_attendance_calendar_rel_group'); |
|
172
|
|
|
} |
|
173
|
|
|
$this->addSql('ALTER TABLE c_attendance_calendar_rel_group ADD CONSTRAINT FK_C2AB1FACFE54D947 FOREIGN KEY (group_id) REFERENCES c_group_info (iid);'); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
if (false === $table->hasForeignKey('FK_C2AB1FACA40A2C8')) { |
|
177
|
|
|
$this->addSql('ALTER TABLE c_attendance_calendar_rel_group ADD CONSTRAINT FK_C2AB1FACA40A2C8 FOREIGN KEY (calendar_id) REFERENCES c_attendance_calendar (iid);'); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if (false === $table->hasIndex('IDX_C2AB1FACA40A2C8')) { |
|
181
|
|
|
$this->addSql('CREATE INDEX IDX_C2AB1FACA40A2C8 ON c_attendance_calendar_rel_group (calendar_id);'); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
if (false === $table->hasIndex('IDX_C2AB1FACFE54D947')) { |
|
185
|
|
|
$this->addSql('CREATE INDEX IDX_C2AB1FACFE54D947 ON c_attendance_calendar_rel_group (group_id);'); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function down(Schema $schema): void |
|
190
|
|
|
{ |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
|