ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailDatabaseUpdateSteps.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ilDBInterface $db;
24
25 public function prepare(ilDBInterface $db): void
26 {
27 $this->db = $db;
28 }
29
30 public function step_1(): void
31 {
32 if ($this->db->tableExists('mail') && $this->db->tableColumnExists('mail', 'm_email')) {
33 $this->db->dropTableColumn('mail', 'm_email');
34 }
35 }
36
37 public function step_2(): void
38 {
39 $result = $this->db->queryF('SELECT value FROM settings WHERE module = %s AND keyword = %s', ['text', 'text'], ['common', 'mail_system_sys_signature']);
40 $row = $this->db->fetchAssoc($result);
41 if (isset($row['value']) && $row['value'] !== '') {
42 $new_value = str_replace(['[CLIENT_NAME]', '[CLIENT_DESC]', '[CLIENT_URL]'], ['[INSTALLATION_NAME]', '[INSTALLATION_DESC]', '[ILIAS_URL]'], $row['value']);
43 if ($new_value !== $row['value']) {
44 $this->db->manipulateF(
45 'UPDATE settings SET value = %s WHERE module = %s AND keyword = %s',
46 ['text', 'text', 'text'],
47 [$new_value, 'common', 'mail_system_sys_signature']
48 );
49 }
50 }
51 }
52
53 public function step_3(): void
54 {
55 $result = $this->db->query("SELECT tpl_id, m_message FROM mail_man_tpl WHERE m_message LIKE '%[CLIENT_NAME]%'");
56 while ($row = $this->db->fetchAssoc($result)) {
57 if (isset($row['m_message'], $row['tpl_id']) && $row['m_message'] !== '' && $row['tpl_id'] !== '') {
58 $new_value = str_replace('[CLIENT_NAME]', '[INSTALLATION_NAME]', $row['m_message']);
59 if ($new_value !== $row['m_message']) {
60 $this->db->manipulateF(
61 'UPDATE mail_man_tpl SET m_message = %s WHERE tpl_id = %s',
62 ['text', 'text'],
63 [$new_value, $row['tpl_id']]
64 );
65 }
66 }
67 }
68 }
69
70 public function step_4(): void
71 {
72 $result = $this->db->query("SELECT lang, type, body FROM mail_template WHERE body LIKE '%[CLIENT_NAME]%'");
73 while ($row = $this->db->fetchAssoc($result)) {
74 if (isset($row['lang'], $row['type'], $row['body']) && $row['body'] !== '') {
75 $new_value = str_replace('[CLIENT_NAME]', '[INSTALLATION_NAME]', $row['body']);
76 if ($new_value !== $row['body']) {
77 $this->db->manipulateF(
78 'UPDATE mail_template SET body = %s WHERE lang = %s AND type = %s',
79 ['text', 'text', 'text'],
80 [$new_value, $row['lang'], $row['type']]
81 );
82 }
83 }
84 }
85 }
86
87 public function step_5(): void
88 {
89 if ($this->db->tableExists('mail_options') && $this->db->tableColumnExists('mail_options', 'linebreak')) {
90 $this->db->dropTableColumn('mail_options', 'linebreak');
91 }
92 }
93
94 public function step_6(): void
95 {
96 if (!$this->db->tableColumnExists('mail_options', 'absence_status')) {
97 $this->db->addTableColumn(
98 'mail_options',
99 'absence_status',
100 [
101 'type' => 'integer',
102 'length' => 1,
103 'notnull' => true,
104 'default' => 0
105 ]
106 );
107 }
108 }
109
110 public function step_7(): void
111 {
112 if (!$this->db->tableColumnExists('mail_options', 'absent_from')) {
113 $this->db->addTableColumn(
114 'mail_options',
115 'absent_from',
116 [
117 'type' => 'integer',
118 'length' => 8,
119 'notnull' => true,
120 'default' => 0
121 ]
122 );
123 }
124 }
125
126 public function step_8(): void
127 {
128 if (!$this->db->tableColumnExists('mail_options', 'absent_until')) {
129 $this->db->addTableColumn(
130 'mail_options',
131 'absent_until',
132 [
133 'type' => 'integer',
134 'length' => 8,
135 'notnull' => true,
136 'default' => 0
137 ]
138 );
139 }
140 }
141
142 public function step_9(): void
143 {
144 if (!$this->db->tableColumnExists('mail_options', 'absence_ar_body')) {
145 $this->db->addTableColumn(
146 'mail_options',
147 'absence_ar_body',
148 [
149 'type' => 'clob',
150 'notnull' => false,
151 'default' => null
152 ]
153 );
154 }
155 }
156
157 public function step_10(): void
158 {
159 if (!$this->db->tableColumnExists('mail_options', 'absence_ar_subject')) {
160 $this->db->addTableColumn(
161 'mail_options',
162 'absence_ar_subject',
163 [
164 'type' => 'text',
165 'length' => 255,
166 'notnull' => false,
167 'default' => null
168 ]
169 );
170 }
171 }
172
173 public function step_11(): void
174 {
175 if (!$this->db->tableExists('mail_auto_responder')) {
176 $this->db->createTable(
177 'mail_auto_responder',
178 [
179 'sender_id' => [
180 'type' => 'integer',
181 'length' => 8,
182 'notnull' => true
183 ],
184 'receiver_id' => [
185 'type' => 'integer',
186 'length' => 8,
187 'notnull' => true
188 ],
189 'sent_time' => [
190 'type' => 'timestamp',
191 'notnull' => true
192 ]
193 ]
194 );
195 $this->db->addPrimaryKey('mail_auto_responder', ['sender_id', 'receiver_id']);
196 }
197 }
198
199 public function step_12(): void
200 {
201 $settings = [
202 'mail_system_sys_signature',
203 'mail_system_usr_from_name',
204 ];
205
206 foreach ($settings as $keyword) {
207 $res = $this->db->queryF(
208 "SELECT value FROM settings WHERE keyword = %s AND value IS NOT NULL AND value != ''",
210 [$keyword]
211 );
212 if ($this->db->numRows($res) === 1) {
213 $value = $this->db->fetchAssoc($res)['value'] ?? '';
214 if ($value === '') {
215 return;
216 }
217
218 $value = preg_replace(
219 '/\[([A-Z_]+?)\]/',
220 '{{$1}}',
221 $value
222 );
223
224 $this->db->manipulateF(
225 'UPDATE settings SET value = %s WHERE keyword = %s',
227 [$value, $keyword]
228 );
229 }
230 }
231 }
232
233 public function step_13(): void
234 {
235 if ($this->db->tableExists("mail_tpl_ctx")) {
236 $query = "UPDATE mail_tpl_ctx SET " . PHP_EOL
237 . " component = REPLACE(component, 'Modules', 'components/ILIAS') " . PHP_EOL
238 . " WHERE component LIKE ('Modules/%')";
239
240 $this->db->manipulate($query);
241 }
242 }
243
244 public function step_14(): void
245 {
246 if ($this->db->tableExists("mail_tpl_ctx")) {
247 $query = "UPDATE mail_tpl_ctx SET " . PHP_EOL
248 . " path = REPLACE(path, 'Modules', 'components/ILIAS') " . PHP_EOL
249 . " WHERE component LIKE ('Modules/%')" . PHP_EOL
250 . " AND path IS NOT NULL";
251
252 $this->db->manipulate($query);
253 }
254 }
255
256 public function step_15(): void
257 {
258 $res = $this->db->queryF(
259 "SELECT value FROM settings WHERE keyword = %s AND value IS NOT NULL AND value != ''",
261 ['mail_system_sys_signature']
262 );
263 if ($this->db->numRows($res) === 1) {
264 $value = $this->db->fetchAssoc($res)['value'] ?? '';
265 $sys_general_signature = preg_replace('/(\s?\*\s?){2,}/', "\n\n-- \n", $value);
266 // replace [] with {{}}
267 $sys_general_signature = preg_replace('/\[([A-Z_]+?)\]/', '{{$1}}', $sys_general_signature);
268 $sys_general_signature = str_replace(
269 ['CLIENT_URL', 'CLIENT'],
270 ['ILIAS_URL', 'INSTALLATION'],
271 $sys_general_signature
272 );
273 $this->db->manipulateF(
274 'DELETE FROM settings WHERE keyword = %s',
276 ['mail_system_sys_signature']
277 );
278 }
279 $this->db->insert('settings', [
280 'module' => ['text', 'common'],
281 'keyword' => ['text', 'mail_system_sys_general_signature'],
282 'value' => [
283 'text',
284 $sys_general_signature ?? "\n\n-- \n{{INSTALLATION_NAME}}\n{{INSTALLATION_DESC}}\n{{ILIAS_URL}}\n"
285 ],
286 ]);
287 $this->db->insert('settings', [
288 'module' => ['text', 'common'],
289 'keyword' => ['text', 'mail_system_usr_general_signature'],
290 'value' => ['text', "\n\n-- \nThis mail was sent by {{USER_FULLNAME}} from {{INSTALLATION_NAME}}\n"],
291 ]);
292 }
293}
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69