Commit | Line | Data |
---|---|---|
b325120a | 1 | <?php |
fbbb74fb DO |
2 | |
3 | // At the moment we assume, that for any two releases we can | |
4 | // sequentally execute all batches, that separate them, and | |
5 | // nothing will break. If this changes one day, the function | |
6 | // below will have to generate smarter upgrade paths, while | |
7 | // the upper layer will remain the same. | |
8 | // Returning an empty array means that no upgrade is necessary. | |
9 | function getDBUpgradePath ($v1, $v2) | |
10 | { | |
a6f83a72 DO |
11 | $versionhistory = array |
12 | ( | |
13 | '0.14.4', | |
14 | '0.14.5', | |
15 | '0.14.6', | |
16 | '0.14.7', | |
17 | '0.14.8', | |
18 | '0.14.9', | |
2ff234d6 DO |
19 | '0.14.10', |
20 | '0.14.11' | |
a6f83a72 | 21 | ); |
fbbb74fb DO |
22 | if (!in_array ($v1, $versionhistory) || !in_array ($v2, $versionhistory)) |
23 | { | |
24 | showError ("An upgrade path has been requested for versions '${v1}' and '${v2}', " . | |
25 | "and at least one of those isn't known to me."); | |
26 | die; | |
27 | } | |
28 | $skip = TRUE; | |
29 | $path = array(); | |
30 | // Now collect all versions > $v1 and <= $v2 | |
31 | foreach ($versionhistory as $v) | |
32 | { | |
33 | if ($v == $v1) | |
34 | { | |
35 | $skip = FALSE; | |
36 | continue; | |
37 | } | |
38 | if ($skip) | |
39 | continue; | |
40 | $path[] = $v; | |
41 | if ($v == $v2) | |
42 | break; | |
43 | } | |
44 | return $path; | |
45 | } | |
46 | ||
47 | // Upgrade batches are name exactly as the release where they first appear. | |
48 | // That simple, but seems sufficient for beginning. | |
49 | function executeUpgradeBatch ($batchid) | |
50 | { | |
51 | $query = array(); | |
ce109ff2 | 52 | global $dbxlink; |
fbbb74fb DO |
53 | switch ($batchid) |
54 | { | |
55 | case '0.14.5': | |
56 | // We can't realiably distinguish between 0.14.4 and 0.14.5, but | |
57 | // luckily the SQL statements below can be safely executed for both. | |
58 | ||
59 | ||
60 | // This has to be checked once more to be sure IPAddress allocation | |
61 | // conventions are correct. | |
62 | $query[] = "delete from IPAddress where name = '' and reserved = 'no'"; | |
63 | ||
64 | // In the 0.14.4 release we had AUTO_INCREMENT low in the dictionary and auth | |
65 | // data tables, thus causing new user's data to take primary keys equal to | |
66 | // the values of shipped data in future releases. Let's shift user's data | |
67 | // up and keep DB consistent. | |
68 | $query[] = "alter table Attribute AUTO_INCREMENT = 10000"; | |
69 | $query[] = "alter table Chapter AUTO_INCREMENT = 10000"; | |
70 | $query[] = "alter table Dictionary AUTO_INCREMENT = 10000"; | |
71 | $query[] = "alter table UserAccount AUTO_INCREMENT = 10000"; | |
72 | $query[] = "update UserAccount set user_id = user_id + 10000 where user_id between 2 and 10000"; | |
73 | $query[] = "update UserPermission set user_id = user_id + 10000 where user_id between 2 and 10000"; | |
74 | $query[] = "update Attribute set attr_id = attr_id + 10000 where attr_id between 25 and 10000"; | |
75 | $query[] = "update AttributeMap set attr_id = attr_id + 10000 where attr_id between 25 and 10000"; | |
76 | $query[] = "update Chapter set chapter_no = chapter_no + 10000 where chapter_no between 21 and 10000"; | |
77 | $query[] = "update AttributeMap set chapter_no = chapter_no + 10000 where chapter_no between 21 and 10000"; | |
78 | break; // -------------------------------------------- | |
79 | case '0.14.6': | |
80 | // This version features new dictionary entries, the correction above should allow us | |
81 | // inject them w/o a problem. | |
82 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,25,'FreeBSD 1.x')"; | |
83 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,26,'FreeBSD 2.x')"; | |
84 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,27,'FreeBSD 3.x')"; | |
85 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,28,'FreeBSD 4.x')"; | |
86 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,29,'FreeBSD 5.x')"; | |
87 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,30,'FreeBSD 6.x')"; | |
88 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,31,'RHFC8')"; | |
89 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (13,32,'ALTLinux Master 4.0')"; | |
90 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (20,20)"; | |
91 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (21,21)"; | |
92 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (22,22)"; | |
93 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (23,23)"; | |
94 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (24,24)"; | |
95 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (25,25)"; | |
96 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (26,26)"; | |
97 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (27,27)"; | |
98 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (28,28)"; | |
99 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,20,'KVM')"; | |
100 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,21,'1000Base-ZX')"; | |
101 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,22,'10GBase-ER')"; | |
102 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,23,'10GBase-LR')"; | |
103 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,24,'10GBase-LRM')"; | |
104 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,25,'10GBase-ZR')"; | |
105 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,26,'10GBase-LX4')"; | |
106 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,27,'10GBase-CX4')"; | |
107 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (2,28,'10GBase-Kx')"; | |
108 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (12,114,'Cisco Catalyst 2970G-24T')"; | |
109 | $query[] = "INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) VALUES (12,115,'Cisco Catalyst 2970G-24TS')"; | |
110 | $query[] = "INSERT INTO `UserPermission` (`user_id`, `page`, `tab`, `access`) VALUES (0,'help','%','yes')"; | |
111 | // And 0.14.6 is the first release, which features Config table. Let's create | |
112 | // and fill it with default values. | |
113 | $query[] = " | |
114 | CREATE TABLE `Config` ( | |
115 | `varname` char(32) NOT NULL, | |
116 | `varvalue` char(64) NOT NULL, | |
117 | `vartype` enum('string','uint') NOT NULL default 'string', | |
118 | `emptyok` enum('yes','no') NOT NULL default 'no', | |
119 | `is_hidden` enum('yes','no') NOT NULL default 'yes', | |
120 | `description` text, | |
121 | PRIMARY KEY (`varname`) | |
122 | ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | |
123 | "; | |
124 | $query[] = "INSERT INTO `Config` VALUES ('rtwidth_0','9','uint','no','yes','')"; | |
125 | $query[] = "INSERT INTO `Config` VALUES ('rtwidth_1','21','uint','no','yes','')"; | |
126 | $query[] = "INSERT INTO `Config` VALUES ('rtwidth_2','9','uint','no','yes','')"; | |
127 | $query[] = "INSERT INTO `Config` VALUES ('color_F','8fbfbf','string','no','no','HSV: 180-25-75. Free atoms, they are available for allocation to objects.')"; | |
128 | $query[] = "INSERT INTO `Config` VALUES ('color_A','bfbfbf','string','no','no','HSV: 0-0-75. Absent atoms.')"; | |
129 | $query[] = "INSERT INTO `Config` VALUES ('color_U','bf8f8f','string','no','no','HSV: 0-25-75. Unusable atoms. Some problems keep them from being free.')"; | |
130 | $query[] = "INSERT INTO `Config` VALUES ('color_T','408080','string','no','no','HSV: 180-50-50. Taken atoms, object_id should be set for such.')"; | |
131 | $query[] = "INSERT INTO `Config` VALUES ('color_Th','80ffff','string','no','no','HSV: 180-50-100. Taken atoms with highlight. They are not stored in the database and are only used for highlighting.')"; | |
132 | $query[] = "INSERT INTO `Config` VALUES ('color_Tw','804040','string','no','no','HSV: 0-50-50. Taken atoms with object problem. This is detected at runtime.')"; | |
133 | $query[] = "INSERT INTO `Config` VALUES ('color_Thw','ff8080','string','no','no','HSV: 0-50-100. An object can be both current and problematic. We run highlightObject() first and markupObjectProblems() second.')"; | |
134 | $query[] = "INSERT INTO `Config` VALUES ('default_port_type','11','uint','no','no','Default value for port type selects.')"; | |
135 | $query[] = "INSERT INTO `Config` VALUES ('MASSCOUNT','15','uint','no','no','Number of lines in object mass-adding form.')"; | |
136 | $query[] = "INSERT INTO `Config` VALUES ('MAXSELSIZE','30','uint','no','no','Maximum size of a SELECT HTML element.')"; | |
137 | $query[] = "INSERT INTO `Config` VALUES ('enterprise','MyCompanyName','string','no','no','Fit to your needs.')"; | |
138 | $query[] = "INSERT INTO `Config` VALUES ('NAMEFUL_OBJTYPES','4,7,8','string','yes','no','These are the object types, which assume a common name to be normally configured. If a name is absent for an object of one of such types, HTML output is corrected to accent this misconfiguration.')"; | |
139 | $query[] = "INSERT INTO `Config` VALUES ('ROW_SCALE','2','uint','no','no','Row-scope picture scale factor.')"; | |
140 | $query[] = "INSERT INTO `Config` VALUES ('PORTS_PER_ROW','12','uint','no','yes','Max switch port per one row on the switchvlans dynamic tab.')"; | |
141 | $query[] = "INSERT INTO `Config` VALUES ('DB_VERSION','0.14.6','string','no','yes','Database version.')"; | |
142 | break; // -------------------------------------------- | |
803338c1 | 143 | case '0.14.7': |
ce109ff2 | 144 | // IPAddress is hopefully fixed now finally. |
803338c1 | 145 | $query[] = "delete from IPAddress where name = '' and reserved != 'yes'"; |
ce109ff2 DO |
146 | |
147 | // Now rebuild the dictionary into a new table with the same data, | |
148 | // but proper indexing. We are going to convert compound index | |
149 | // into 1-field one to employ AUTO_INCREMENT properly. This means | |
150 | // renumbering lots of records in Dictionary and adjusting records | |
151 | // in related tables. After that we can safely swap the tables. | |
9bf70f70 DO |
152 | $query[] = " |
153 | CREATE TABLE `Dictionary_0_14_7_new` ( | |
154 | `chapter_no` int(10) unsigned NOT NULL, | |
155 | `dict_key` int(10) unsigned NOT NULL auto_increment, | |
156 | `dict_value` char(128) default NULL, | |
157 | PRIMARY KEY (`dict_key`), | |
158 | UNIQUE KEY `chap_to_key` (`chapter_no`,`dict_key`), | |
159 | UNIQUE KEY `chap_to_val` (`chapter_no`,`dict_value`) | |
160 | ) TYPE=MyISAM AUTO_INCREMENT=50000 | |
161 | "; | |
ce109ff2 | 162 | |
758fe24c | 163 | echo '<pre>'; |
ce109ff2 DO |
164 | // Find all chapter numbers, which will require AttributeValue adjustment. |
165 | $q2 = 'select distinct chapter_no from AttributeMap where chapter_no != 0'; | |
166 | $r2 = $dbxlink->query ($q2); | |
758fe24c DO |
167 | $chaplist = array(); |
168 | while ($row = $r2->fetch (PDO::FETCH_NUM)) | |
169 | $chaplist[] = $row[0]; | |
ce109ff2 | 170 | $r2->closeCursor(); |
758fe24c | 171 | unset ($r2); |
ce109ff2 DO |
172 | |
173 | $stock = array(); | |
174 | // Below I list the records, which are known to be the stock | |
175 | // dictionary records of 0.14.6 release. | |
176 | $stock[1] = array | |
177 | ( | |
178 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16 | |
179 | ); | |
180 | $stock[2] = array | |
181 | ( | |
182 | 3, 4, 5, 6, 7, 8, 9, | |
183 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | |
184 | 20, 21, 22, 23, 24, 25, 26, 27, 28 | |
185 | ); | |
186 | $stock[11] = array | |
187 | ( | |
188 | 1, 3, 4, 5, 6, 7, 8, 9, | |
189 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, | |
190 | 21, 22, 24, 25, 26, 27, 28, 29, | |
191 | 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, | |
192 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
193 | 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, | |
194 | 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, | |
195 | 70, 71, 72, 73, 74, 75, 76 | |
196 | ); | |
197 | $stock[12] = array | |
198 | ( | |
199 | 1, 11, 13, 14, 15, 16, 17, 18, 19, 20, 26, 29, | |
200 | 31, 32, 33, 34, 35, 36, 37, 38, 39, | |
201 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
202 | 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, | |
203 | 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, | |
204 | 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, | |
205 | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, | |
206 | 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, | |
207 | 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, | |
db1147d2 | 208 | 110, 111, 112, 113, 114, 115 |
ce109ff2 DO |
209 | ); |
210 | $stock[13] = array | |
211 | ( | |
212 | 1, 2, 3, 4, 5, 6, 7, 8, 9, | |
213 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, | |
214 | 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | |
215 | 30, 31, 32 | |
216 | ); | |
217 | $stock[14] = array | |
218 | ( | |
219 | 1, 2, 9, 11, 13, 15, 19, 20, 21, 22 | |
220 | ); | |
221 | $stock[16] = array | |
222 | ( | |
223 | 1, 2, 3, 4, 5, 6, 7, 8 | |
224 | ); | |
225 | $stock[17] = array | |
226 | ( | |
227 | 1, 2, 3, 4, 5, 6, 7, 8, 9, | |
228 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, | |
229 | 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | |
230 | 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, | |
231 | 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, | |
232 | 50 | |
233 | ); | |
234 | $stock[18] = array | |
235 | ( | |
236 | 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 | |
237 | ); | |
238 | $stock[19] = array | |
239 | ( | |
240 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 | |
241 | ); | |
242 | $stock[20] = array | |
243 | ( | |
244 | 1, 2 | |
245 | ); | |
246 | ||
247 | // Load dictionary and transform into two tree structures for | |
248 | // stock and user record sets. | |
249 | $dict = array(); | |
264b07b4 | 250 | $q3 = 'select chapter_no, dict_key, dict_value from Dictionary order by chapter_no, dict_key'; |
ce109ff2 DO |
251 | $r3 = $dbxlink->query ($q3); |
252 | ||
9e7f8a4b | 253 | while ($row = $r3->fetch (PDO::FETCH_ASSOC)) |
ce109ff2 DO |
254 | { |
255 | $tree = 'user'; | |
256 | $dict_key = $row['dict_key']; | |
257 | $chapter_no = $row['chapter_no']; | |
258 | switch ($chapter_no) | |
259 | { | |
260 | case 1: // RackObjectType | |
261 | case 2: // PortType | |
262 | case 11: // server models | |
263 | case 12: // network switch models | |
264 | case 13: // server OS type | |
265 | case 14: // network switch OS type | |
266 | case 16: // router OS type | |
267 | case 17: // router models | |
268 | case 18: // disk array models | |
269 | case 19: // tape library models | |
270 | case 20: // Protocols | |
271 | if (in_array ($dict_key, $stock[$chapter_no])) | |
272 | $tree = 'stock'; | |
273 | break; | |
274 | } | |
a07a39b1 | 275 | $dict[$tree][$chapter_no][$dict_key] = array ('value' => $row['dict_value']); |
ce109ff2 DO |
276 | } |
277 | $r3->closeCursor(); | |
758fe24c | 278 | unset ($r3); |
ce109ff2 DO |
279 | |
280 | ||
281 | // Now we store stock dataset first, bump up key value and store | |
282 | // user's data. After that we will know the new dict_key for all | |
283 | // records. | |
284 | // The result of both datasets processing is saved in $new_dict. | |
285 | // Save on calling LAST_ISERT_ID() each time by keeping own key. | |
286 | $newkey = 1; | |
287 | $new_dict = array(); | |
288 | foreach ($dict['stock'] as $chapter_no => $words) | |
289 | { | |
290 | $new_dict[$chapter_no] = array(); | |
291 | foreach ($words as $dict_key => $entry) | |
292 | { | |
1b5942be | 293 | $query[] = "insert into Dictionary_0_14_7_new (chapter_no, dict_key, dict_value) " . |
ce109ff2 DO |
294 | "values (${chapter_no}, ${newkey}, '${entry['value']}')"; |
295 | $new_dict[$chapter_no][$dict_key] = $entry; | |
296 | $new_dict[$chapter_no][$dict_key]['newkey'] = $newkey; | |
297 | $newkey++; | |
298 | } | |
299 | } | |
e7882270 | 300 | $newkey = 50000; |
ce109ff2 DO |
301 | foreach ($dict['user'] as $chapter_no => $words) |
302 | { | |
303 | // Some chapters may appear on the user dataset only. | |
304 | if (!isset ($new_dict[$chapter_no])) | |
305 | $new_dict[$chapter_no] = array(); | |
306 | foreach ($words as $dict_key => $entry) | |
307 | { | |
308 | $query[] = "insert into Dictionary_0_14_7_new " . | |
309 | "values (${chapter_no}, ${newkey}, '${entry['value']}')"; | |
310 | $new_dict[$chapter_no][$dict_key] = $entry; | |
311 | $new_dict[$chapter_no][$dict_key]['newkey'] = $newkey; | |
312 | $newkey++; | |
313 | } | |
314 | } | |
315 | // The new table should now have adequate AUTO_INCREMENT w/o our care. | |
758fe24c DO |
316 | // Install the new data. |
317 | $query[] = 'drop table Dictionary'; | |
318 | $query[] = 'alter table Dictionary_0_14_7_new rename to Dictionary'; | |
ce109ff2 DO |
319 | |
320 | // Now we iterate over the joint dataset, picking some chapters and | |
321 | // performing additional processing: | |
322 | // 1 (RackObjectType) --- adjust RackObject and regenerate AttributeMap | |
a07a39b1 | 323 | // 2 (PortType) --- adjust Port and regenerate PortCompat (at a latter point) |
ce109ff2 DO |
324 | // 3 (RackRow) --- adjust Rack |
325 | // 20 (Protocols) --- adjust PortForwarding | |
326 | // All other chapters listed in $chaplist --- adjust AttributeValue | |
327 | ||
328 | $query[] = "delete from AttributeMap"; | |
329 | foreach ($new_dict as $chapter_no => $words) | |
330 | { | |
331 | foreach ($words as $oldkey => $data) | |
332 | { | |
333 | $value = $data['value']; | |
334 | $newkey = $data['newkey']; | |
264b07b4 DO |
335 | // Even if the key doesn't change, go on to have |
336 | // AttributeMap regenerated completely. | |
9bf70f70 | 337 | #echo "oldkey == ${oldkey} newkey == ${newkey} value == ${value}\n"; |
ce109ff2 DO |
338 | if ($chapter_no == 1) |
339 | { | |
340 | $q4 = "select id from RackObject where objtype_id = ${oldkey}"; | |
341 | $r4 = $dbxlink->query ($q4); | |
342 | while ($row = $r4->fetch (PDO::FETCH_ASSOC)) | |
343 | $query[] = "update RackObject set objtype_id = ${newkey} where id = ${row['id']} limit 1"; | |
344 | $r4->closeCursor(); | |
264b07b4 | 345 | unset ($r4); |
ce109ff2 | 346 | |
758fe24c DO |
347 | $q5 = "select attr_id, chapter_no from AttributeMap where objtype_id = ${oldkey}"; |
348 | $r5 = $dbxlink->query ($q5); | |
349 | while ($row = $r5->fetch (PDO::FETCH_ASSOC)) | |
ce109ff2 | 350 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (${newkey}, ${row['attr_id']}, ${row['chapter_no']})"; |
758fe24c | 351 | $r5->closeCursor(); |
264b07b4 | 352 | unset ($r5); |
ce109ff2 | 353 | } |
a07a39b1 DO |
354 | elseif ($chapter_no == 2) |
355 | { | |
758fe24c | 356 | $q46 = "select id from Port where type = ${oldkey}"; |
758fe24c DO |
357 | $r46 = $dbxlink->query ($q46); |
358 | if ($r46 == NULL) | |
359 | echo 'ERROR'; | |
360 | while ($row = $r46->fetch (PDO::FETCH_ASSOC)) | |
a07a39b1 | 361 | $query[] = "update Port set type = ${newkey} where id = ${row['id']} limit 1"; |
758fe24c | 362 | $r46->closeCursor(); |
264b07b4 | 363 | unset ($r46); |
a07a39b1 | 364 | } |
ce109ff2 DO |
365 | elseif ($chapter_no == 3) |
366 | { | |
758fe24c DO |
367 | $q7 = "select id from Rack where row_id = ${oldkey}"; |
368 | $r7 = $dbxlink->query ($q7); | |
369 | while ($row = $r7->fetch (PDO::FETCH_ASSOC)) | |
ce109ff2 | 370 | $query[] = "update Rack set row_id = ${newkey} where id = ${row['id']} limit 1"; |
758fe24c | 371 | $r7->closeCursor(); |
264b07b4 | 372 | unset ($r7); |
ce109ff2 | 373 | } |
a07a39b1 DO |
374 | elseif ($chapter_no == 20) |
375 | { | |
264b07b4 DO |
376 | $q8 = "select object_id, localip, localport, remoteip, remoteport from PortForwarding where proto = ${oldkey}"; |
377 | $r8 = $dbxlink->query ($q8); | |
758fe24c | 378 | while ($row = $r8->fetch (PDO::FETCH_ASSOC)) |
264b07b4 DO |
379 | $query[] = "update PortForwarding set proto = ${newkey} where " . |
380 | "object_id = ${row['object_id']} and localip = ${row['localip']} and " . | |
381 | "localport = ${row['localport']} and remoteip = ${row['remoteip']} and " . | |
382 | "remoteport = ${row['remoteport']} and proto = ${oldkey} limit 1"; | |
758fe24c | 383 | $r8->closeCursor(); |
264b07b4 | 384 | unset ($r8); |
758fe24c DO |
385 | } |
386 | elseif (in_array ($chapter_no, $chaplist)) | |
387 | { | |
5b1d68c5 | 388 | $q81 = "select object_id, AttributeValue.attr_id from " . |
264b07b4 DO |
389 | "AttributeValue natural join Attribute natural join AttributeMap " . |
390 | "inner join RackObject on RackObject.id = object_id and RackObject.objtype_id = AttributeMap.objtype_id " . | |
391 | "where attr_type = 'dict' and chapter_no = ${chapter_no} and uint_value = ${oldkey}"; | |
392 | $r81 = $dbxlink->query ($q81); | |
393 | while ($row = $r81->fetch (PDO::FETCH_ASSOC)) | |
1b5942be DO |
394 | $query[] = "update AttributeValue set uint_value = ${newkey} " . |
395 | "where object_id = ${row['object_id']} and attr_id = ${row['attr_id']}"; | |
264b07b4 DO |
396 | $r81->closeCursor(); |
397 | unset ($r81); | |
a07a39b1 | 398 | } |
ce109ff2 DO |
399 | } |
400 | } | |
a07a39b1 | 401 | // Now it's possible to schedule PortCompat regeneration. |
1b5942be DO |
402 | // Convert the fields to unsigned on occasion. |
403 | $query[] = 'drop table PortCompat'; | |
404 | $query[] = 'create table PortCompat (type1 int(10) unsigned NOT NULL, type2 int(10) unsigned NOT NULL)'; | |
758fe24c DO |
405 | $q9 = "select type1, type2 from PortCompat"; |
406 | $r9 = $dbxlink->query ($q9); | |
407 | while ($row = $r9->fetch (PDO::FETCH_ASSOC)) | |
a07a39b1 DO |
408 | { |
409 | $new_type1 = $new_dict[2][$row['type1']]['newkey']; | |
410 | $new_type2 = $new_dict[2][$row['type2']]['newkey']; | |
411 | $query[] = "insert into PortCompat (type1, type2) values (${new_type1}, ${new_type2})"; | |
412 | } | |
758fe24c | 413 | $r9->closeCursor(); |
264b07b4 | 414 | unset ($r9); |
758fe24c | 415 | echo '</pre>'; |
a07a39b1 DO |
416 | |
417 | // Give the configuration some finish | |
418 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_F'"; | |
419 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_A'"; | |
420 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_U'"; | |
421 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_T'"; | |
422 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Th'"; | |
423 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Tw'"; | |
424 | $query[] = "update Config set is_hidden = 'yes' where varname = 'color_Thw'"; | |
425 | $query[] = "update Config set description = 'Default port type' where varname = 'default_port_type'"; | |
426 | $query[] = "update Config set description = 'Picture scale for rack row display' where varname = 'ROW_SCALE'"; | |
427 | $query[] = "update Config set description = 'Organization name' where varname = 'enterprise'"; | |
428 | $query[] = "update Config set description = 'Expect common name configured for the following object types' where varname = 'NAMEFUL_OBJTYPES'"; | |
429 | $query[] = "update Config set description = '<SELECT> lists height' where varname = 'MAXSELSIZE'"; | |
430 | $query[] = "update Config set description = '"Fast" form is this many records tall' where varname = 'MASSCOUNT'"; | |
264b07b4 | 431 | $query[] = "update Config set is_hidden = 'no', description = 'Ports per row in VLANs tab' where varname = 'PORTS_PER_ROW'"; |
a07a39b1 | 432 | $query[] = "INSERT INTO `Config` VALUES ('IPV4_ADDRS_PER_PAGE','256','uint','no','no','IPv4 addresses per page')"; |
9e7f8a4b | 433 | $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_RACK_HEIGHT','42','uint','yes','no','Default rack height')"; |
bd912758 DO |
434 | // After Dictionary transformation we ought to list 337 stock records in DB. Add more. |
435 | $new_words = array(); | |
436 | $new_words[338] = array (12 => 'Dell PowerConnect 2216'); | |
437 | $new_words[] = array (12 => 'Dell PowerConnect 2224'); | |
438 | $new_words[] = array (12 => 'Dell PowerConnect 2324'); | |
439 | $new_words[] = array (12 => 'Dell PowerConnect 2708'); | |
440 | $new_words[] = array (12 => 'Dell PowerConnect 2716'); | |
441 | $new_words[] = array (12 => 'Dell PowerConnect 2724'); | |
442 | $new_words[] = array (12 => 'Dell PowerConnect 2748'); | |
443 | $new_words[] = array (12 => 'Dell PowerConnect 3424'); | |
444 | $new_words[] = array (12 => 'Dell PowerConnect 3424P'); | |
445 | $new_words[] = array (12 => 'Dell PowerConnect 3448'); | |
446 | $new_words[] = array (12 => 'Dell PowerConnect 3448P'); | |
447 | $new_words[] = array (12 => 'Dell PowerConnect 5324'); | |
448 | $new_words[] = array (12 => 'Dell PowerConnect 6224'); | |
449 | $new_words[] = array (12 => 'Dell PowerConnect 6224P'); | |
450 | $new_words[] = array (12 => 'Dell PowerConnect 6224F'); | |
451 | $new_words[] = array (12 => 'Dell PowerConnect 6248'); | |
452 | $new_words[] = array (12 => 'Dell PowerConnect 6248P'); | |
453 | $new_words[] = array (11 => 'Dell PowerEdge 6850'); | |
454 | $new_words[] = array (11 => 'Dell PowerEdge 6950'); | |
455 | $new_words[] = array (11 => 'Dell PowerEdge R900'); | |
456 | $new_words[] = array (11 => 'Dell PowerEdge 4400'); | |
457 | $new_words[] = array (11 => 'Dell PowerEdge 2650'); | |
458 | $new_words[] = array (11 => 'Dell PowerEdge 2550'); | |
459 | $new_words[] = array (11 => 'Dell PowerEdge 750'); | |
460 | $new_words[] = array (11 => 'Dell PowerEdge 2450'); | |
461 | $new_words[] = array (11 => 'Dell PowerEdge 850'); | |
462 | $new_words[] = array (11 => 'Dell PowerEdge 1850'); | |
463 | $new_words[] = array (11 => 'Dell PowerEdge 860'); | |
464 | $new_words[] = array (11 => 'Dell PowerEdge 2900'); | |
465 | $new_words[] = array (11 => 'Dell PowerEdge 2970'); | |
466 | $new_words[] = array (11 => 'Dell PowerEdge SC1435'); | |
467 | $new_words[] = array (12 => 'Cisco Catalyst 6509'); | |
468 | $new_words[] = array (12 => 'Cisco ME 6524GS-8S'); | |
469 | $new_words[] = array (12 => 'Cisco ME 6524GT-8S'); | |
470 | $new_words[] = array (12 => 'Cisco Catalyst 4503-E'); | |
471 | $new_words[] = array (12 => 'Cisco Catalyst 4506-E'); | |
472 | $new_words[] = array (12 => 'Cisco Catalyst 4507R-E'); | |
473 | $new_words[] = array (12 => 'Cisco Catalyst 4510R-E'); | |
474 | $new_words[] = array (12 => 'Cisco Catalyst 3750-24TE-M'); | |
475 | $new_words[] = array (12 => 'Cisco Catalyst 4948-10GE'); | |
476 | $new_words[] = array (12 => 'Cisco ME 4924-10GE'); | |
477 | $new_words[] = array (12 => 'Cisco Catalyst 2960-24'); | |
478 | $new_words[] = array (12 => 'Cisco Catalyst 2950-24'); | |
479 | $new_words[] = array (12 => 'Cisco Catalyst 2950-12'); | |
480 | $new_words[] = array (12 => 'Cisco Catalyst 2950C-24'); | |
481 | $new_words[] = array (12 => 'Cisco Catalyst 2950G-24-DC'); | |
482 | $new_words[] = array (12 => 'Cisco Catalyst 2950SX-48'); | |
483 | $new_words[] = array (12 => 'Cisco Catalyst 2950SX-24'); | |
484 | $new_words[] = array (12 => 'Cisco Catalyst 2950T-24'); | |
485 | $new_words[] = array (12 => 'Cisco Catalyst 2950T-48'); | |
486 | $new_words[] = array (12 => 'Cisco Catalyst 2950G-12'); | |
487 | $new_words[] = array (12 => 'Cisco Catalyst 2950G-24'); | |
488 | $new_words[] = array (12 => 'Cisco Catalyst 2950G-48'); | |
bd912758 DO |
489 | $new_words[] = array (12 => 'Cisco Catalyst 3508G XL'); |
490 | $new_words[] = array (12 => 'Cisco Catalyst 3512 XL'); | |
491 | $new_words[] = array (12 => 'Cisco Catalyst 3524 XL'); | |
492 | $new_words[] = array (12 => 'Cisco Catalyst 3524 PWR XL'); | |
493 | $new_words[] = array (12 => 'Cisco Catalyst 3548 XL'); | |
494 | $new_words[] = array (12 => 'Cisco ME 2400-24TS-A'); | |
495 | $new_words[] = array (12 => 'Cisco ME 2400-24TS-D'); | |
496 | $new_words[] = array (12 => 'Cisco Catalyst 3550-12T'); | |
497 | $new_words[] = array (12 => 'Cisco Catalyst 3550-12G'); | |
498 | $new_words[] = array (12 => 'Cisco Catalyst 3550-24'); | |
499 | $new_words[] = array (12 => 'Cisco Catalyst 3550-24 FX'); | |
500 | $new_words[] = array (12 => 'Cisco Catalyst 3550-24 DC'); | |
501 | $new_words[] = array (12 => 'Cisco Catalyst 3550-24 PWR'); | |
502 | $new_words[] = array (12 => 'Cisco Catalyst 3550-48'); | |
503 | $new_words[] = array (12 => 'Cisco ME 3400G-12CS-A'); | |
504 | $new_words[] = array (12 => 'Cisco ME 3400G-12CS-D'); | |
505 | $new_words[] = array (12 => 'Cisco ME 3400G-2CS-A'); | |
506 | $new_words[] = array (12 => 'Cisco ME 3400-24TS-A'); | |
507 | $new_words[] = array (12 => 'Cisco ME 3400-24TS-D'); | |
508 | $new_words[] = array (12 => 'Cisco ME 3400-24FS-A'); | |
7373a304 DO |
509 | $new_words[] = array (12 => 'Foundry FastIron GS 624XGP'); |
510 | $new_words[] = array (12 => 'Foundry FastIron GS 624XGP-POE'); | |
511 | $new_words[] = array (12 => 'Foundry FastIron LS 624'); | |
512 | $new_words[] = array (12 => 'Foundry FastIron LS 648'); | |
513 | $new_words[] = array (12 => 'Foundry NetIron M2404F'); | |
514 | $new_words[] = array (12 => 'Foundry NetIron M2404C'); | |
515 | $new_words[] = array (17 => 'Foundry BigIron RX-32'); | |
e7882270 DO |
516 | $new_words[] = array (13 => 'Debian 2.0 (hamm)'); |
517 | $new_words[] = array (13 => 'Debian 2.1 (slink)'); | |
518 | $new_words[] = array (13 => 'Debian 2.2 (potato)'); | |
519 | $new_words[] = array (13 => 'Debian 4.0 (etch)'); | |
520 | $new_words[] = array (13 => 'ALTLinux Server 4.0'); | |
e7882270 DO |
521 | $new_words[] = array (13 => 'ALTLinux Sisyphus'); |
522 | $new_words[] = array (13 => 'openSUSE 10.0'); | |
523 | $new_words[] = array (13 => 'openSUSE 10.1'); | |
524 | $new_words[] = array (13 => 'openSUSE 10.2'); | |
525 | $new_words[] = array (13 => 'openSUSE 10.3'); | |
526 | $new_words[] = array (13 => 'Ubuntu 4.10'); | |
527 | $new_words[] = array (13 => 'Ubuntu 5.04'); | |
528 | $new_words[] = array (13 => 'Ubuntu 5.10'); | |
529 | $new_words[] = array (13 => 'Ubuntu 6.06 LTS'); | |
530 | $new_words[] = array (13 => 'Ubuntu 6.10'); | |
531 | $new_words[] = array (13 => 'Ubuntu 7.04'); | |
532 | $new_words[] = array (13 => 'Ubuntu 7.10'); | |
533 | $new_words[] = array (13 => 'Ubuntu 8.04 LTS'); | |
534 | $new_words[] = array (13 => 'RHEL5'); | |
5f58747d DO |
535 | $new_words[] = array (18 => 'Dell PowerVault 210S'); |
536 | $new_words[] = array (18 => 'Dell PowerVault 221S'); | |
ab0ec3ef DO |
537 | $new_words[] = array (2 => 'dry contact'); |
538 | $new_words[] = array (2 => 'unknown'); | |
499dfa73 DO |
539 | // Two above records ought to take keys 439 and 440. |
540 | $query[] = "INSERT INTO `PortCompat` (`type1`, `type2`) VALUES (439,439)"; | |
efb6bab4 DO |
541 | $new_words[] = array (13 => 'CentOS-2'); |
542 | $new_words[] = array (13 => 'CentOS-3'); | |
543 | $new_words[] = array (13 => 'CentOS-4'); | |
544 | $new_words[] = array (13 => 'CentOS-5'); | |
bd912758 DO |
545 | foreach ($new_words as $dict_key => $tmp) |
546 | foreach ($tmp as $chapter_no => $dict_value) | |
547 | $query[] = 'INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) ' . | |
548 | "VALUES (${chapter_no}, ${dict_key}, '${dict_value}')"; | |
57913f20 DO |
549 | // Resetting to defaults is worse, than remapping, but better than |
550 | // leaving messed values. | |
551 | $query[] = "update Config set varvalue = '24' where varname = 'default_port_type' limit 1"; | |
ce109ff2 | 552 | // We are done. |
54c2a7a8 | 553 | $query[] = "update Config set varvalue = '0.14.7' where varname = 'DB_VERSION'"; |
803338c1 | 554 | break; // -------------------------------------------- |
a6305acc DO |
555 | case '0.14.8': |
556 | $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('REQUIRE_ASSET_TAG_FOR','4,7,8','string','yes','no','Require asset tag for the following object types')"; | |
78f44cbc DO |
557 | $query[] = "alter table Port modify column id int(10) unsigned NOT NULL auto_increment"; |
558 | $query[] = "alter table Port modify column object_id int(10) unsigned NOT NULL"; | |
559 | $query[] = "alter table Port modify column type int(10) unsigned NOT NULL"; | |
560 | $query[] = "alter table Link modify column porta int(10) unsigned"; | |
561 | $query[] = "alter table Link modify column portb int(10) unsigned"; | |
ba1c6d42 DO |
562 | $query[] = "alter table PortForwarding modify column object_id int(10) unsigned not null"; |
563 | $query[] = "alter table PortForwarding modify column localport smallint(5) unsigned not null"; | |
564 | $query[] = "alter table PortForwarding modify column remoteport smallint(5) unsigned not null"; | |
565 | $query[] = "alter table IPBonds modify column object_id int(10) unsigned not null"; | |
566 | $query[] = "alter table IPRanges modify column id int(10) unsigned not null"; | |
567 | $query[] = "alter table IPRanges modify column mask int(10) unsigned not null"; | |
78f44cbc DO |
568 | $query[] = "alter table Port add index `type` (type)"; |
569 | $query[] = "alter table PortCompat add index `type1` (type1)"; | |
570 | $query[] = "alter table PortCompat add index `type2` (type2)"; | |
992d2ec2 DO |
571 | $query[] = "update Dictionary set dict_value = 'Debian 3.0 (woody)' where dict_key = 234"; |
572 | $query[] = "update Dictionary set dict_value = 'Debian 3.1 (sarge)' where dict_key = 235"; | |
573 | $query[] = "update Dictionary set dict_value = 'Foundry BigIron 15000' where dict_key = 311"; | |
574 | $query[] = "update Dictionary set dict_value = 'RHF7' where dict_key = 232"; | |
575 | $query[] = "update Dictionary set dict_value = 'RHF8' where dict_key = 242"; | |
c8b74094 DO |
576 | $query[] = "INSERT INTO `Attribute` (`attr_id`, `attr_type`, `attr_name`) VALUES (25,'string','UUID');"; |
577 | $query[] = "INSERT INTO `AttributeMap` (`objtype_id`, `attr_id`, `chapter_no`) VALUES (4,25,0);"; | |
ba1c6d42 DO |
578 | $query[] = "update Dictionary set dict_value = '[[Cisco Catalyst 2970G-24T | http://www.cisco.com/en/US/products/hw/switches/ps5206/ps5313/index.html]]' where dict_key = 210"; |
579 | $query[] = "update Dictionary set dict_value = '[[Cisco Catalyst 2970G-24TS | http://www.cisco.com/en/US/products/hw/switches/ps5206/ps5437/index.html]]' where dict_key = 211"; | |
78f44cbc | 580 | $query[] = "update Config set varvalue = '0.14.8' where varname = 'DB_VERSION'"; |
a6305acc | 581 | break; // -------------------------------------------- |
cf48742e DO |
582 | case '0.14.9': |
583 | $query[] = "alter table IPRanges modify column id int(10) unsigned not null auto_increment"; | |
0a7136d4 | 584 | $query[] = "alter table Rack modify column height tinyint(3) unsigned not null default '42'"; |
86f94102 | 585 | $query[] = "alter table Rack add column thumb_data blob after comment"; |
2526f63c DO |
586 | $query[] = " |
587 | CREATE TABLE `IPLoadBalancer` ( | |
588 | `object_id` int(10) unsigned default NULL, | |
589 | `rspool_id` int(10) unsigned default NULL, | |
70c24883 | 590 | `vs_id` int(10) unsigned default NULL, |
2526f63c DO |
591 | `vsconfig` text, |
592 | `rsconfig` text, | |
70c24883 | 593 | UNIQUE KEY `LB-VS` (`object_id`,`vs_id`) |
2526f63c DO |
594 | ) ENGINE=MyISAM"; |
595 | $query[] = " | |
596 | CREATE TABLE `IPRSPool` ( | |
597 | `id` int(10) unsigned NOT NULL auto_increment, | |
2526f63c DO |
598 | `name` char(255) default NULL, |
599 | `vsconfig` text, | |
600 | `rsconfig` text, | |
601 | PRIMARY KEY (`id`) | |
602 | ) ENGINE=MyISAM"; | |
603 | $query[] = " | |
604 | CREATE TABLE `IPRealServer` ( | |
605 | `id` int(10) unsigned NOT NULL auto_increment, | |
35b72b35 | 606 | `inservice` enum('yes','no') NOT NULL default 'no', |
2526f63c DO |
607 | `rsip` int(10) unsigned default NULL, |
608 | `rsport` smallint(5) unsigned default NULL, | |
609 | `rspool_id` int(10) unsigned default NULL, | |
610 | `rsconfig` text, | |
70c24883 DO |
611 | PRIMARY KEY (`id`), |
612 | UNIQUE KEY `pool-endpoint` (`rspool_id`,`rsip`,`rsport`) | |
2526f63c DO |
613 | ) ENGINE=MyISAM"; |
614 | $query[] = " | |
615 | CREATE TABLE `IPVirtualService` ( | |
616 | `id` int(10) unsigned NOT NULL auto_increment, | |
617 | `vip` int(10) unsigned default NULL, | |
618 | `vport` smallint(5) unsigned default NULL, | |
619 | `proto` enum('TCP','UDP') NOT NULL default 'TCP', | |
620 | `name` char(255) default NULL, | |
621 | `vsconfig` text, | |
622 | `rsconfig` text, | |
d800a805 | 623 | PRIMARY KEY (`id`) |
2526f63c | 624 | ) ENGINE=MyISAM"; |
d800a805 | 625 | $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_SLB_VS_PORT','','uint','yes','no','Default port of SLB virtual service')"; |
73e11958 | 626 | $query[] = "INSERT INTO `Config` VALUES ('DEFAULT_SLB_RS_PORT','','uint','yes','no','Default port of SLB real server')"; |
6dbdc7c7 DO |
627 | $query[] = "INSERT INTO `Config` VALUES ('IPV4_PERFORMERS','1,4,7,8,12,14','string','yes','no','IPv4-capable object types')"; |
628 | $query[] = "INSERT INTO `Config` VALUES ('NATV4_PERFORMERS','4,7,8','string','yes','no','NATv4-capable object types')"; | |
f2154c9f | 629 | $query[] = "INSERT INTO `Config` VALUES ('USER_AUTH_SRC','database','string','no','no','User authentication source')"; |
3e0fc4b6 | 630 | $query[] = "alter table RackSpace drop column problem_id"; |
d800a805 | 631 | $query[] = "update Config set varvalue = '0.14.9' where varname = 'DB_VERSION'"; |
cf48742e | 632 | break; // -------------------------------------------- |
a6f83a72 DO |
633 | case '0.14.10': |
634 | $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('DETECT_URLS','no','string','yes','no','Detect URLs in text fields')"; | |
f187f2ec DO |
635 | $query[] = "alter table RackHistory modify column height tinyint(3) unsigned"; |
636 | $query[] = "alter table RackHistory add column thumb_data blob after comment"; | |
4b8d413e | 637 | $query[] = "INSERT INTO `Config` VALUES ('RACK_PRESELECT_THRESHOLD','1','uint','no','no','Rack pre-selection threshold')"; |
a6f83a72 | 638 | $query[] = "update Config set varvalue = '0.14.10' where varname = 'DB_VERSION'"; |
81dbd3bc | 639 | break; // -------------------------------------------- |
2ff234d6 DO |
640 | case '0.14.11': |
641 | $new_words = array(); | |
642 | $new_words[445] = array (1 => 'KVM switch'); | |
643 | $new_words[] = array (2 => 'KVM (console)'); | |
644 | $new_words[] = array (1 => 'multiplexer'); | |
645 | $query[] = "update Dictionary set dict_value = 'network switch' where dict_key = 8"; | |
646 | $query[] = "update Dictionary set dict_value = 'KVM (host)' where dict_key = 33"; | |
647 | $query[] = "delete from PortCompat where type1 = 33 and type2 = 33"; | |
648 | $query[] = "insert into PortCompat (type1, type2) values (33, 446)"; | |
649 | $query[] = "insert into PortCompat (type1, type2) values (446, 33)"; | |
35d3ecaf DO |
650 | $query[] = "insert into Chapter (chapter_no, sticky, chapter_name) values (21, 'no', 'KVM switch models')"; |
651 | $query[] = "insert into Chapter (chapter_no, sticky, chapter_name) values (22, 'no', 'multiplexer models')"; | |
2ff234d6 DO |
652 | $query[] = "update Chapter set chapter_name = 'network switch models' where chapter_no = 12"; |
653 | $new_words[] = array (21 => '[[Avocent DSR1021 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2418]]'); | |
654 | $new_words[] = array (21 => '[[Avocent DSR1022 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2498]]'); | |
655 | $new_words[] = array (21 => '[[Avocent DSR1024 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2588]]'); | |
656 | $new_words[] = array (21 => '[[Avocent DSR1031 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2804]]'); | |
657 | $new_words[] = array (21 => '[[Avocent DSR1020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2340]]'); | |
658 | $new_words[] = array (21 => '[[Avocent DSR2020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2884]]'); | |
659 | $new_words[] = array (21 => '[[Avocent DSR4020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3100]]'); | |
660 | $new_words[] = array (21 => '[[Avocent DSR8020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3358]]'); | |
661 | $new_words[] = array (21 => '[[Avocent DSR1030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2726]]'); | |
662 | $new_words[] = array (21 => '[[Avocent DSR2030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2988]]'); | |
663 | $new_words[] = array (21 => '[[Avocent DSR2035 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3050]]'); | |
664 | $new_words[] = array (21 => '[[Avocent DSR4030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3196]]'); | |
665 | $new_words[] = array (21 => '[[Avocent DSR8030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3472]]'); | |
666 | $new_words[] = array (21 => '[[Avocent DSR8035 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3580]]'); | |
667 | $new_words[] = array (21 => '[[Avocent AutoView 1415 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1612]]'); | |
668 | $new_words[] = array (21 => '[[Avocent AutoView 1515 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1736]]'); | |
669 | $new_words[] = array (21 => '[[Avocent AutoView 2015 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=1930]]'); | |
670 | $new_words[] = array (21 => '[[Avocent AutoView 2020 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2012]]'); | |
671 | $new_words[] = array (21 => '[[Avocent AutoView 2030 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2114]]'); | |
672 | $new_words[] = array (21 => '[[Avocent AutoView 3100 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2222]]'); | |
673 | $new_words[] = array (21 => '[[Avocent AutoView 3200 | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=2266]]'); | |
674 | $new_words[] = array (21 => '[[Avocent SwitchView 1000 4-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=4016]]'); | |
675 | $new_words[] = array (21 => '[[Avocent SwitchView 1000 8-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=4094]]'); | |
676 | $new_words[] = array (21 => '[[Avocent SwitchView 1000 16-port | http://www.avocent.com/WorkArea/linkit.aspx?LinkIdentifier=id&ItemID=3934]]'); | |
677 | $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
678 | $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
679 | $new_words[] = array (22 => '[[Cronyx FMUX/S-4E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
680 | $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
681 | $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
682 | $new_words[] = array (22 => '[[Cronyx FMUX/S-8E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
683 | $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1 | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
684 | $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1/ETS | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
685 | $new_words[] = array (22 => '[[Cronyx FMUX/S-16E1/M | http://www.cronyx.ru/hardware/fmux-ring.html]]'); | |
686 | $new_words[] = array (22 => '[[Cronyx E1-XL/S | http://www.cronyx.ru/hardware/e1xl-s.html]]'); | |
687 | $new_words[] = array (22 => '[[Cronyx E1-DXC/S | http://www.cronyx.ru/hardware/e1dxc-s.html]]'); | |
688 | $new_words[] = array (22 => '[[Cronyx FMUX-4-E2 | http://www.cronyx.ru/hardware/fmux4-e2.html]]'); | |
689 | $new_words[] = array (22 => '[[Cronyx FMUX-4-E3 | http://www.cronyx.ru/hardware/fmux16-e3.html]]'); | |
690 | $new_words[] = array (22 => '[[Cronyx FMUX/SAT | http://www.cronyx.ru/hardware/fmux-sat.html]]'); | |
691 | $new_words[] = array (22 => '[[Cronyx E1-XL/S-IP | http://www.cronyx.ru/hardware/e1xl-ip.html]]'); | |
692 | $new_words[] = array (17 => '[[RAD FCD-IPM | http://www.rad.com/Article/0,6583,36426-E1_T1_or_Fractional_E1_T1_Modular_Access_Device_with_Integrated_Router,00.html]]'); | |
693 | $new_words[] = array (22 => '[[RAD FCD-E1M | http://www.rad.com/Article/0,6583,36723-E1_T1_Modular_Access_Multiplexer,00.html]]'); | |
694 | $new_words[] = array (22 => '[[RAD FCD-T1M | http://www.rad.com/Article/0,6583,36723-E1_T1_Modular_Access_Multiplexer,00.html]]'); | |
695 | $new_words[] = array (22 => '[[RAD FCD-155E | http://www.rad.com/Article/0,6583,36276-Ethernet_over_SDH_SONET_ADM,00.html]]'); | |
696 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 1, 0)"; | |
697 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 2, 21)"; | |
698 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 3, 0)"; | |
699 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 5, 0)"; | |
700 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 14, 0)"; | |
701 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (445, 22, 0)"; | |
702 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 1, 0)"; | |
703 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 2, 22)"; | |
704 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 3, 0)"; | |
705 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 5, 0)"; | |
706 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 14, 0)"; | |
707 | $query[] = "insert into AttributeMap (objtype_id, attr_id, chapter_no) values (447, 22, 0)"; | |
708 | # $query[] = ""; | |
709 | foreach ($new_words as $dict_key => $tmp) | |
710 | foreach ($tmp as $chapter_no => $dict_value) | |
711 | $query[] = 'INSERT INTO `Dictionary` (`chapter_no`, `dict_key`, `dict_value`) ' . | |
712 | "VALUES (${chapter_no}, ${dict_key}, '${dict_value}')"; | |
f70bed91 | 713 | $query[] = "update Rack set thumb_data = NULL"; |
2ff234d6 DO |
714 | $query[] = "update Config set varvalue = '0.14.11' where varname = 'DB_VERSION'"; |
715 | break; // -------------------------------------------- | |
7e7a8387 DO |
716 | case '0.14.12': |
717 | $query[] = "INSERT INTO `Config` VALUES (DEFAULT_IPV4_RS_INSERVICE','no','string','no','no','Inservice status for new SLB real servers')"; | |
718 | $query[] = "update Config set varvalue = '0.14.12' where varname = 'DB_VERSION'"; | |
719 | break; // -------------------------------------------- | |
720 | # case '0.14.13': | |
80a40611 DO |
721 | # $query[] = "INSERT INTO `Config` (varname, varvalue, vartype, emptyok, is_hidden, description) VALUES ('AUTO_PORTS_CONFIG','FIXME','string','yes','no','Autoports configuration')"; |
722 | # $query[] = "alter table Rack add column left_is_front enum ('yes', 'no') not null default 'yes' after height"; | |
723 | # $query[] = "alter table Rack add column bottom_is_unit1 enum ('yes', 'no') not null default 'yes' after left_is_front"; | |
7e7a8387 | 724 | # $query[] = "update Config set varvalue = '0.14.13' where varname = 'DB_VERSION'"; |
80a40611 | 725 | # break; // -------------------------------------------- |
fbbb74fb DO |
726 | default: |
727 | showError ("executeUpgradeBatch () failed, because batch '${batchid}' isn't defined"); | |
728 | die; | |
729 | break; | |
730 | } | |
fbbb74fb | 731 | $failures = array(); |
ce109ff2 | 732 | $ndots = 0; |
22e40283 | 733 | echo "<pre>Executing database upgrade batch '${batchid}':\n"; |
fbbb74fb DO |
734 | foreach ($query as $q) |
735 | { | |
736 | $result = $dbxlink->query ($q); | |
737 | if ($result != NULL) | |
fbbb74fb | 738 | echo '.'; |
758fe24c DO |
739 | else |
740 | { | |
741 | echo '!'; | |
742 | $errorInfo = $dbxlink->errorInfo(); | |
743 | $failures[] = array ($q, $errorInfo[2]); | |
744 | } | |
745 | if (++$ndots == 50) | |
746 | { | |
747 | echo "\n"; | |
15a50768 | 748 | flush(); |
758fe24c | 749 | $ndots = 0; |
fbbb74fb | 750 | } |
fbbb74fb DO |
751 | } |
752 | echo '<br>'; | |
753 | if (!count ($failures)) | |
754 | echo "No errors!\n"; | |
755 | else | |
756 | { | |
757 | echo "The following queries failed:\n"; | |
758 | foreach ($failures as $f) | |
759 | { | |
760 | list ($q, $i) = $f; | |
761 | echo "${q} // ${i}\n"; | |
762 | } | |
763 | } | |
764 | echo '</pre>'; | |
765 | } | |
766 | ||
767 | // ****************************************************************** | |
768 | // | |
769 | // Execution starts here | |
770 | // | |
771 | // ****************************************************************** | |
772 | ||
773 | $root = (empty($_SERVER['HTTPS'])?'http':'https'). | |
774 | '://'. | |
775 | (isset($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:($_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT']=='80'?'':$_SERVER['SERVER_PORT']))). | |
54c2a7a8 DO |
776 | dirname($_SERVER['PHP_SELF']); |
777 | if (substr ($root, -1) != '/') | |
778 | $root .= '/'; | |
fbbb74fb DO |
779 | |
780 | // The below will be necessary as long as we rely on showError() | |
781 | require_once 'inc/interface.php'; | |
782 | ||
783 | require_once 'inc/config.php'; | |
784 | require_once 'inc/database.php'; | |
785 | if (file_exists ('inc/secret.php')) | |
786 | require_once 'inc/secret.php'; | |
787 | else | |
788 | die ("Database connection parameters are read from inc/secret.php file, " . | |
789 | "which cannot be found.\nCopy provided inc/secret-sample.php to " . | |
790 | "inc/secret.php and modify to your setup.\n\nThen reload the page."); | |
791 | ||
792 | try | |
793 | { | |
794 | $dbxlink = new PDO ($pdo_dsn, $db_username, $db_password); | |
795 | } | |
796 | catch (PDOException $e) | |
797 | { | |
798 | die ("Database connection failed:\n\n" . $e->getMessage()); | |
799 | } | |
800 | ||
fbbb74fb DO |
801 | // Now we need to be sure that the current user is the administrator. |
802 | // The rest doesn't matter within this context. | |
803 | // We still continue to use the current authenticator though, but this will | |
804 | // last only till the UserAccounts remains the same. After that this file | |
805 | // will have to dig into the DB for the user accounts. | |
806 | require_once 'inc/auth.php'; | |
807 | ||
808 | // This will not fail sanely, because getUserAccounts() depends on showError() | |
809 | $accounts = getUserAccounts(); | |
810 | ||
d78fdaea DO |
811 | // Only administrator is always authenticated locally, so reject others |
812 | // for authenticate() to succeed. | |
99ee5479 DO |
813 | |
814 | if | |
815 | ( | |
816 | !isset ($_SERVER['PHP_AUTH_USER']) or | |
817 | !isset ($_SERVER['PHP_AUTH_PW']) or | |
818 | $accounts[$_SERVER['PHP_AUTH_USER']]['user_id'] != 1 or | |
819 | !authenticated_via_database (escapeString ($_SERVER['PHP_AUTH_USER']), escapeString ($_SERVER['PHP_AUTH_PW'])) | |
820 | ) | |
821 | { | |
c0142c01 DO |
822 | header ('WWW-Authenticate: Basic realm="RackTables upgrade"'); |
823 | header ('HTTP/1.0 401 Unauthorized'); | |
824 | showError ('You must be authenticated as an administrator to complete the upgrade.'); | |
99ee5479 DO |
825 | die; |
826 | } | |
fbbb74fb DO |
827 | |
828 | $dbver = getDatabaseVersion(); | |
829 | echo 'Code version == ' . CODE_VERSION; | |
830 | echo '<br>Database version == ' . $dbver; | |
831 | if ($dbver == CODE_VERSION) | |
758fe24c | 832 | { |
fbbb74fb DO |
833 | die ("<p align=justify>Your database seems to be up-to-date. " . |
834 | "Now the best thing to do would be to follow to the <a href='${root}'>main page</a> " . | |
835 | "and explore your data. Have a nice day.</p>"); | |
758fe24c | 836 | } |
fbbb74fb DO |
837 | |
838 | foreach (getDBUpgradePath ($dbver, CODE_VERSION) as $batchid) | |
839 | executeUpgradeBatch ($batchid); | |
840 | ||
841 | echo '<br>Database version == ' . getDatabaseVersion(); | |
842 | echo "<p align=justify>Your database seems to be up-to-date. " . | |
843 | "Now the best thing to do would be to follow to the <a href='${root}'>main page</a> " . | |
844 | "and explore your data. Have a nice day.</p>"; | |
845 | ||
846 | ?> |