ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDataCollectionDBUpdateSteps80.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  protected ilDBInterface $db;
22 
23  public function prepare(ilDBInterface $db): void
24  {
25  $this->db = $db;
26  }
27 
28  public function step_1(): void
29  {
30  $this->db->manipulate("UPDATE il_dcl_tableview " .
31  "SET description=" . $this->db->quote("", "text") .
32  "WHERE description is null");
33  $this->db->modifyTableColumn("il_dcl_tableview", "description", [ 'notnull' => true,
34  'default' => '']);
35  }
36 
37  public function step_2(): void
38  {
39  $this->db->manipulate("UPDATE il_dcl_tview_set " .
40  "SET in_filter=0 " .
41  "WHERE in_filter is null");
42  $this->db->manipulate("UPDATE il_dcl_tview_set " .
43  "SET visible=0 " .
44  "WHERE visible is null");
45  $this->db->manipulate("UPDATE il_dcl_tview_set " .
46  "SET filter_changeable=0 " .
47  "WHERE filter_changeable is null");
48  $this->db->modifyTableColumn("il_dcl_tview_set", "in_filter", [ 'notnull' => true,
49  'default' => 0]);
50  $this->db->modifyTableColumn("il_dcl_tview_set", "visible", [ 'notnull' => true,
51  'default' => 0]);
52  $this->db->modifyTableColumn("il_dcl_tview_set", "filter_changeable", [ 'notnull' => true,
53  'default' => 0]);
54  }
55 
56  public function step_3(): void
57  {
58  $this->db->manipulate("UPDATE il_dcl_tfield_set " .
59  "SET exportable=0 " .
60  "WHERE exportable is null");
61  $this->db->modifyTableColumn("il_dcl_tfield_set", "exportable", [ 'notnull' => true,
62  'default' => 0]);
63  }
64 
65  public function step_4(): void
66  {
67  $this->db->modifyTableColumn("il_dcl_stloc3_value", "value", [ 'notnull' => false]);
68  }
69 
70  public function step_5(): void
71  {
72  if (!$this->db->indexExistsByFields('il_dcl_field_prop', array('id', 'field_id'))) {
73  $this->db->addIndex('il_dcl_field_prop', array('id', 'field_id'), 'i1');
74  }
75  if (!$this->db->indexExistsByFields('il_dcl_tview_set', array('tableview_id'))) {
76  $this->db->addIndex('il_dcl_tview_set', array('tableview_id'), 'i1');
77  }
78  }
79 
80  public function step_6(): void
81  {
82  $this->db->modifyTableColumn(
83  'il_dcl_sel_opts',
84  'value',
85  [
86  "length" => 4000,
87  ]
88  );
89  }
90 
91  public function step_7(): void
92  {
93  if (!$this->db->indexExistsByFields('il_dcl_field_prop', array('field_id'))) {
94  $this->db->addIndex('il_dcl_field_prop', array('field_id'), 'i2');
95  }
96  if (!$this->db->indexExistsByFields('il_dcl_sel_opts', array('field_id'))) {
97  $this->db->addIndex('il_dcl_sel_opts', array('field_id'), 'i1');
98  }
99  if (!$this->db->indexExistsByFields('il_dcl_sel_opts', array('opt_id'))) {
100  $this->db->addIndex('il_dcl_sel_opts', array('opt_id'), 'i2');
101  }
102  if (!$this->db->indexExistsByFields('il_dcl_tview_set', array('field'))) {
103  $this->db->addIndex('il_dcl_tview_set', array('field'), 'i2');
104  }
105  if (!$this->db->indexExistsByFields('il_dcl_tview_set', array('in_filter'))) {
106  $this->db->addIndex('il_dcl_tview_set', array('in_filter'), 'i3');
107  }
108  if (!$this->db->indexExistsByFields('il_dcl_tfield_set', array('field'))) {
109  $this->db->addIndex('il_dcl_tfield_set', array('field'), 'i3');
110  }
111  if (!$this->db->indexExistsByFields('il_dcl_tfield_set', array('table_id'))) {
112  $this->db->addIndex('il_dcl_tfield_set', array('table_id'), 'i4');
113  }
114  }
115 
116  public function step_8(): void
117  {
118  $this->db->manipulateF(
119  'UPDATE il_dcl_field_prop prop INNER JOIN il_dcl_field field ON field.id = prop.field_id ' .
120  'SET name = "link_detail_page_text" WHERE field.datatype_id = %s AND name = "link_detail_page"',
123  );
124  $this->db->manipulateF(
125  'UPDATE il_dcl_field_prop prop INNER JOIN il_dcl_field field ON field.id = prop.field_id ' .
126  'SET name = "link_detail_page_mob" WHERE field.datatype_id = %s AND name = "link_detail_page"',
129  );
130  }
131 
132  public function step_9(): void
133  {
134  $this->db->manipulateF(
135  'UPDATE il_dcl_stloc1_value v ' .
136  'INNER JOIN il_dcl_record_field rf ON rf.id = v.record_field_id ' .
137  'INNER JOIN il_dcl_field f ON f.id = rf.field_id ' .
138  'SET v.value = REPLACE(v.value, "<br />", "\r\n") WHERE f.datatype_id = %s',
141  );
142  }
143 
144  public function step_10(): void
145  {
146  $this->db->manipulate('UPDATE il_dcl_field_prop SET value = "" WHERE value IS NULL');
147  }
148 
149  public function step_11(): void
150  {
151  if ($this->db->tableExists('il_dcl_field_prop_b')) {
152  $this->db->dropTable('il_dcl_field_prop_b');
153  }
154 
155  if ($this->db->tableExists('il_dcl_field_prop_s_b')) {
156  $this->db->dropTable('il_dcl_field_prop_s_b');
157  }
158  }
159 
160  public function step_12(): void
161  {
162  global $DIC;
163  $slot = $DIC['component.repository']->getPluginSlotById(ilDclFieldTypePlugin::SLOT_ID);
164  foreach ($slot->getPlugins() as $plugin) {
165  $plugin = $DIC['component.factory']->getPlugin($plugin->getId());
166  $field_type_name = ilDclFieldTypePlugin::getDataType($plugin->getId());
167 
168  $field_ids = [];
169  $stmt = $this->db->queryF(
170  'SELECT field_id FROM il_dcl_field_prop WHERE name = "plugin_hook_name" AND value = %s',
172  [$plugin->getPluginName()]
173  );
174  while ($row = $this->db->fetchAssoc($stmt)) {
175  $field_ids[] = (int) $row['field_id'];
176  }
177 
178  $id = 0;
179  $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE title LIKE %s', [ilDBConstants::T_TEXT], [$field_type_name]);
180  while ($row = $this->db->fetchAssoc($stmt)) {
181  $id = (int) $row['id'];
182  }
183  if ($id === 0) {
184  $type = $plugin->getStorageLocation();
185  $field_model_class = 'il' . $plugin->getPluginName() . 'FieldModel';
186  $type = (new $field_model_class())->getStorageLocationOverride() ?? $plugin->getStorageLocation();
187 
188  $this->db->manipulateF(
189  '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;',
190  [
194  ],
195  [
196  $field_type_name,
198  $type
199  ]
200  );
201  $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE title LIKE %s', [ilDBConstants::T_TEXT], [$field_type_name]);
202  $id = (int) $this->db->fetchAssoc($stmt)['id'];
203  }
204 
205  foreach ($field_ids as $field_id) {
206  $this->db->manipulateF(
207  'UPDATE il_dcl_field SET datatype_id = %s WHERE id = %s',
209  [$id, $field_id]
210  );
211  }
212 
213  $this->db->manipulateF(
214  'DELETE FROM il_dcl_field_prop WHERE name = "plugin_hook_name" AND value = %s',
216  [$plugin->getPluginName()]
217  );
218  }
219  $this->db->manipulateF(
220  'DELETE FROM il_dcl_datatype WHERE id = %s',
223  );
224  }
225 
226  public function step_13(): void
227  {
228  $id = false;
229  $stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE id LIKE %s', [ilDBConstants::T_INTEGER], [17]);
230  if ($row = $this->db->fetchAssoc($stmt)) {
231  $id = true;
232  }
233 
234  if (!$id) {
235  $this->db->insert(
236  'il_dcl_datatype',
237  [
238  'id' => [ilDBConstants::T_INTEGER, 17],
239  'title' => [ilDBConstants::T_TEXT, 'copy'],
241  'storage_location' => [ilDBConstants::T_INTEGER, 1],
242  'sort' => [ilDBConstants::T_INTEGER, 85],
243  ]
244  );
245  }
246  }
247 }
$type
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getDataType(string $plugin_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...