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