ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DBUpdateSteps11.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\User\Setup;
22
24use ILIAS\Data\UUID\Factory as UUIDFactory;
25
27{
28 private \ilDBInterface $db;
29 private UUIDFactory $uuid_factory;
30
31 public function prepare(\ilDBInterface $db): void
32 {
33 $this->db = $db;
34 $this->uuid_factory = new UUIDFactory();
35 }
36
37 private function insertSetting(
38 string $keyword,
39 string $value
40 ): void {
41 if ($this->db->fetchObject(
42 $this->db->query(
43 "SELECT COUNT(*) cnt FROM settings WHERE module = 'common' AND keyword='{$keyword}'"
44 )
45 )?->cnt > 0
46 ) {
47 return;
48 }
49
50 $this->db->insert(
51 'settings',
52 [
53 'module' => [
55 'common'
56 ],
57 'keyword' => [
59 $keyword
60 ],
61 'value' => [
63 $value
64 ],
65 ]
66 );
67 }
68
69 public function step_1(): void
70 {
71 if (!$this->db->tableColumnExists('mail_template', 'att_rid')) {
72 $this->db->addTableColumn(
73 'mail_template',
74 'att_rid',
75 [
76 'type' => \ilDBConstants::T_TEXT,
77 'length' => 64
78 ]
79 );
80 }
81 }
82
83 public function step_2(): void
84 {
85 if ($this->db->tableExists('usr_data_multi')
86 && !$this->db->tableExists('usr_profile_data')) {
87 $this->db->renameTable(
88 'usr_data_multi',
89 'usr_profile_data'
90 );
91 }
92 if ($this->db->tableExists('usr_profile_data')) {
93 $this->db->modifyTableColumn('usr_profile_data', 'value', ['type' => \ilDBConstants::T_CLOB]);
94 }
95 if ($this->db->sequenceExists('usr_profile_data')) {
96 $this->db->dropSequence('usr_profile_data');
97 }
98 if ($this->db->tableExists('usr_profile_data')
99 && $this->db->tableColumnExists('usr_profile_data', 'id')) {
100 $this->db->dropTableColumn('usr_profile_data', 'id');
101 }
102 if ($this->db->tableExists('usr_profile_data')
103 && !$this->db->indexExistsByFields('usr_profile_data', ['usr_id', 'field_id'])) {
104 $this->db->addIndex('usr_profile_data', ['usr_id', 'field_id'], 'uf');
105 }
106 }
107
108 public function step_3(): void
109 {
110 if ($this->db->tableExists('udf_data')) {
111 $this->db->dropTable('udf_data');
112 }
113
114 if ($this->db->sequenceExists('udf_definition')) {
115 /*
116 * 2025-07-17, sk: This needs to be done here, as we absolutely need
117 * the change to be ready for the next steps
118 */
119 $this->db->modifyTableColumn('ldap_attribute_mapping', 'keyword', ['length' => 68]);
120 $this->db->modifyTableColumn('settings', 'keyword', ['length' => 74]);
121
122 $this->db->renameTableColumn('udf_definition', 'field_id', 'old_field_id');
123 $this->db->manipulate('ALTER TABLE udf_definition ADD COLUMN field_id VARCHAR(64) NOT NULL FIRST');
124 $this->db->modifyTableColumn('udf_clob', 'field_id', ['type' => 'text', 'length' => 64]);
125 $this->db->modifyTableColumn('udf_text', 'field_id', ['type' => 'text', 'length' => 64]);
126 $fields_query = $this->db->query('SELECT old_field_id FROM udf_definition');
127 while (($row = $this->db->fetchObject($fields_query))) {
128 $uuid = $this->uuid_factory->uuid4AsString();
129 $this->db->manipulate(
130 "UPDATE udf_definition SET field_id = '{$uuid}' WHERE old_field_id = '{$row->old_field_id}'"
131 );
132 $this->db->manipulate(
133 "UPDATE udf_clob SET field_id = '{$uuid}' WHERE field_id = '{$row->old_field_id}'"
134 );
135 $this->db->manipulate(
136 "UPDATE udf_text SET field_id = '{$uuid}' WHERE field_id = '{$row->old_field_id}'"
137 );
138 $this->db->manipulate(
139 "UPDATE ldap_attribute_mapping SET keyword = 'udf_{$uuid}' WHERE keyword = 'udf_{$row->old_field_id}'"
140 );
141 $this->db->manipulate(
142 "UPDATE settings SET keyword = 'pmap_udf_{$uuid}' WHERE keyword = 'pmap_udf_{$row->old_field_id}'"
143 );
144 $this->db->manipulate(
145 "UPDATE settings SET keyword = 'pumap_udf_{$uuid}' WHERE keyword = 'pumap_udf_{$row->old_field_id}'"
146 );
147 }
148 $this->db->dropTableColumn('udf_definition', 'old_field_id');
149 $this->db->addPrimaryKey('udf_definition', ['field_id']);
150 $this->db->dropSequence('udf_definition');
151 }
152 }
153
154 public function step_4(): void
155 {
156 if ($this->db->tableExists('udf_text')) {
157 $this->db->manipulate('INSERT INTO usr_profile_data SELECT * FROM udf_text');
158 $this->db->dropTable('udf_text');
159 }
160
161 if ($this->db->tableExists('udf_clob')) {
162 $this->db->manipulate('INSERT INTO usr_profile_data SELECT * FROM udf_clob');
163 $this->db->dropTable('udf_clob');
164 }
165 }
166
167 public function step_5(): void
168 {
169 if (!$this->db->tableExists('usr_field_config')) {
170 $this->db->createTable(
171 'usr_field_config',
172 [
173 'field_id' => [
174 'type' => \ilDBConstants::T_TEXT,
175 'length' => 64,
176 'notnull' => true
177 ],
178 'visible_in_registration' => [
179 'type' => \ilDBConstants::T_INTEGER,
180 'length' => 1,
181 'notnull' => true
182 ],
183 'visible_to_user' => [
184 'type' => \ilDBConstants::T_INTEGER,
185 'length' => 1,
186 'notnull' => true
187 ],
188 'visible_in_lua' => [
189 'type' => \ilDBConstants::T_INTEGER,
190 'length' => 1,
191 'notnull' => true
192 ],
193 'visible_in_crss' => [
194 'type' => \ilDBConstants::T_INTEGER,
195 'length' => 1,
196 'notnull' => true
197 ],
198 'visible_in_grps' => [
199 'type' => \ilDBConstants::T_INTEGER,
200 'length' => 1,
201 'notnull' => true
202 ],
203 'visible_in_prgs' => [
204 'type' => \ilDBConstants::T_INTEGER,
205 'length' => 1,
206 'notnull' => true
207 ],
208 'changeable_by_user' => [
209 'type' => \ilDBConstants::T_INTEGER,
210 'length' => 1,
211 'notnull' => true
212 ],
213 'changeable_in_lua' => [
214 'type' => \ilDBConstants::T_INTEGER,
215 'length' => 1,
216 'notnull' => true
217 ],
218 'required' => [
219 'type' => \ilDBConstants::T_INTEGER,
220 'length' => 1,
221 'notnull' => true
222 ],
223 'export' => [
224 'type' => \ilDBConstants::T_INTEGER,
225 'length' => 1,
226 'notnull' => true
227 ],
228 'searchable' => [
229 'type' => \ilDBConstants::T_INTEGER,
230 'length' => 1,
231 'notnull' => true
232 ],
233 'available_in_certs' => [
234 'type' => \ilDBConstants::T_INTEGER,
235 'length' => 1,
236 'notnull' => true
237 ],
238 ]
239 );
240 $this->db->addPrimaryKey('usr_field_config', ['field_id']);
241 $this->db->insert(
242 'usr_field_config',
243 [
244 'field_id' => [\ilDBConstants::T_TEXT, 'location'],
245 'visible_in_registration' => [\ilDBConstants::T_INTEGER, 0],
246 'visible_to_user' => [\ilDBConstants::T_INTEGER, 1],
247 'visible_in_lua' => [\ilDBConstants::T_INTEGER, 0],
248 'visible_in_crss' => [\ilDBConstants::T_INTEGER, 0],
249 'visible_in_grps' => [\ilDBConstants::T_INTEGER, 0],
250 'visible_in_prgs' => [\ilDBConstants::T_INTEGER, 0],
251 'changeable_by_user' => [\ilDBConstants::T_INTEGER, 1],
252 'changeable_in_lua' => [\ilDBConstants::T_INTEGER, 0],
253 'required' => [\ilDBConstants::T_INTEGER, 0],
254 'export' => [\ilDBConstants::T_INTEGER, 0],
255 'searchable' => [\ilDBConstants::T_INTEGER, 0],
256 'available_in_certs' => [\ilDBConstants::T_INTEGER, 0]
257 ]
258 );
259 }
260 }
261
262 public function step_6(): void
263 {
264 $this->db->modifyTableColumn(
265 'udf_definition',
266 'field_type',
267 [
268 'type' => \ilDBConstants::T_TEXT,
269 'length' => 4000
270 ]
271 );
272 $this->db->update(
273 'udf_definition',
274 [
275 'field_type' => [
277 \ILIAS\User\Profile\Fields\Custom\Text::class
278 ]
279 ],
280 [
281 'field_type' => [
283 '1'
284 ]
285 ]
286 );
287 $this->db->update(
288 'udf_definition',
289 [
290 'field_type' => [
292 \ILIAS\User\Profile\Fields\Custom\Select::class
293 ]
294 ],
295 [
296 'field_type' => [
298 '2'
299 ]
300 ]
301 );
302 $this->db->update(
303 'udf_definition',
304 [
305 'field_type' => [
307 \ILIAS\User\Profile\Fields\Custom\TextArea::class
308 ]
309 ],
310 [
311 'field_type' => [
313 '3'
314 ]
315 ]
316 );
317 }
318
319 public function step_7(): void
320 {
321 if (!$this->db->tableColumnExists('udf_definition', 'section')) {
322 $this->db->addTableColumn(
323 'udf_definition',
324 'section',
325 [
326 'type' => \ilDBConstants::T_TEXT,
327 'length' => 64,
328 'notnull' => true,
329 'default' => AvailableSections::Other->value
330 ]
331 );
332 }
333 }
334
335 public function step_8(): void
336 {
337 if ($this->db->fetchObject(
338 $this->db->query(
339 'SELECT COUNT(*) cnt FROM settings WHERE module = "common"' . PHP_EOL
340 . 'AND keyword="usr_settings_changeable_by_user_new_mail_notification"'
341 )
342 )?->cnt <= 0
343 ) {
344 $this->db->manipulate(
345 'INSERT INTO settings (module, keyword, value) VALUES '
346 . '("common", "usr_settings_changeable_by_user_new_mail_notification", "1"), '
347 . '("common", "usr_settings_changeable_lua_new_mail_notification", "1"), '
348 . '("common", "usr_settings_export_new_mail_notification", "1")'
349 );
350 }
351
352 $renamed_fields = [
353 'hide_own_online_status' => 'awrn_user_show',
354 'bs_allow_to_contact_me' => 'allow_contact_request',
355 'mail_incoming_mail' => 'incoming_mail',
356 'skin_style' => 'style',
357 'upload' => 'avatar',
358 'sel_country' => 'selcountry',
359 'country' => 'old_country',
360 'selcountry' => 'country'
361 ];
362
363 foreach ($renamed_fields as $old_id => $new_id) {
364 $settings_query = $this->db->query(
365 "SELECT keyword FROM settings WHERE {$this->db->like('keyword', \ilDBConstants::T_TEXT, "%_{$old_id}")}"
366 );
367 while (($row = $this->db->fetchObject($settings_query)) !== null) {
368 if ($row->keyword === 'admin_country') {
369 continue;
370 }
371 $this->db->update(
372 'settings',
373 [
374 'keyword' => [
376 str_replace("_{$old_id}", "_{$new_id}", $row->keyword)
377 ]
378 ],
379 [
380 'module' => [
382 'common'
383 ],
384 'keyword' => [
386 $row->keyword
387 ]
388 ]
389 );
390 }
391
392 $user_query = $this->db->query(
393 "SELECT DISTINCT keyword FROM usr_pref WHERE {$this->db->like('keyword', \ilDBConstants::T_TEXT, "%_{$old_id}")}"
394 );
395 while (($row = $this->db->fetchObject($user_query)) !== null) {
396 $this->db->update(
397 'usr_pref',
398 [
399 'keyword' => [
401 str_replace("_{$old_id}", "_{$new_id}", $row->keyword)
402 ]
403 ],
404 [
405 'keyword' => [
407 $row->keyword
408 ]
409 ]
410 );
411 }
412 }
413 }
414
415 public function step_9(): void
416 {
417 $query = $this->db->query(
418 "SELECT usr_id, keyword FROM usr_pref WHERE {$this->db->like('keyword', \ilDBConstants::T_TEXT, 'public_udf_&')}"
419 );
420 while (($row = $this->db->fetchObject($query)) !== null) {
421 $this->db->update(
422 'usr_pref',
423 [
424 keyword => [
426 str_replace('public_udf_', 'public_', $row['keyword'])
427 ]
428 ],
429 [
430 'usr_id' => [
432 $row['usr_id']
433 ],
434 'keyword' => [
436 $row['keyword']
437 ]
438 ]
439 );
440 }
441 }
442
443 public function step_10(): void
444 {
445 if ($this->db->tableColumnExists('usr_data', 'time_limit_message')) {
446 $this->db->dropTableColumn('usr_data', 'time_limit_message');
447 }
448
449 if ($this->db->tableColumnExists('usr_data', 'sel_country')) {
450 $this->db->renameTableColumn('usr_data', 'country', 'old_country');
451 $this->db->renameTableColumn('usr_data', 'sel_country', 'country');
452 }
453 }
454
455 public function step_11(): void
456 {
457 $this->db->modifyTableColumn('usr_pref', 'keyword', ['length' => 74]);
458 }
459
460 public function step_12(): void
461 {
462 if ($this->db->fetchObject(
463 $this->db->query(
464 'SELECT COUNT(*) cnt FROM settings WHERE module = "common"' . PHP_EOL
465 . 'AND keyword="usr_settings_changeable_by_user_starting_point"'
466 )
467 )?->cnt <= 0
468 ) {
469 $this->db->update(
470 'settings',
471 [
472 'keyword' => [
474 'usr_settings_changeable_by_user_starting_point'
475 ]
476 ],
477 [
478 'module' => [
480 'common'
481 ],
482 'keyword' => [
484 'usr_starting_point_personal'
485 ]
486 ]
487 );
488 } else {
489 $this->db->manipulate(
490 'DELETE FROM settings WHERE module = "common" AND keyword= "usr_starting_point_personal"'
491 );
492 }
493
494 $this->insertSetting('usr_settings_changeable_lua_starting_point', '1');
495 $this->insertSetting('usr_settings_export_starting_point', '1');
496
497 foreach ([
498 'last_visited',
499 'timezone',
500 'date_format',
501 'time_format'
502 ] as $setting) {
503 $this->insertSetting("usr_settings_changeable_by_user_{$setting}", '1');
504 $this->insertSetting("usr_settings_changeable_lua_{$setting}", '1');
505 $this->insertSetting("usr_settings_export_{$setting}", '1');
506 }
507 }
508}
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
insertSetting(string $keyword, string $value)
ilSetting $setting
Definition: class.ilias.php:68
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
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))