ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UpdateSteps.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
28{
30
31 public function prepare(ilDBInterface $database): void
32 {
33 $this->database = $database;
34 }
35
36 public function step_1(): void
37 {
38 $this->renameTables([
39 'tos_documents' => 'ldoc_documents',
40 'tos_criterion_to_doc' => 'ldoc_criteria',
41 'tos_acceptance_track' => 'ldoc_acceptance_track',
42 'tos_versions' => 'ldoc_versions',
43 ]);
44
45 $this->ensureColumn('ldoc_documents', 'provider', [
46 'type' => ilDBConstants::T_TEXT,
47 'notnull' => true,
48 'default' => 'tos',
49 'length' => 255,
50 ]);
51
52 $this->ensureColumn('ldoc_documents', 'hash', [
53 'type' => ilDBConstants::T_TEXT,
54 'notnull' => true,
55 'default' => '',
56 'length' => 255,
57 ]);
58
59 foreach (['ldoc_documents', 'ldoc_versions'] as $table) {
60 $this->ensureColumn($table, 'type', [
61 'type' => ilDBConstants::T_TEXT,
62 'notnull' => true,
63 'default' => 'html',
64 'length' => 255,
65 ]);
66 }
67 }
68
69 public function step_2(): void
70 {
71 // Keep
72 }
73
74 public function step_3(): void
75 {
76 $this->ensureColumn('ldoc_versions', 'provider', [
77 'type' => ilDBConstants::T_TEXT,
78 'notnull' => true,
79 'default' => '',
80 'length' => 255,
81 ]);
82
83 $select_provider = '(SELECT d.provider FROM ldoc_documents AS d WHERE v.doc_id = d.id)';
84 $this->database->manipulate("UPDATE ldoc_versions AS v SET provider = $select_provider WHERE provider = '' AND EXISTS $select_provider");
85 }
86
90 private function ensureColumn(string $table, string $name, array $attributes): void
91 {
92 if (!$this->database->tableColumnExists($table, $name)) {
93 $this->database->addTableColumn($table, $name, $attributes);
94 }
95 }
96
100 private function renameTables(array $tables): void
101 {
102 foreach ($tables as $old => $new) {
103 if (!$this->database->tableExists($new)) {
104 $this->database->renameTable($old, $new);
105 }
106 }
107 }
108}
ensureColumn(string $table, string $name, array $attributes)
Definition: UpdateSteps.php:90
prepare(ilDBInterface $database)
Definition: UpdateSteps.php:31
Class ilDBConstants.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Agent.php:21