ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Test10DBUpdateSteps.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Test\Setup;
22
26
28{
29 protected \ilDBInterface $db;
30
31 public function prepare(\ilDBInterface $db): void
32 {
33 $this->db = $db;
34 }
35
36 public function step_1(): void
37 {
38 if (!$this->db->tableColumnExists('tst_tests', 'ip_range_from')) {
39 $this->db->addTableColumn(
40 'tst_tests',
41 'ip_range_from',
42 [
43 'type' => 'text',
44 'length' => 39
45 ]
46 );
47 }
48 if (!$this->db->tableColumnExists('tst_tests', 'ip_range_to')) {
49 $this->db->addTableColumn(
50 'tst_tests',
51 'ip_range_to',
52 [
53 'type' => 'text',
54 'length' => 39
55 ]
56 );
57 }
58 }
59
60 public function step_2(): void
61 {
62 $this->db->update(
63 'il_cert_cron_queue',
64 ['adapter_class' => [\ilDBConstants::T_TEXT, TestPlaceholderValues::class]],
65 ['adapter_class' => [\ilDBConstants::T_TEXT, 'ilTestPlaceholderValues']]
66 );
67 }
68
69 public function step_3(): void
70 {
73 'id' => [
74 'type' => \ilDBConstants::T_INTEGER,
75 'length' => 8,
76 'notnull' => true
77 ],
78 'ref_id' => [
79 'type' => \ilDBConstants::T_INTEGER,
80 'length' => 8,
81 'notnull' => true
82 ],
83 'admin_id' => [
84 'type' => \ilDBConstants::T_INTEGER,
85 'length' => 8,
86 'notnull' => true
87 ],
88 'interaction_type' => [
89 'type' => \ilDBConstants::T_TEXT,
90 'length' => 256,
91 'notnull' => true
92 ],
93 'modification_ts' => [
94 'type' => \ilDBConstants::T_INTEGER,
95 'length' => 8,
96 'notnull' => true
97 ],
98 'additional_data' => [
99 'type' => \ilDBConstants::T_CLOB
100 ]
101 ]);
103 $this->db->addPrimaryKey(TestLoggingDatabaseRepository::TEST_ADMINISTRATION_LOG_TABLE, ['id']);
104 $this->db->addIndex(TestLoggingDatabaseRepository::TEST_ADMINISTRATION_LOG_TABLE, ['ref_id'], 'rid');
105 }
106
109 'id' => [
110 'type' => \ilDBConstants::T_INTEGER,
111 'length' => 8,
112 'notnull' => true
113 ],
114 'ref_id' => [
115 'type' => \ilDBConstants::T_INTEGER,
116 'length' => 8,
117 'notnull' => true
118 ],
119 'qst_id' => [
120 'type' => \ilDBConstants::T_INTEGER,
121 'length' => 8
122 ],
123 'admin_id' => [
124 'type' => \ilDBConstants::T_INTEGER,
125 'length' => 8,
126 'notnull' => true
127 ],
128 'interaction_type' => [
129 'type' => \ilDBConstants::T_TEXT,
130 'length' => 256,
131 'notnull' => true
132 ],
133 'modification_ts' => [
134 'type' => \ilDBConstants::T_INTEGER,
135 'length' => 8,
136 'notnull' => true
137 ],
138 'additional_data' => [
139 'type' => \ilDBConstants::T_CLOB
140 ]
141 ]);
144 $this->db->addIndex(TestLoggingDatabaseRepository::QUESTION_ADMINISTRATION_LOG_TABLE, ['ref_id'], 'rid');
145 }
146
147 if (!$this->db->tableExists(TestLoggingDatabaseRepository::PARTICIPANT_LOG_TABLE)) {
149 'id' => [
150 'type' => \ilDBConstants::T_INTEGER,
151 'length' => 8,
152 'notnull' => true
153 ],
154 'ref_id' => [
155 'type' => \ilDBConstants::T_INTEGER,
156 'length' => 8,
157 'notnull' => true
158 ],
159 'qst_id' => [
160 'type' => \ilDBConstants::T_INTEGER,
161 'length' => 8,
162 'notnull' => false
163 ],
164 'pax_id' => [
165 'type' => \ilDBConstants::T_INTEGER,
166 'length' => 8,
167 'notnull' => true
168 ],
169 'source_ip' => [
170 'type' => \ilDBConstants::T_TEXT,
171 'length' => 42,
172 'notnull' => true
173 ],
174 'interaction_type' => [
175 'type' => \ilDBConstants::T_TEXT,
176 'length' => 256,
177 'notnull' => true
178 ],
179 'modification_ts' => [
180 'type' => \ilDBConstants::T_INTEGER,
181 'length' => 8,
182 'notnull' => true
183 ],
184 'additional_data' => [
185 'type' => \ilDBConstants::T_CLOB
186 ]
187 ]);
189 $this->db->addPrimaryKey(TestLoggingDatabaseRepository::PARTICIPANT_LOG_TABLE, ['id']);
190 $this->db->addIndex(TestLoggingDatabaseRepository::PARTICIPANT_LOG_TABLE, ['ref_id'], 'rid');
191 }
192
193 if (!$this->db->tableExists(TestLoggingDatabaseRepository::SCORING_LOG_TABLE)) {
195 'id' => [
196 'type' => \ilDBConstants::T_INTEGER,
197 'length' => 8,
198 'notnull' => true
199 ],
200 'ref_id' => [
201 'type' => \ilDBConstants::T_INTEGER,
202 'length' => 8,
203 'notnull' => true
204 ],
205 'qst_id' => [
206 'type' => \ilDBConstants::T_INTEGER,
207 'length' => 8,
208 'notnull' => true
209 ],
210 'admin_id' => [
211 'type' => \ilDBConstants::T_INTEGER,
212 'length' => 8,
213 'notnull' => true
214 ],
215 'pax_id' => [
216 'type' => \ilDBConstants::T_INTEGER,
217 'length' => 8,
218 'notnull' => true
219 ],
220 'interaction_type' => [
221 'type' => \ilDBConstants::T_TEXT,
222 'length' => 256,
223 'notnull' => true
224 ],
225 'modification_ts' => [
226 'type' => \ilDBConstants::T_INTEGER,
227 'length' => 8,
228 'notnull' => true
229 ],
230 'additional_data' => [
231 'type' => \ilDBConstants::T_CLOB
232 ]
233 ]);
234 $this->db->createSequence(TestLoggingDatabaseRepository::SCORING_LOG_TABLE);
235 $this->db->addPrimaryKey(TestLoggingDatabaseRepository::SCORING_LOG_TABLE, ['id']);
236 $this->db->addIndex(TestLoggingDatabaseRepository::SCORING_LOG_TABLE, ['ref_id'], 'rid');
237 }
238
239 if (!$this->db->tableExists(TestLoggingDatabaseRepository::ERROR_LOG_TABLE)) {
240 $this->db->createTable(TestLoggingDatabaseRepository::ERROR_LOG_TABLE, [
241 'id' => [
242 'type' => \ilDBConstants::T_INTEGER,
243 'length' => 8,
244 'notnull' => true
245 ],
246 'ref_id' => [
247 'type' => \ilDBConstants::T_INTEGER,
248 'length' => 8,
249 'notnull' => true
250 ],
251 'qst_id' => [
252 'type' => \ilDBConstants::T_INTEGER,
253 'length' => 8
254 ],
255 'admin_id' => [
256 'type' => \ilDBConstants::T_INTEGER,
257 'length' => 8
258 ],
259 'pax_id' => [
260 'type' => \ilDBConstants::T_INTEGER,
261 'length' => 8
262 ],
263 'interaction_type' => [
264 'type' => \ilDBConstants::T_TEXT,
265 'length' => 256,
266 'notnull' => true
267 ],
268 'modification_ts' => [
269 'type' => \ilDBConstants::T_INTEGER,
270 'length' => 8,
271 'notnull' => true
272 ],
273 'error_message' => [
274 'type' => \ilDBConstants::T_TEXT,
275 'length' => 4000,
276 'notnull' => true,
277 'default' => ''
278 ]
279 ]);
280 $this->db->createSequence(TestLoggingDatabaseRepository::ERROR_LOG_TABLE);
281 $this->db->addPrimaryKey(TestLoggingDatabaseRepository::ERROR_LOG_TABLE, ['id']);
282 $this->db->addIndex(TestLoggingDatabaseRepository::ERROR_LOG_TABLE, ['ref_id'], 'rid');
283 }
284 }
285
286 public function step_4(): void
287 {
288 if (!$this->db->tableColumnExists('tst_invited_user', 'ip_range_from')) {
289 $this->db->addTableColumn(
290 'tst_invited_user',
291 'ip_range_from',
292 [
293 'type' => 'text',
294 'length' => 39
295 ]
296 );
297 }
298 if (!$this->db->tableColumnExists('tst_invited_user', 'ip_range_to')) {
299 $this->db->addTableColumn(
300 'tst_invited_user',
301 'ip_range_to',
302 [
303 'type' => 'text',
304 'length' => 39
305 ]
306 );
307 }
308
309
310 if ($this->db->tableColumnExists('tst_invited_user', 'clientip')) {
311 $this->db->manipulate('UPDATE tst_invited_user SET ip_range_from = clientip, ip_range_to = clientip WHERE ip_range_from IS NULL AND ip_range_to IS NULL');
312 $this->db->dropTableColumn('tst_invited_user', 'clientip');
313 }
314 }
315
316 public function step_5(): void
317 {
318 if (!$this->db->tableColumnExists('tst_addtime', 'user_fi')) {
319 $this->db->addTableColumn(
320 'tst_addtime',
321 'user_fi',
322 [
323 'type' => \ilDBConstants::T_INTEGER,
324 'length' => 8,
325 'notnull' => true
326 ]
327 );
328 }
329 if (!$this->db->tableColumnExists('tst_addtime', 'test_fi')) {
330 $this->db->addTableColumn(
331 'tst_addtime',
332 'test_fi',
333 [
334 'type' => \ilDBConstants::T_INTEGER,
335 'length' => 8,
336 'notnull' => true
337 ]
338 );
339 }
340
341 if ($this->db->tableColumnExists('tst_addtime', 'active_fi')) {
342 $this->db->manipulate(
343 '
344 UPDATE tst_addtime INNER JOIN tst_active ON tst_active.active_id = tst_addtime.active_fi
345 SET tst_addtime.test_fi = tst_active.test_fi, tst_addtime.user_fi = tst_active.user_fi'
346 );
347
348 $this->db->dropTableColumn('tst_addtime', 'active_fi');
349 }
350
351 if (!$this->db->primaryExistsByFields('tst_addtime', ['user_fi', 'test_fi'])) {
352 $this->db->addPrimaryKey('tst_addtime', ['user_fi', 'test_fi']);
353 }
354 }
355
356 public function step_6(): void
357 {
358 if ($this->db->tableColumnExists('tst_tests', 'broken')) {
359 $this->db->dropTableColumn('tst_tests', 'broken');
360 }
361 }
362
363 public function step_7(): void
364 {
365 if ($this->db->tableColumnExists('tst_tests', 'obligations_enabled')) {
366 $this->db->dropTableColumn('tst_tests', 'obligations_enabled');
367 }
368
369 if ($this->db->tableColumnExists('tst_pass_result', 'obligations_answered')) {
370 $this->db->dropTableColumn('tst_pass_result', 'obligations_answered');
371 }
372
373 if ($this->db->tableColumnExists('tst_test_question', 'obligatory')) {
374 $this->db->dropTableColumn('tst_test_question', 'obligatory');
375 }
376
377 if ($this->db->tableColumnExists('tst_result_cache', 'obligations_answered')) {
378 $this->db->dropTableColumn('tst_result_cache', 'obligations_answered');
379 }
380 }
381
382 public function step_8(): void
383 {
384 if (!$this->db->tableColumnExists('tst_pass_result', 'finalized_by')) {
385 $this->db->addTableColumn(
386 'tst_pass_result',
387 'finalized_by',
388 [
389 'type' => \ilDBConstants::T_TEXT,
390 'length' => 256,
391 'notnull' => false
392 ]
393 );
394 }
395 }
396
397 public function step_9(): void
398 {
399 $this->db->manipulate('DELETE FROM rbac_operations WHERE operation = "tst_statistics"');
400 }
401
402 public function step_10(): void
403 {
404 if ($this->db->tableColumnExists('tst_tests', 'author')) {
405 $this->db->dropTableColumn('tst_tests', 'author');
406 }
407 }
408
409 public function step_11(): void
410 {
411 if ($this->db->tableColumnExists('tst_tests', 'enable_processing_time')) {
412 $this->db->manipulateF(
413 'UPDATE tst_tests SET enable_processing_time = %s WHERE enable_processing_time IS NULL',
415 [0]
416 );
417 $this->db->modifyTableColumn(
418 'tst_tests',
419 'enable_processing_time',
420 [
421 'type' => \ilDBConstants::T_INTEGER,
422 'length' => 1,
423 'notnull' => true,
424 'default' => 0
425 ]
426 );
427 }
428 }
429
430 public function step_12(): void
431 {
432 if (!$this->db->tableExists(DBRepository::TST_EXPORT_TABLE)) {
433 $this->db->createTable(DBRepository::TST_EXPORT_TABLE, [
434 'object_id' => [
435 'type' => \ilDBConstants::T_INTEGER,
436 'length' => 8,
437 'notnull' => true
438 ],
439 'type' => [
440 'type' => \ilDBConstants::T_TEXT,
441 'length' => 32,
442 'notnull' => true
443 ],
444 'rid' => [
445 'type' => \ilDBConstants::T_TEXT,
446 'length' => 64
447 ]
448 ]);
449 $this->db->addPrimaryKey(DBRepository::TST_EXPORT_TABLE, ['rid']);
450 $this->db->addIndex(DBRepository::TST_EXPORT_TABLE, ['object_id'], 'oid');
451 }
452 }
453
454 public function step_13(): void
455 {
456 $this->db->update(
457 'rbac_operations',
458 ['op_order' => [\ilDBConstants::T_INTEGER, 4100]],
459 ['operation' => [\ilDBConstants::T_TEXT, 'tst_history_read']]
460 );
461 $this->db->update(
462 'rbac_operations',
463 ['op_order' => [\ilDBConstants::T_INTEGER, 4200]],
464 ['operation' => [\ilDBConstants::T_TEXT, 'tst_results']]
465 );
466 }
467}
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...