ILIAS  release_8 Revision v8.24
class.ilStyleDBUpdateSteps.php
Go to the documentation of this file.
1<?php
2
17
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('style_char_title')) {
33 $fields = [
34 'type' => [
35 'type' => 'text',
36 'length' => 30,
37 'notnull' => true
38 ],
39 'characteristic' => [
40 'type' => 'text',
41 'length' => 30,
42 'notnull' => true
43 ],
44 'lang' => [
45 'type' => 'text',
46 'length' => 2,
47 'notnull' => true
48 ],
49 'title' => [
50 'type' => 'text',
51 'length' => 200,
52 'notnull' => false
53 ]
54 ];
55
56 $this->db->createTable('style_char_title', $fields);
57 $this->db->addPrimaryKey('style_char_title', ['type', 'characteristic', 'lang']);
58 }
59 }
60
61 public function step_2()
62 {
63 $this->db->dropPrimaryKey('style_char_title');
64 if (!$this->db->tableColumnExists('style_char_title', 'style_id')) {
65 $this->db->addTableColumn('style_char_title', 'style_id', array(
66 "type" => "integer",
67 "notnull" => true,
68 "length" => 4
69 ));
70 }
71 $this->db->addPrimaryKey('style_char_title', ['style_id', 'type', 'characteristic', 'lang']);
72 }
73
74 public function step_3()
75 {
76 if (!$this->db->tableColumnExists('style_char', 'order_nr')) {
77 $this->db->addTableColumn('style_char', 'order_nr', array(
78 "type" => "integer",
79 "notnull" => true,
80 "length" => 4,
81 "default" => 0
82 ));
83 }
84 }
85
86 public function step_4()
87 {
88 if (!$this->db->tableColumnExists('style_char', 'deprecated')) {
89 $this->db->addTableColumn('style_char', 'deprecated', array(
90 "type" => "integer",
91 "notnull" => true,
92 "length" => 1,
93 "default" => 0
94 ));
95 }
96 }
97
98 public function step_5()
99 {
100 $this->db->renameTableColumn('style_char', "deprecated", 'outdated');
101 }
102
103 public function step_6()
104 {
105 if (!$this->db->tableExists('sty_rep_container')) {
106 $fields = [
107 'ref_id' => [
108 'type' => 'integer',
109 'length' => 4,
110 'notnull' => true,
111 'default' => 0
112 ],
113 'reuse' => [
114 'type' => 'integer',
115 'length' => 1,
116 'notnull' => true,
117 'default' => 0
118 ]
119 ];
120
121 $this->db->createTable('sty_rep_container', $fields);
122 $this->db->addPrimaryKey('sty_rep_container', ['ref_id']);
123 }
124 }
125
126 public function step_7()
127 {
128 $set = $this->db->queryF(
129 "SELECT * FROM content_object ",
130 [],
131 []
132 );
133 while ($rec = $this->db->fetchAssoc($set)) {
134 $this->db->replace(
135 "style_usage",
136 array(
137 "obj_id" => array("integer", (int) $rec["id"])
138 ),
139 array(
140 "style_id" => array("integer", (int) $rec["stylesheet"])
141 )
142 );
143 }
144 }
145
146 public function step_8()
147 {
148 $set = $this->db->queryF(
149 "SELECT * FROM content_page_data ",
150 [],
151 []
152 );
153 while ($rec = $this->db->fetchAssoc($set)) {
154 $this->db->replace(
155 "style_usage",
156 array(
157 "obj_id" => array("integer", (int) $rec["content_page_id"])),
158 array(
159 "style_id" => array("integer", (int) $rec["stylesheet"]))
160 );
161 }
162 }
163
164 public function step_9()
165 {
166 if (!$this->db->tableColumnExists('style_data', 'owner_obj')) {
167 $this->db->addTableColumn('style_data', 'owner_obj', array(
168 'type' => 'integer',
169 'notnull' => false,
170 'length' => 4,
171 'default' => 0
172 ));
173 }
174 }
175
176 public function step_10()
177 {
178 $set = $this->db->queryF(
179 "SELECT * FROM style_data WHERE standard = %s",
180 ["integer"],
181 [0]
182 );
183 while ($rec = $this->db->fetchAssoc($set)) {
184 $set2 = $this->db->queryF(
185 "SELECT * FROM style_usage " .
186 " WHERE style_id = %s ",
187 ["integer"],
188 [$rec["id"]]
189 );
190 while ($rec2 = $this->db->fetchAssoc($set2)) {
191 $this->db->update(
192 "style_data",
193 [
194 "owner_obj" => ["integer", $rec2["obj_id"]]
195 ],
196 [ // where
197 "id" => ["integer", $rec["id"]]
198 ]
199 );
200 }
201 }
202 }
203
204 public function step_11()
205 {
206 // Add new index
207 if (!$this->db->indexExistsByFields('style_template', ['style_id'])) {
208 $this->db->addIndex('style_template', ['style_id'], 'i1');
209 }
210 }
211
212 public function step_12()
213 {
214 // Add new index
215 if (!$this->db->indexExistsByFields('style_usage', array('style_id'))) {
216 $this->db->addIndex('style_usage', array('style_id'), 'i1');
217 }
218 }
219}
prepare(\ilDBInterface $db)
Prepare the execution of the steps.
return true
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...