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{
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 $this->db->dropTable('chatroom_prooms', false);
39 $this->db->dropTable('chatroom_proomaccess', false);
40 $this->db->dropTable('chatroom_psessions', false);
41
42 $this->dropColumnWhenExists('chatroom_history', 'sub_room');
43 $this->dropColumnWhenExists('chatroom_settings', 'allow_private_rooms');
44 $this->dropColumnWhenExists('chatroom_settings', 'private_rooms_enabled');
45 }
46
47 public function step_2(): void
48 {
49 $this->dropTableWhenExists('chatroom_smilies');
50 }
51
52 public function step_3(): void
53 {
54 $this->dropColumnWhenExists('chatroom_settings', 'restrict_history');
55 }
56
57 public function step_4(): void
58 {
59 $query = '
60 UPDATE object_data
61 INNER JOIN chatroom_settings ON object_data.obj_id = chatroom_settings.object_id
62 SET object_data.offline = IF(chatroom_settings.online_status = 1, 0, 1)
63 WHERE object_data.type = %s
64 ';
65
66 $this->db->manipulateF(
67 $query,
69 ['chtr']
70 );
71 }
72
73 public function step_5(): void
74 {
75 $this->dropTableWhenExists('chatroom_uploads');
76 $this->db->manipulate('DELETE FROM chatroom_bans WHERE user_id NOT IN (SELECT usr_id FROM usr_data)');
77 }
78
79 public function step_6(): void
80 {
81 $replace = [
82 '&lt;' => '<',
83 '&gt;' => '>',
84 '&amp;' => '&',
85 '&quot;' => '"',
86 ];
87
88 $s = 'JSON_VALUE(message, "$.content")';
89 foreach ($replace as $from => $to) {
90 $s = sprintf('REPLACE(%s, %s, %s)', $s, $this->db->quote($from, ilDBConstants::T_TEXT), $this->db->quote($to, ilDBConstants::T_TEXT));
91 }
92
93 $this->db->manipulate(
94 'UPDATE chatroom_history SET message = JSON_SET(message, "$.content", ' . $s . ') ' .
95 'WHERE JSON_VALID(message) = 1 AND JSON_VALUE(message, "$.type") = ' . $this->db->quote('message', ilDBConstants::T_TEXT)
96 );
97 }
98
99 private function dropColumnWhenExists(string $table, string $column): void
100 {
101 if ($this->db->tableColumnExists($table, $column)) {
102 $this->db->dropTableColumn($table, $column);
103 }
104 }
105
106 private function dropTableWhenExists(string $table): void
107 {
108 if ($this->db->tableExists($table)) {
109 $this->db->dropTable($table);
110 }
111 }
112}
dropColumnWhenExists(string $table, string $column)
Definition: UpdateSteps.php:99
Class ilDBConstants.
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...