ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDataCollectionDBUpdateSteps9.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 $this->db->manipulate(
33 "UPDATE il_dcl_tableview " .
34 "SET description=" . $this->db->quote("", "text") .
35 "WHERE description is null"
36 );
37 $this->db->modifyTableColumn("il_dcl_tableview", "description", [
38 'notnull' => true,
39 'default' => ''
40 ]);
41 }
42
43 public function step_2(): void
44 {
45 $this->db->manipulate(
46 "UPDATE il_dcl_tview_set " .
47 "SET in_filter=0 " .
48 "WHERE in_filter is null"
49 );
50 $this->db->manipulate(
51 "UPDATE il_dcl_tview_set " .
52 "SET visible=0 " .
53 "WHERE visible is null"
54 );
55 $this->db->manipulate(
56 "UPDATE il_dcl_tview_set " .
57 "SET filter_changeable=0 " .
58 "WHERE filter_changeable is null"
59 );
60 $this->db->modifyTableColumn("il_dcl_tview_set", "in_filter", [
61 'notnull' => 1,
62 'default' => 0
63 ]);
64 $this->db->modifyTableColumn("il_dcl_tview_set", "visible", [
65 'notnull' => 1,
66 'default' => 0
67 ]);
68 $this->db->modifyTableColumn("il_dcl_tview_set", "filter_changeable", [
69 'notnull' => 1,
70 'default' => 0
71 ]);
72 }
73
74 public function step_3(): void
75 {
76 $this->db->manipulate(
77 "UPDATE il_dcl_tfield_set " .
78 "SET exportable=0 " .
79 "WHERE exportable is null"
80 );
81 $this->db->modifyTableColumn("il_dcl_tfield_set", "exportable", [
82 'notnull' => 1,
83 'default' => 0
84 ]);
85 }
86
87 public function step_4(): void
88 {
89 $this->db->modifyTableColumn("il_dcl_stloc3_value", "value", ['notnull' => false]);
90 }
91
92 public function step_5(): void
93 {
94 if (!$this->db->indexExistsByFields('il_dcl_field_prop', ['id', 'field_id'])) {
95 $this->db->addIndex('il_dcl_field_prop', ['id', 'field_id'], 'i1');
96 }
97 if (!$this->db->indexExistsByFields('il_dcl_tview_set', ['tableview_id'])) {
98 $this->db->addIndex('il_dcl_tview_set', ['tableview_id'], 'i1');
99 }
100 }
101
102 public function step_6(): void
103 {
104 $this->db->insert("il_dcl_datatype", [
106 'title' => [ilDBConstants::T_TEXT, 'file'],
108 'storage_location' => [ilDBConstants::T_INTEGER, 1],
109 'sort' => [ilDBConstants::T_INTEGER, 75],
110 ]);
111 }
112
113 public function step_7(): void
114 {
115 $this->db->manipulateF(
116 "DELETE FROM il_dcl_datatype WHERE id = %s",
118 [defined(ilDclDatatype::class . '::INPUTFORMAT_FILEUPLOAD') ? ilDclDatatype::INPUTFORMAT_FILEUPLOAD : 6]
119 );
120 }
121
122 public function step_8(): void
123 {
124 $this->db->modifyTableColumn(
125 'il_dcl_sel_opts',
126 'value',
127 [
128 "length" => 4000,
129 ]
130 );
131 }
132
133 public function step_9(): void
134 {
135 $this->db->manipulate(
136 "UPDATE il_dcl_field_prop, il_dcl_field
137 SET name='link_detail_page_text'
138 WHERE name='link_detail_page'
139 AND il_dcl_field_prop.field_id=il_dcl_field.id
140 AND il_dcl_field.datatype_id=2"
141 );
142 }
143
144 public function step_10(): void
145 {
146 if (!$this->db->indexExistsByFields('il_dcl_field_prop', array('field_id'))) {
147 $this->db->addIndex('il_dcl_field_prop', array('field_id'), 'i2');
148 }
149 if (!$this->db->indexExistsByFields('il_dcl_sel_opts', array('field_id'))) {
150 $this->db->addIndex('il_dcl_sel_opts', array('field_id'), 'i1');
151 }
152 if (!$this->db->indexExistsByFields('il_dcl_sel_opts', array('opt_id'))) {
153 $this->db->addIndex('il_dcl_sel_opts', array('opt_id'), 'i2');
154 }
155 if (!$this->db->indexExistsByFields('il_dcl_tview_set', array('field'))) {
156 $this->db->addIndex('il_dcl_tview_set', array('field'), 'i2');
157 }
158 if (!$this->db->indexExistsByFields('il_dcl_tview_set', array('in_filter'))) {
159 $this->db->addIndex('il_dcl_tview_set', array('in_filter'), 'i3');
160 }
161 if (!$this->db->indexExistsByFields('il_dcl_tfield_set', array('field'))) {
162 $this->db->addIndex('il_dcl_tfield_set', array('field'), 'i3');
163 }
164 if (!$this->db->indexExistsByFields('il_dcl_tfield_set', array('table_id'))) {
165 $this->db->addIndex('il_dcl_tfield_set', array('table_id'), 'i4');
166 }
167 }
168
169 public function step_11(): void
170 {
171 $this->db->manipulateF(
172 'UPDATE il_dcl_field_prop prop INNER JOIN il_dcl_field field ON field.id = prop.field_id ' .
173 'SET name = "link_detail_page_mob" WHERE field.datatype_id = %s AND name = "link_detail_page"',
176 );
177 }
178
179 public function step_12(): void
180 {
181 $this->db->manipulateF(
182 'UPDATE il_dcl_stloc1_value v ' .
183 'INNER JOIN il_dcl_record_field rf ON rf.id = v.record_field_id ' .
184 'INNER JOIN il_dcl_field f ON f.id = rf.field_id ' .
185 'SET v.value = REPLACE(v.value, "<br />", "\r\n") WHERE f.datatype_id = %s',
188 );
189 }
190
191 public function step_13(): void
192 {
193 if ($this->db->tableColumnExists('il_dcl_tableview', 'step_vs')) {
194 $this->db->dropTableColumn('il_dcl_tableview', 'step_vs');
195 }
196 if ($this->db->tableColumnExists('il_dcl_tableview', 'step_c')) {
197 $this->db->dropTableColumn('il_dcl_tableview', 'step_c');
198 }
199 if ($this->db->tableColumnExists('il_dcl_tableview', 'step_e')) {
200 $this->db->dropTableColumn('il_dcl_tableview', 'step_e');
201 }
202 if ($this->db->tableColumnExists('il_dcl_tableview', 'step_o')) {
203 $this->db->dropTableColumn('il_dcl_tableview', 'step_o');
204 }
205 if ($this->db->tableColumnExists('il_dcl_tableview', 'step_s')) {
206 $this->db->dropTableColumn('il_dcl_tableview', 'step_s');
207 }
208 }
209
210 public function step_14(): void
211 {
212 $this->db->manipulate('UPDATE il_dcl_field_prop SET value = "" WHERE value IS NULL');
213 }
214
215 public function step_15(): void
216 {
217 if ($this->db->tableExists('il_dcl_field_prop_b')) {
218 $this->db->dropTable('il_dcl_field_prop_b');
219 }
220
221 if ($this->db->tableExists('il_dcl_field_prop_s_b')) {
222 $this->db->dropTable('il_dcl_field_prop_s_b');
223 }
224 }
225
226 public function step_16(): void
227 {
228 global $DIC;
229 $slot = $DIC['component.repository']->getPluginSlotById(ilDclFieldTypePlugin::SLOT_ID);
230 foreach ($slot->getPlugins() as $plugin) {
231 $plugin = $DIC['component.factory']->getPlugin($plugin->getId());
232 $field_type_name = ilDclFieldTypePlugin::getDataType($plugin->getId());
233
234 $field_ids = [];
235 $stmt = $this->db->queryF(
236 'SELECT field_id FROM il_dcl_field_prop WHERE name = "plugin_hook_name" AND value = %s',
238 [$plugin->getPluginName()]
239 );
240 while ($row = $this->db->fetchAssoc($stmt)) {
241 $field_ids[] = (int) $row['field_id'];
242 }
243
244 $id = 0;
245 $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE title LIKE %s', [ilDBConstants::T_TEXT], [$field_type_name]);
246 while ($row = $this->db->fetchAssoc($stmt)) {
247 $id = (int) $row['id'];
248 }
249 if ($id === 0) {
250 $type = $plugin->getStorageLocation();
251 $field_model_class = 'il' . $plugin->getPluginName() . 'FieldModel';
252 $type = (new $field_model_class())->getStorageLocationOverride() ?? $plugin->getStorageLocation();
253
254 $this->db->manipulateF(
255 'INSERT INTO il_dcl_datatype (id, title, ildb_type, storage_location, sort) SELECT GREATEST(MAX(id), 1000) + 1, %s, %s, %s, GREATEST(MAX(sort), 10000) + 10 FROM il_dcl_datatype;',
256 [
260 ],
261 [
262 $field_type_name,
264 $type
265 ]
266 );
267 $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE title LIKE %s', [ilDBConstants::T_TEXT], [$field_type_name]);
268 $id = (int) $this->db->fetchAssoc($stmt)['id'];
269 }
270
271 foreach ($field_ids as $field_id) {
272 $this->db->manipulateF(
273 'UPDATE il_dcl_field SET datatype_id = %s WHERE id = %s',
275 [$id, $field_id]
276 );
277 }
278
279 $this->db->manipulateF(
280 'DELETE FROM il_dcl_field_prop WHERE name = "plugin_hook_name" AND value = %s',
282 [$plugin->getPluginName()]
283 );
284 }
285 $this->db->manipulateF(
286 'DELETE FROM il_dcl_datatype WHERE id = %s',
288 [12]
289 );
290 }
291
292 public function step_17(): void
293 {
294 $id = false;
295 $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE id LIKE %s', [ilDBConstants::T_INTEGER], [ilDclDatatype::INPUTFORMAT_COPY]);
296 if ($row = $this->db->fetchAssoc($stmt)) {
297 $id = true;
298 }
299
300 if (!$id) {
301 $this->db->insert(
302 'il_dcl_datatype',
303 [
305 'title' => [ilDBConstants::T_TEXT, 'copy'],
307 'storage_location' => [ilDBConstants::T_INTEGER, 1],
308 'sort' => [ilDBConstants::T_INTEGER, 85],
309 ]
310 );
311 }
312 }
313
314 public function step_18(): void
315 {
316 $stmt = $this->db->queryF(
317 'SELECT * FROM page_object INNER JOIN il_dcl_tableview ON page_id = id WHERE rendered_content IS NOT NULL AND parent_type = %s',
320 );
321
322 while ($row = $this->db->fetchAssoc($stmt)) {
323 $tableview = new ilDclTableView((int) $row['page_id']);
324 $content = $row['content'];
325 $rendered_content = $row['rendered_content'];
326
327 foreach (['id', 'create_date', 'last_update', 'owner', 'last_edit_by'] as $field) {
328 $content = str_replace('[' . $field . ']', '[[' . $field . ']]', $content);
329 $content = str_replace('[[[' . $field . ']]]', '[[' . $field . ']]', $content);
330 $rendered_content = str_replace('[' . $field . ']', '[[' . $field . ']]', $rendered_content);
331 $rendered_content = str_replace('[[[' . $field . ']]]', '[[' . $field . ']]', $rendered_content);
332 }
333
334 $sub_stmt = $this->db->queryF(
335 'SELECT * FROM il_dcl_field WHERE table_id = %s',
337 [(int) $row['table_id']]
338 );
339 while ($field = $this->db->fetchAssoc($sub_stmt)) {
340 $old = ['[' . $field['title'] . ']','[dclrefln field="' . $field['title'] . '"][/dclrefln]' ];
341 $content = str_replace($old, '[[' . $field['id'] . ']]', $content);
342 $rendered_content = str_replace($old, '[[' . $field['id'] . ']]', $rendered_content);
343 }
344
345 $this->db->manipulateF(
346 'UPDATE page_object SET content = %s, rendered_content = %s WHERE page_id = %s',
348 [$content, $rendered_content, (int) $row['page_id']]
349 );
350 }
351 }
352
353 public function step_19(): void
354 {
355 if ($this->db->tableColumnExists('il_dcl_datatype', 'ildb_type')) {
356 $this->db->dropTableColumn('il_dcl_datatype', 'ildb_type');
357 }
358 }
359
360 public function step_20(): void
361 {
362 $stmt = $this->db->queryF(
363 'SELECT id FROM il_dcl_datatype WHERE id = %s AND title = %s',
366 );
367 if ($this->db->fetchAssoc($stmt) === null) {
368 $this->db->manipulateF(
369 'UPDATE il_dcl_datatype SET title = %s WHERE id = %s',
372 );
373 }
374 }
375}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getDataType(string $plugin_id)
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26