ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilResourceStorageDB80.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilDBInterface $db;
26
27 public function prepare(ilDBInterface $db): void
28 {
29 $this->db = $db;
30 }
31
32 public function step_1(): void
33 {
34 if (!$this->db->tableExists('il_resource_stkh_u') && $this->db->tableExists('il_resource_stakeh')) {
35 $this->db->renameTable('il_resource_stakeh', 'il_resource_stkh_u');
36 $this->db->createTable(
37 'il_resource_stkh',
38 [
39 'id' => ['type' => 'text', 'length' => 32, 'notnull' => true, 'default' => ''],
40 'class_name' => ['type' => 'text', 'length' => 250, 'notnull' => true, 'default' => ''],
41 ]
42 );
43 $this->db->addPrimaryKey('il_resource_stkh', ['id']);
44 $this->db->manipulate(
45 "INSERT INTO il_resource_stkh (id, class_name) SELECT DISTINCT stakeholder_id, stakeholder_class FROM il_resource_stkh_u;"
46 );
47 }
48
49 if ($this->db->tableColumnExists('il_resource_stkh_u', 'stakeholder_class')) {
50 $this->db->dropTableColumn('il_resource_stkh_u', 'stakeholder_class');
51 }
52 if ($this->db->tableColumnExists('il_resource_stkh_u', 'internal')) {
53 $this->db->dropTableColumn('il_resource_stkh_u', 'internal');
54 }
55 }
56
57 public function step_2(): void
58 {
59 // rename all identification columns to rid
60 if (!$this->db->tableColumnExists('il_resource', 'rid')) {
61 $this->db->renameTableColumn(
62 'il_resource',
63 'identification',
64 'rid'
65 );
66 }
67 if (!$this->db->tableColumnExists('il_resource_info', 'rid')) {
68 $this->db->renameTableColumn(
69 'il_resource_info',
70 'identification',
71 'rid'
72 );
73 }
74 if (!$this->db->tableColumnExists('il_resource_revision', 'rid')) {
75 $this->db->renameTableColumn(
76 'il_resource_revision',
77 'identification',
78 'rid'
79 );
80 }
81 if (!$this->db->tableColumnExists('il_resource_stkh_u', 'rid')) {
82 $this->db->renameTableColumn(
83 'il_resource_stkh_u',
84 'identification',
85 'rid'
86 );
87 }
88 }
89
90 public function step_3(): void
91 {
92 // set all rid columns to the same size
93 $attributes = [
94 'length' => 64,
95 'notnull' => true,
96 'default' => '',
97 ];
98 $this->db->modifyTableColumn(
99 'il_resource',
100 'rid',
101 $attributes
102 );
103 $this->db->modifyTableColumn(
104 'il_resource_info',
105 'rid',
106 $attributes
107 );
108 $this->db->modifyTableColumn(
109 'il_resource_revision',
110 'rid',
111 $attributes
112 );
113 $this->db->modifyTableColumn(
114 'il_resource_stkh_u',
115 'rid',
116 $attributes
117 );
118 try {
119 $this->db->modifyTableColumn(
120 'file_data',
121 'rid',
122 $attributes
123 );
124 } catch (Throwable) {
125 }
126 }
127
128 public function step_4(): void
129 {
130 if (!$this->db->tableColumnExists('il_resource_info', 'version_number')) {
131 $this->db->addTableColumn(
132 'il_resource_info',
133 'version_number',
134 [
135 'type' => 'integer',
136 'length' => 8
137 ]
138 );
139
140 $this->db->manipulate(
141 "UPDATE il_resource_info
142JOIN il_resource_revision ON il_resource_info.internal = il_resource_revision.internal
143SET il_resource_info.version_number = il_resource_revision.version_number
144"
145 );
146 }
147 }
148
149 public function step_5(): void
150 {
151 // remove internal columns and add primaries
152 if ($this->db->tableColumnExists('il_resource_revision', 'internal')) {
153 $this->db->dropTableColumn('il_resource_revision', 'internal');
154 $this->db->addPrimaryKey(
155 'il_resource_revision',
156 [
157 'rid',
158 'version_number',
159 ]
160 );
161 }
162 if ($this->db->tableColumnExists('il_resource_info', 'internal')) {
163 $this->db->dropTableColumn('il_resource_info', 'internal');
164 $this->db->addPrimaryKey(
165 'il_resource_info',
166 [
167 'rid',
168 'version_number',
169 ]
170 );
171 }
172 if ($this->db->tableColumnExists('il_resource_stkh', 'internal')) {
173 $this->db->dropTableColumn('il_resource_stkh', 'internal');
174 $this->db->addPrimaryKey(
175 'il_resource_stkh',
176 [
177 'rid',
178 'stakeholder_id',
179 ]
180 );
181 }
182 }
183
184 public function step_6(): void
185 {
186 // set several fields to notnull
187 $attributes = [
188 'notnull' => true,
189 'default' => '',
190 ];
191 $table_fields = [
192 'il_resource' => ['storage_id'],
193 'il_resource_info' => ['title', 'size', 'creation_date'],
194 'il_resource_revision' => ['owner_id', 'title'],
195 ];
196 foreach ($table_fields as $table => $fields) {
197 foreach ($fields as $field) {
198 $this->db->modifyTableColumn(
199 $table,
200 $field,
201 $attributes
202 );
203 }
204 }
205 }
206
207 public function step_7(): void
208 {
209 // add index to file_data rid
210 if (!$this->db->indexExistsByFields('file_data', ['rid'])) {
211 $this->db->addIndex('file_data', ['rid'], 'i1');
212 }
213 }
214
215 public function step_8(): void
216 {
217 // several changes to irss tables
218 $this->db->modifyTableColumn(
219 'il_resource_revision',
220 'available',
221 [
222 'default' => 1,
223 ]
224 );
225 $this->db->modifyTableColumn(
226 'il_resource_stkh_u',
227 'stakeholder_id',
228 ['length' => 64]
229 );
230 $this->db->modifyTableColumn(
231 'il_resource_stkh',
232 'id',
233 ['length' => 64]
234 );
235 $this->db->modifyTableColumn(
236 'il_resource_info',
237 'title',
238 ['length' => 255]
239 );
240 $this->db->modifyTableColumn(
241 'il_resource_revision',
242 'title',
243 ['length' => 255]
244 );
245 }
246
247 public function step_9(): void
248 {
249 if (!$this->db->tableExists('il_resource_rc')) {
250 $this->db->createTable(
251 'il_resource_rc',
252 [
253 'rcid' => [
254 'type' => 'text',
255 'length' => 64,
256 'notnull' => true,
257 'default' => '',
258 ],
259 'title' => [
260 'type' => 'text',
261 'length' => 4000,
262 'notnull' => false,
263 'default' => '',
264 ],
265 'owner' => [
266 'type' => 'integer',
267 'length' => 8,
268 'notnull' => true,
269 'default' => 0,
270 ],
271 ]
272 );
273 }
274
275 if (!$this->db->tableExists('il_resource_rca')) {
276 $this->db->createTable(
277 'il_resource_rca',
278 [
279 'rcid' => [
280 'type' => 'text',
281 'length' => 64,
282 'notnull' => true,
283 'default' => '',
284 ],
285 'rid' => [
286 'type' => 'text',
287 'length' => 64,
288 'notnull' => true,
289 'default' => '',
290 ],
291 'position' => [
292 'type' => 'integer',
293 'length' => 8,
294 'notnull' => true,
295 'default' => 0,
296 ],
297 ]
298 );
299 }
300 }
301
302 public function step_10(): void
303 {
304 if (!$this->db->primaryExistsByFields('il_resource_rca', ['rcid', 'rid'])) {
305 $this->db->addPrimaryKey(
306 'il_resource_rca',
307 [
308 'rcid',
309 'rid',
310 ]
311 );
312 }
313
314 if (!$this->db->primaryExistsByFields('il_resource_rc', ['rcid'])) {
315 $this->db->addPrimaryKey(
316 'il_resource_rc',
317 [
318 'rcid'
319 ]
320 );
321 }
322 }
323
324 public function step_11(): void
325 {
326 $this->db->modifyTableColumn(
327 'il_resource_rc',
328 'owner',
329 ['length' => 4]
330 );
331
332 $this->db->modifyTableColumn(
333 'il_resource_revision',
334 'owner_id',
335 ['length' => 4]
336 );
337 }
338
339 public function step_12(): void
340 {
341 $this->db->renameTableColumn(
342 'il_resource_rc',
343 'owner',
344 'owner_id',
345 );
346 }
347
348 public function step_13(): void
349 {
350 if ($this->db->indexExistsByFields('il_resource_stkh_u', ['stakeholder_id'])) {
351 $this->db->dropIndexByFields('il_resource_stkh_u', ['stakeholder_id']);
352 }
353 if ($this->db->indexExistsByFields('il_resource_stkh_u', ['rid'])) {
354 $this->db->dropIndexByFields('il_resource_stkh_u', ['rid']);
355 }
356 if (!$this->db->primaryExistsByFields('il_resource_stkh_u', ['rid', 'stakeholder_id'])) {
357 $this->db->addPrimaryKey('il_resource_stkh_u', ['rid', 'stakeholder_id']);
358 }
359 }
360}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...