ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.DBUpdateSteps8.php
Go to the documentation of this file.
1<?php
2
20
21use ILIAS\Setup;
22
24{
25 private \ilDBInterface $db;
26
27 public function prepare(\ilDBInterface $db): void
28 {
29 $this->db = $db;
30 }
31
32 public function step_1(): void
33 {
34 if ($this->db->tableColumnExists('adv_mdf_definition', 'field_values')) {
35 $field_infos = [
36 'type' => 'clob',
37 'notnull' => false,
38 'default' => null
39 ];
40 $this->db->modifyTableColumn('adv_mdf_definition', 'field_values', $field_infos);
41 }
42 }
43
44 public function step_2(): void
45 {
46 if (!$this->db->tableColumnExists('pg_amd_page_list', 'sdata')) {
47 $field_infos = [
48 'type' => 'clob',
49 'notnull' => false,
50 'default' => null
51 ];
52 $this->db->addTableColumn('pg_amd_page_list', 'sdata', $field_infos);
53 }
54 }
55
56 private function migrate(int $id, int $field_id, $data): void
57 {
58 $query = 'UPDATE pg_amd_page_list ' .
59 'SET sdata = ' . $this->db->quote(serialize(serialize($data)), \ilDBConstants::T_TEXT) . ' ' .
60 'WHERE id = ' . $this->db->quote($id, \ilDBConstants::T_INTEGER) . ' ' .
61 'AND field_id = ' . $this->db->quote($field_id, \ilDBConstants::T_INTEGER);
62 $this->db->manipulate($query);
63 }
64
65 private function migrateData(int $field_id, $data): array
66 {
67 if (!is_array($data)) {
68 return [];
69 }
70 $indexes = [];
71 foreach ($data as $idx => $value) {
72 $query = 'SELECT idx from adv_mdf_enum ' .
73 'WHERE value = ' . $this->db->quote($value, \ilDBConstants::T_TEXT) . ' ' .
74 'AND field_id = ' . $this->db->quote($field_id, \ilDBConstants::T_INTEGER);
75 $res = $this->db->query($query);
76
77 $found_index = false;
78 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
79 $indexes[] = (int) $row->idx;
80 $found_index = true;
81 }
82 if ($found_index) {
83 continue;
84 }
85 $query = 'SELECT idx from adv_mdf_enum ' .
86 'WHERE idx = ' . $this->db->quote($value, \ilDBConstants::T_TEXT) . ' ' .
87 'AND field_id = ' . $this->db->quote($field_id, \ilDBConstants::T_INTEGER);
88 $res = $this->db->query($query);
89 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
90 $indexes[] = (int) $row->idx;
91 }
92 }
93 return $indexes;
94 }
95
96
97
98 public function step_3(): void
99 {
100 $query = 'SELECT id, pg.field_id, data, field_type FROM pg_amd_page_list pg ' .
101 'JOIN adv_mdf_definition adv ' .
102 'ON pg.field_id = adv.field_id ' .
103 'WHERE sdata IS null ';
104 $res = $this->db->query($query);
105 while ($row = $res->fetchRow(\ilDBConstants::FETCHMODE_OBJECT)) {
106 if ($row->field_type == 1 || $row->field_type == 8) {
107 $this->migrate(
108 (int) $row->id,
109 (int) $row->field_id,
110 $this->migrateData(
111 (int) $row->field_id,
112 unserialize(unserialize($row->data))
113 )
114 );
115 } else {
116 $this->migrate(
117 (int) $row->id,
118 (int) $row->field_id,
119 unserialize(unserialize($row->data))
120 );
121 }
122 }
123 }
124
125 public function step_4(): void
126 {
127 $this->db->modifyTableColumn(
128 'adv_md_values_extlink',
129 'value',
130 [
131 'type' => 'text',
132 'length' => 2000,
133 'notnull' => false
134 ]
135 );
136 }
137}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.Agent.php:19
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...