1 | <?php |
---|
2 | // for easier patching |
---|
3 | |
---|
4 | // Note: DO UPDATES ALWAYS OVER THE ITEM NAMES, SO NO KB's |
---|
5 | // DATABASES GET SCREWED UP. |
---|
6 | // |
---|
7 | // |
---|
8 | if (!config::get("DBUpdate")) |
---|
9 | config::set("DBUpdate","000"); |
---|
10 | |
---|
11 | // Current update version of Database |
---|
12 | define(CURRENT_DB_UPDATE,config::get("DBUpdate")); |
---|
13 | //Update version of this autoupgrade.php |
---|
14 | // Moved to index.php |
---|
15 | //define(LASTEST_DB_UPDATE,"008"); |
---|
16 | |
---|
17 | function updateDB(){ |
---|
18 | // if update nesseary run updates |
---|
19 | if (CURRENT_DB_UPDATE < LASTEST_DB_UPDATE ){ |
---|
20 | |
---|
21 | update001(); |
---|
22 | update002(); |
---|
23 | update003(); |
---|
24 | update004(); |
---|
25 | update005(); |
---|
26 | |
---|
27 | update007(); |
---|
28 | update008(); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | /* |
---|
33 | * Too much has changed between update005 and current status for a clean |
---|
34 | * update006. Restarting from update007 in the hope that the differences |
---|
35 | * between 5 and 7 are worked out and an update006 implemented |
---|
36 | */ |
---|
37 | |
---|
38 | function update001(){ |
---|
39 | //Checking if this Update already done |
---|
40 | if (CURRENT_DB_UPDATE < "001" ) |
---|
41 | { |
---|
42 | require_once("common/includes/class.item.php"); |
---|
43 | // Changing ShieldBooster Slot from None to Mid Slot |
---|
44 | $ShieldBoosterGroup = item::get_group_id("Small Shield Booster I"); |
---|
45 | update_slot_of_group($ShieldBoosterGroup,0,2); |
---|
46 | |
---|
47 | // Changing Tracking Scripts Slot from None to Mid Slot |
---|
48 | $ScriptGroupID1 = item::get_group_id("Optimal Range"); |
---|
49 | update_slot_of_group($ScriptGroupID1,0,2); |
---|
50 | |
---|
51 | // Changing Warp Disruption Scripts Slot from None to Mid Slot |
---|
52 | $ScriptGroupID2 = item::get_group_id("Focused Warp Disruption"); |
---|
53 | update_slot_of_group($ScriptGroupID2,0,2); |
---|
54 | |
---|
55 | // Changing Tracking Disruption Scripts Slot from None to Mid Slot |
---|
56 | $ScriptGroupID3 = item::get_group_id("Optimal Range Disruption"); |
---|
57 | update_slot_of_group($ScriptGroupID3,0,2); |
---|
58 | |
---|
59 | // Changing Sensor Booster Scripts Slot from None to Mid Slot |
---|
60 | $ScriptGroupID4 = item::get_group_id("Targeting Range"); |
---|
61 | update_slot_of_group($ScriptGroupID4,0,2); |
---|
62 | |
---|
63 | // Changing Sensor Dampener Scripts Slot from None to Mid Slot |
---|
64 | $ScriptGroupID5 = item::get_group_id("Scan Resolution Dampening"); |
---|
65 | update_slot_of_group($ScriptGroupID5,0,2); |
---|
66 | |
---|
67 | // Changing Energy Weapon Slot from None to High Slot |
---|
68 | $EnergyWeaponGroup = item::get_group_id("Gatling Pulse Laser I"); |
---|
69 | update_slot_of_group($EnergyWeaponGroup,0,1); |
---|
70 | |
---|
71 | // Changing Group of Salvager I to same as Small Tractor Beam I |
---|
72 | $item = new Item(); |
---|
73 | $item->lookup("Salvager I"); |
---|
74 | $SalvagerTypeId = $item->getId(); |
---|
75 | $SalvagerGroup = item::get_group_id("Salvager I"); |
---|
76 | $TractorBeam = item::get_group_id("Small Tractor Beam I"); |
---|
77 | move_item_to_group($SalvagerTypeId,$SalvagerGroup ,$TractorBeam); |
---|
78 | |
---|
79 | //writing Update Status into ConfigDB |
---|
80 | config::set("DBUpdate","001"); |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | function update002(){ |
---|
85 | // to correct the already existing Salvager in med slots. |
---|
86 | // missed it in update001 |
---|
87 | if (CURRENT_DB_UPDATE < "002" ) |
---|
88 | { |
---|
89 | require_once("common/includes/class.item.php"); |
---|
90 | $SalvagerGroup = item::get_group_id("Salvager I"); |
---|
91 | update_slot_of_group($SalvagerGroup,2,1); |
---|
92 | config::set("DBUpdate","002"); |
---|
93 | } |
---|
94 | } |
---|
95 | |
---|
96 | function update003(){ |
---|
97 | // Warefare Links and Command Prozessor were midslot items in install file, should be high slot |
---|
98 | if (CURRENT_DB_UPDATE < "003" ) |
---|
99 | { |
---|
100 | require_once("common/includes/class.item.php"); |
---|
101 | $WarfareLinkGroup = item::get_group_id("Skirmish Warfare Link - Rapid Deployment"); |
---|
102 | update_slot_of_group($WarfareLinkGroup,2,1); |
---|
103 | config::set("DBUpdate","003"); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | function update004(){ |
---|
108 | // new trinity ships are wrong saved as T1 shipes |
---|
109 | if (CURRENT_DB_UPDATE < "004" ) |
---|
110 | { |
---|
111 | $qry = new DBQuery(); |
---|
112 | |
---|
113 | $query = "UPDATE kb3_ships |
---|
114 | INNER JOIN kb3_ship_classes ON scl_id = shp_class |
---|
115 | SET shp_techlevel = 2 |
---|
116 | WHERE scl_class IN ('Electronic Attack Ship','Heavy Interdictor','Black Ops','Marauder','Heavy Interdictor','Jump Freighter') |
---|
117 | AND shp_techlevel = 1;"; |
---|
118 | $qry->execute($query); |
---|
119 | config::set("DBUpdate","004"); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | function update005(){ |
---|
124 | // Blueprints and small fixes |
---|
125 | if (CURRENT_DB_UPDATE < "005" ) |
---|
126 | { |
---|
127 | $qry = new DBQuery(); |
---|
128 | $query = <<<EOF |
---|
129 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29249, 105, 'Magnate Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
130 | |
---|
131 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29267, 111, 'Apotheosis Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
132 | |
---|
133 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29338, 106, 'Omen Navy Issue Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
134 | |
---|
135 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29339, 106, 'Scythe Fleet Issue Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
136 | |
---|
137 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29341, 106, 'Osprey Navy Issue Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
138 | |
---|
139 | INSERT INTO `kb3_invtypes` (`typeID`, `groupID`, `typeName`, `description`, `icon`, `radius`, `mass`, `volume`, `capacity`, `portionSize`, `raceID`, `basePrice`, `marketGroupID`) VALUES (29345, 106, 'Exequror Navy Issue Blueprint', '', '0', 0, 0, 0.01, 0, 1, 0, 0, 0); |
---|
140 | |
---|
141 | INSERT INTO `kb3_dgmtypeattributes` (`typeID`, `attributeID`, `value`) VALUES ('29249', '422', '1'); |
---|
142 | |
---|
143 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='180'; |
---|
144 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='181'; |
---|
145 | |
---|
146 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='182'; |
---|
147 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='183'; |
---|
148 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='184'; |
---|
149 | |
---|
150 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='228'; |
---|
151 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='229'; |
---|
152 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='230'; |
---|
153 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='231'; |
---|
154 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='232'; |
---|
155 | |
---|
156 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='277'; |
---|
157 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='278'; |
---|
158 | UPDATE `kb3_dgmattributetypes` SET `icon` = '50_11' WHERE `attributeID`='279'; |
---|
159 | |
---|
160 | UPDATE `kb3_dgmattributetypes` SET `icon` = '04_12' WHERE `attributeID`='193'; |
---|
161 | UPDATE `kb3_dgmattributetypes` SET `icon` = '04_12' WHERE `attributeID`='235'; |
---|
162 | |
---|
163 | UPDATE `kb3_dgmattributetypes` SET `icon` = '22_14' WHERE `attributeID`='108'; |
---|
164 | UPDATE `kb3_dgmattributetypes` SET `icon` = '22_14' WHERE `attributeID`='197'; |
---|
165 | |
---|
166 | UPDATE `kb3_dgmattributetypes` SET `icon` = '07_15' WHERE `attributeID`='137'; |
---|
167 | |
---|
168 | UPDATE `kb3_dgmattributetypes` SET `icon` = '24_01' WHERE `attributeID`='77'; |
---|
169 | |
---|
170 | UPDATE `kb3_dgmattributetypes` SET `icon` = '22_08' WHERE `attributeID`='153'; |
---|
171 | |
---|
172 | UPDATE `kb3_dgmattributetypes` SET `icon` = '07_15' WHERE `attributeID`='484'; |
---|
173 | EOF; |
---|
174 | |
---|
175 | $qry->execute($query); |
---|
176 | config::set("DBUpdate","005"); |
---|
177 | |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | function update007() |
---|
182 | { |
---|
183 | //Checking if this Update already done |
---|
184 | if (CURRENT_DB_UPDATE < "007" ) |
---|
185 | { |
---|
186 | $qry = new DBQuery(true); |
---|
187 | // Add columns for external ids. |
---|
188 | $qry->execute("SHOW COLUMNS FROM kb3_alliances LIKE 'all_external_id'"); |
---|
189 | $testresult = $qry->recordCount(); |
---|
190 | if(!$testresult) |
---|
191 | { |
---|
192 | $sql = "ALTER TABLE `kb3_alliances` ". |
---|
193 | "ADD `all_external_id` INT( 11 ) UNSIGNED NULL ". |
---|
194 | "DEFAULT NULL , ADD UNIQUE ( all_external_id )"; |
---|
195 | $qry->execute($sql); |
---|
196 | } |
---|
197 | |
---|
198 | $qry->execute("SHOW COLUMNS FROM kb3_corps LIKE 'crp_external_id'"); |
---|
199 | $testresult = $qry->recordCount(); |
---|
200 | if(!$testresult) |
---|
201 | { |
---|
202 | $sql = "ALTER TABLE `kb3_corps` ". |
---|
203 | "ADD `crp_external_id` INT( 11 ) UNSIGNED NULL ". |
---|
204 | "DEFAULT NULL , ADD UNIQUE ( crp_external_id )"; |
---|
205 | $qry->execute($sql); |
---|
206 | } |
---|
207 | |
---|
208 | /* |
---|
209 | * Needs more code changes first to change |
---|
210 | * plt_externalid == 0 checks to plt_externalid IS NULL |
---|
211 | * |
---|
212 | $sql = " ALTER TABLE `kb3_pilots` CHANGE `plt_externalid` `plt_externalid` INT( 11 ) UNSIGNED NULL DEFAULT NULL "; |
---|
213 | $qry->execute($sql); |
---|
214 | |
---|
215 | // Remove bugged non-unique external ids. |
---|
216 | $sql = "UPDATE kb3_pilots old JOIN ". |
---|
217 | "(SELECT DISTINCT a.plt_id ". |
---|
218 | "FROM kb3_pilots a, kb3_pilots b ". |
---|
219 | "WHERE a.plt_externalid = b.plt_externalid ". |
---|
220 | "AND a.plt_id <> b.plt_id AND a.plt_externalid > 0) new ". |
---|
221 | "ON old.plt_id = new.plt_id SET old.plt_externalid = 0 "; |
---|
222 | $qry->execute($sql); |
---|
223 | |
---|
224 | $sql = "UPDATE kb3_pilots set plt_externalid = NULL WHERE plt_externalid = 0"; |
---|
225 | if( $qry->execute($sql)) |
---|
226 | { |
---|
227 | $qry->execute(" ALTER TABLE `kb3_pilots` ". |
---|
228 | "DROP INDEX `plt_externalid` , ". |
---|
229 | "ADD UNIQUE `plt_externalid` ( `plt_externalid` ) "); |
---|
230 | } |
---|
231 | */ |
---|
232 | $qry->execute("SHOW COLUMNS FROM kb3_kills LIKE 'kll_external_id'"); |
---|
233 | $testresult = $qry->recordCount(); |
---|
234 | if(!$testresult) |
---|
235 | { |
---|
236 | $sql = "ALTER TABLE `kb3_kills` ". |
---|
237 | "ADD `kll_external_id` INT( 11 ) UNSIGNED NULL ". |
---|
238 | "DEFAULT NULL , ADD UNIQUE ( kll_external_id )"; |
---|
239 | $qry->execute($sql); |
---|
240 | } |
---|
241 | // Add isk loss column to kb3_kills |
---|
242 | $qry->execute("SHOW COLUMNS FROM kb3_kills LIKE 'kll_isk_loss'"); |
---|
243 | $sql = "ALTER TABLE `kb3_kills` ADD `kll_isk_loss` FLOAT NOT NULL DEFAULT '0'"; |
---|
244 | if(!$qry->recordCount()) $qry->execute($sql); |
---|
245 | // Update price with items destroyed and ship value, excluding |
---|
246 | // blueprints since default cost is for BPO and BPC looks identical |
---|
247 | $sql = "CREATE TABLE IF NOT EXISTS `tmp_pricing` ( |
---|
248 | `kll_id` int(11) NOT NULL DEFAULT '0', |
---|
249 | `ship` float NOT NULL DEFAULT '0', |
---|
250 | `destroyed` float NOT NULL DEFAULT '0', |
---|
251 | `dropped` float NOT NULL DEFAULT '0', |
---|
252 | PRIMARY KEY (`kll_id`), |
---|
253 | KEY `ship` (`ship`), |
---|
254 | KEY `destroyed` (`destroyed`), |
---|
255 | KEY `dropped` (`dropped`) |
---|
256 | ) ENGINE=MyISAM"; |
---|
257 | $qry->execute($sql); |
---|
258 | $qry->execute('SELECT * FROM tmp_pricing limit 1'); |
---|
259 | if(!$qry->recordCount()) $qry->execute("INSERT INTO tmp_pricing select kll_id,0,0,0 FROM kb3_kills"); |
---|
260 | $sql = "update tmp_pricing inner join kb3_kills on kb3_kills.kll_id = tmp_pricing.kll_id |
---|
261 | INNER JOIN kb3_ships ON kb3_ships.shp_id = kll_ship_id |
---|
262 | LEFT JOIN kb3_ships_values ON kb3_ships_values.shp_id = kll_ship_id |
---|
263 | set ship = if(isnull(shp_value),shp_baseprice,shp_value) |
---|
264 | where ship = 0"; |
---|
265 | $qry->execute($sql); |
---|
266 | $sql = "UPDATE tmp_pricing |
---|
267 | INNER JOIN (SELECT itd_kll_id, |
---|
268 | sum(if(typeName LIKE '%Blueprint%',0,if(isnull(itd_quantity), |
---|
269 | 0,itd_quantity * if(price = 0 OR isnull(price),basePrice,price)))) |
---|
270 | AS killcost |
---|
271 | FROM kb3_items_destroyed |
---|
272 | LEFT JOIN kb3_item_price ON kb3_item_price.typeID = itd_itm_id |
---|
273 | LEFT JOIN kb3_invtypes ON itd_itm_id = kb3_invtypes.typeID |
---|
274 | GROUP BY itd_kll_id) cost on kll_id = itd_kll_id |
---|
275 | SET destroyed = killcost |
---|
276 | WHERE destroyed = 0"; |
---|
277 | $qry->execute($sql); |
---|
278 | if(config::get(kd_droptototal)) |
---|
279 | $sql = "UPDATE tmp_pricing |
---|
280 | INNER JOIN (SELECT itd_kll_id, |
---|
281 | sum(if(typeName LIKE '%Blueprint%',0,if(isnull(itd_quantity), |
---|
282 | 0,itd_quantity * if(price = 0 OR isnull(price),basePrice,price)))) |
---|
283 | AS killcost |
---|
284 | FROM kb3_items_dropped |
---|
285 | LEFT JOIN kb3_item_price ON kb3_item_price.typeID = itd_itm_id |
---|
286 | LEFT JOIN kb3_invtypes ON itd_itm_id = kb3_invtypes.typeID |
---|
287 | GROUP BY itd_kll_id) cost on kll_id = itd_kll_id |
---|
288 | SET dropped = killcost |
---|
289 | WHERE dropped = 0"; |
---|
290 | $qry->execute($sql); |
---|
291 | $qry->execute('UPDATE kb3_kills inner join tmp_pricing |
---|
292 | ON kb3_kills.kll_id = tmp_pricing.kll_id SET kll_isk_loss = ship + destroyed + dropped'); |
---|
293 | $qry->execute('DROP TABLE tmp_pricing'); |
---|
294 | $qry->execute("SHOW COLUMNS FROM kb3_kills LIKE 'kll_fb_crp_id'"); |
---|
295 | if($qry->recordCount()) $qry->execute("ALTER TABLE `kb3_kills` DROP `kll_fb_crp_id`"); |
---|
296 | $qry->execute("SHOW COLUMNS FROM kb3_kills LIKE 'kll_fb_all_id'"); |
---|
297 | if($qry->recordCount()) $qry->execute("ALTER TABLE `kb3_kills` DROP `kll_fb_all_id`"); |
---|
298 | // Drop unused columns |
---|
299 | $qry->execute("SHOW COLUMNS FROM kb3_corps LIKE 'crp_trial'"); |
---|
300 | if($qry->recordCount()) $qry->execute("ALTER TABLE kb3_corps DROP crp_trial"); |
---|
301 | $qry->execute("SHOW COLUMNS FROM kb3_pilots LIKE 'plt_killpoints'"); |
---|
302 | if($qry->recordCount()) $qry->execute("ALTER TABLE kb3_pilots DROP plt_killpoints"); |
---|
303 | $qry->execute("SHOW COLUMNS FROM kb3_pilots LIKE 'plt_losspoints'"); |
---|
304 | if($qry->recordCount()) $qry->execute("ALTER TABLE kb3_pilots DROP plt_losspoints"); |
---|
305 | |
---|
306 | // Add corp and alliance index to kb3_inv_detail |
---|
307 | $qry->execute("SHOW INDEX FROM kb3_inv_detail"); |
---|
308 | |
---|
309 | $indexcexists = false; |
---|
310 | $indexaexists = false; |
---|
311 | while($testresult = $qry->getRow()) |
---|
312 | if($testresult['Column_name'] == 'ind_crp_id') |
---|
313 | $indexcexists = true; |
---|
314 | if($testresult['Column_name'] == 'ind_all_id') |
---|
315 | $indexaexists = true; |
---|
316 | if(!indexcexists) |
---|
317 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_crp_id` ) "); |
---|
318 | if(!indexaexists) |
---|
319 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_all_id` ) "); |
---|
320 | // Add table for api cache |
---|
321 | $sql = "CREATE TABLE IF NOT EXISTS `kb3_apicache` ( |
---|
322 | `cfg_site` varchar(16) NOT NULL default '', |
---|
323 | `cfg_key` varchar(32) NOT NULL default '', |
---|
324 | `cfg_value` text NOT NULL, |
---|
325 | PRIMARY KEY (`cfg_site`,`cfg_key`) |
---|
326 | )"; |
---|
327 | $qry->execute($sql); |
---|
328 | $qry->execute("CREATE TABLE IF NOT EXISTS `kb3_apilog` ( |
---|
329 | `log_site` VARCHAR( 20 ) NOT NULL , |
---|
330 | `log_keyname` VARCHAR( 20 ) NOT NULL , |
---|
331 | `log_posted` INT NOT NULL , |
---|
332 | `log_errors` INT NOT NULL , |
---|
333 | `log_ignored` INT NOT NULL , |
---|
334 | `log_verified` INT NOT NULL , |
---|
335 | `log_totalmails` INT NOT NULL , |
---|
336 | `log_source` VARCHAR( 20 ) NOT NULL , |
---|
337 | `log_type` VARCHAR( 20 ) NOT NULL , |
---|
338 | `log_timestamp` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' |
---|
339 | ) ENGINE = MYISAM "); |
---|
340 | |
---|
341 | // set update complete |
---|
342 | config::set('API_DBUpdate', '1'); |
---|
343 | |
---|
344 | // Add subsystem slot |
---|
345 | $qry->execute("SELECT 1 FROM kb3_item_locations WHERE itl_id = 7"); |
---|
346 | if(!$qry->recordCount()) |
---|
347 | { |
---|
348 | $qry->execute("INSERT INTO `kb3_item_locations` (`itl_id`, `itl_location`) VALUES(7, 'Subsystem Slot')"); |
---|
349 | $qry->execute("UPDATE `kb3_item_types` SET `itt_slot` = '7' WHERE `kb3_item_types`.`itt_id` = 954 LIMIT 1"); |
---|
350 | $qry->execute("UPDATE `kb3_item_types` SET `itt_slot` = '7' WHERE `kb3_item_types`.`itt_id` = 955 LIMIT 1"); |
---|
351 | $qry->execute("UPDATE `kb3_item_types` SET `itt_slot` = '7' WHERE `kb3_item_types`.`itt_id` = 956 LIMIT 1"); |
---|
352 | $qry->execute("UPDATE `kb3_item_types` SET `itt_slot` = '7' WHERE `kb3_item_types`.`itt_id` = 957 LIMIT 1"); |
---|
353 | $qry->execute("UPDATE `kb3_item_types` SET `itt_slot` = '7' WHERE `kb3_item_types`.`itt_id` = 958 LIMIT 1"); |
---|
354 | } |
---|
355 | $qry->execute("TRUNCATE kb3_inv_all"); |
---|
356 | $qry->execute("TRUNCATE kb3_inv_crp"); |
---|
357 | $qry->execute("TRUNCATE kb3_inv_plt"); |
---|
358 | |
---|
359 | config::set("DBUpdate","007"); |
---|
360 | } |
---|
361 | } |
---|
362 | // Add unique name indices to alliance, corp and pilot |
---|
363 | // Check kb3_inv_detail has correct indices |
---|
364 | function update008() |
---|
365 | { |
---|
366 | //Checking if this Update already done |
---|
367 | if (CURRENT_DB_UPDATE < "008" ) |
---|
368 | { |
---|
369 | if(!config::get('008updatestatus')) config::set('008updatestatus',0); |
---|
370 | $qry = new DBQuery(true); |
---|
371 | |
---|
372 | if(config::get('008updatestatus') <1) |
---|
373 | { |
---|
374 | // Add pilot, corp and alliance index to kb3_inv_detail |
---|
375 | // Incomplete in update007 |
---|
376 | $qry->execute("SHOW INDEXES FROM kb3_inv_detail"); |
---|
377 | $indexcexists = false; |
---|
378 | $indexaexists = false; |
---|
379 | $indexpexists = false; |
---|
380 | $indexkexists = false; |
---|
381 | while($testresult = $qry->getRow()) |
---|
382 | { |
---|
383 | if($testresult['Column_name'] == 'ind_kll_id' && $testresult['Seq_in_index'] == 1) |
---|
384 | $indexkexists = true; |
---|
385 | if($testresult['Column_name'] == 'ind_crp_id' && $testresult['Seq_in_index'] == 1) |
---|
386 | $indexcexists = true; |
---|
387 | if($testresult['Column_name'] == 'ind_all_id' && $testresult['Seq_in_index'] == 1) |
---|
388 | $indexaexists = true; |
---|
389 | if($testresult['Column_name'] == 'ind_plt_id' && $testresult['Seq_in_index'] == 1) |
---|
390 | $indexpexists = true; |
---|
391 | } |
---|
392 | // |
---|
393 | if(!indexkexists) |
---|
394 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_kll_id`, `ind_order` ) "); |
---|
395 | if(!indexcexists) |
---|
396 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_crp_id` ) "); |
---|
397 | if(!indexaexists) |
---|
398 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_all_id` ) "); |
---|
399 | if(!indexpexists) |
---|
400 | $qry->execute("ALTER TABLE `kb3_inv_detail` ADD INDEX ( `ind_plt_id` ) "); |
---|
401 | config::set('008updatestatus', 1); |
---|
402 | } |
---|
403 | |
---|
404 | $qry->execute("SHOW INDEXES FROM kb3_corps"); |
---|
405 | $indexaexists = false; |
---|
406 | while($testresult = $qry->getRow()) |
---|
407 | { |
---|
408 | if($testresult['Column_name'] == 'crp_name' && $testresult['Non_unique'] == 0) |
---|
409 | $indexcexists = true; |
---|
410 | } |
---|
411 | if(!$indexcexists) |
---|
412 | { |
---|
413 | $sqlcrp = 'select a.crp_id as newid, b.crp_id as oldid from kb3_corps a, kb3_corps b where a.crp_name = b.crp_name and a.crp_id < b.crp_id'; |
---|
414 | |
---|
415 | if(config::get('008updatestatus') <2) |
---|
416 | { |
---|
417 | $qry->execute('update kb3_inv_detail join ('.$sqlcrp.') c on c.oldid = ind_crp_id set ind_crp_id = c.newid'); |
---|
418 | config::set('008updatestatus', 2); |
---|
419 | } |
---|
420 | if(config::get('008updatestatus') <3) |
---|
421 | { |
---|
422 | $qry->execute('update kb3_pilots join ('.$sqlcrp.') c on (c.oldid = plt_crp_id) set plt_crp_id = c.newid'); |
---|
423 | config::set('008updatestatus', 3); |
---|
424 | } |
---|
425 | if(config::get('008updatestatus') <4) |
---|
426 | { |
---|
427 | $qry->execute('update kb3_kills join ('.$sqlcrp.') c on (c.oldid = kll_crp_id) set kll_crp_id = c.newid'); |
---|
428 | config::set('008updatestatus', 4); |
---|
429 | } |
---|
430 | |
---|
431 | if(config::get('008updatestatus') <6) |
---|
432 | { |
---|
433 | $qry->execute('delete b from kb3_corps a, kb3_corps b where a.crp_name = b.crp_name and a.crp_id < b.crp_id'); |
---|
434 | config::set('008updatestatus', 6); |
---|
435 | } |
---|
436 | if(config::get('008updatestatus') <7) |
---|
437 | { |
---|
438 | $qry->execute("SHOW INDEXES FROM kb3_corps"); |
---|
439 | $indexcexists = false; |
---|
440 | while($testresult = $qry->getRow()) |
---|
441 | { |
---|
442 | if($testresult['Column_name'] == 'crp_name' && $testresult['Seq_in_index'] == 1) |
---|
443 | { |
---|
444 | $indexcname = $testresult['Key_name']; |
---|
445 | $indexcexists = true; |
---|
446 | } |
---|
447 | // Don't replace a custom multi-column index. |
---|
448 | elseif($testresult['Key_name'] == $indexcname && $testresult['Seq_in_index'] == 2) |
---|
449 | $indexcexists = false; |
---|
450 | } |
---|
451 | if(!$indexcexists) $qry->execute("ALTER TABLE `kb3_corps` DROP INDEX `".$indexcname."`"); |
---|
452 | $qry->execute("ALTER TABLE `kb3_corps` ADD UNIQUE INDEX ( `crp_name` ) "); |
---|
453 | config::set('008updatestatus', 7); |
---|
454 | } |
---|
455 | } |
---|
456 | // Make kb3_alliances.all_name unique without losing kills |
---|
457 | $qry->execute("SHOW INDEXES FROM kb3_alliances"); |
---|
458 | $indexaexists = false; |
---|
459 | while($testresult = $qry->getRow()) |
---|
460 | { |
---|
461 | if($testresult['Column_name'] == 'all_name' && $testresult['Non_unique'] == 0) |
---|
462 | $indexaexists = true; |
---|
463 | } |
---|
464 | if(!$indexaexists) |
---|
465 | { |
---|
466 | $sqlall = 'select a.all_id as newid, b.all_id as oldid from kb3_alliances a, kb3_alliances b where a.all_name = b.all_name and a.all_id < b.all_id'; |
---|
467 | if(config::get('008updatestatus') <8) |
---|
468 | { |
---|
469 | $qry->execute('update kb3_inv_detail join ('.$sqlall.') c on c.oldid = ind_all_id set ind_all_id = c.newid'); |
---|
470 | config::set('008updatestatus', 8); |
---|
471 | } |
---|
472 | if(config::get('008updatestatus') <9) |
---|
473 | { |
---|
474 | $qry->execute('update kb3_corps join ('.$sqlall.') c on (c.oldid = crp_all_id) set crp_all_id = c.newid'); |
---|
475 | config::set('008updatestatus', 9); |
---|
476 | } |
---|
477 | if(config::get('008updatestatus') <10) |
---|
478 | { |
---|
479 | $qry->execute('update kb3_kills join ('.$sqlall.') c on (c.oldid = kll_all_id) set kll_all_id = c.newid'); |
---|
480 | config::set('008updatestatus', 10); |
---|
481 | } |
---|
482 | |
---|
483 | if(config::get('008updatestatus') <12) |
---|
484 | { |
---|
485 | $qry->execute('delete b from kb3_alliances a, kb3_alliances b where a.all_name = b.all_name and a.all_id < b.all_id'); |
---|
486 | config::set('008updatestatus', 12); |
---|
487 | } |
---|
488 | if(config::get('008updatestatus') <13) |
---|
489 | { |
---|
490 | $qry->execute("SHOW INDEXES FROM kb3_alliances"); |
---|
491 | $indexaexists = false; |
---|
492 | while($testresult = $qry->getRow()) |
---|
493 | { |
---|
494 | if($testresult['Column_name'] == 'all_name' && $testresult['Seq_in_index'] == 1) |
---|
495 | { |
---|
496 | $indexaname = $testresult['Key_name']; |
---|
497 | $indexaexists = true; |
---|
498 | } |
---|
499 | // Don't replace a custom multi-column index. |
---|
500 | elseif($testresult['Key_name'] == $indexaname && $testresult['Seq_in_index'] == 2) |
---|
501 | $indexaexists = false; |
---|
502 | } |
---|
503 | if($indexaexists) $qry->execute("ALTER TABLE `kb3_alliances` DROP INDEX `".$indexaname."`"); |
---|
504 | $qry->execute("ALTER TABLE `kb3_alliances` ADD UNIQUE INDEX ( `all_name` ) "); |
---|
505 | config::set('008updatestatus', 13); |
---|
506 | } |
---|
507 | } |
---|
508 | |
---|
509 | // Make kb3_pilots.plt_name unique without losing kills |
---|
510 | $qry->execute("SHOW INDEXES FROM kb3_pilots"); |
---|
511 | $indexaexists = false; |
---|
512 | while($testresult = $qry->getRow()) |
---|
513 | { |
---|
514 | if($testresult['Column_name'] == 'plt_name' && $testresult['Non_unique'] == 0) |
---|
515 | $indexaexists = true; |
---|
516 | } |
---|
517 | if(!$indexaexists) |
---|
518 | { |
---|
519 | $sqlplt = 'select a.plt_id as newid, b.plt_id as oldid from kb3_pilots a, kb3_pilots b where a.plt_name = b.plt_name and a.plt_id < b.plt_id'; |
---|
520 | if(config::get('008updatestatus') <14) |
---|
521 | { |
---|
522 | $qry->execute('update kb3_inv_detail join ('.$sqlplt.') c on c.oldid = ind_plt_id set ind_plt_id = c.newid'); |
---|
523 | config::set('008updatestatus', 14); |
---|
524 | } |
---|
525 | if(config::get('008updatestatus') <15) |
---|
526 | { |
---|
527 | $qry->execute('update kb3_kills join ('.$sqlplt.') c on (c.oldid = kll_victim_id) set kll_victim_id = c.newid'); |
---|
528 | config::set('008updatestatus', 15); |
---|
529 | } |
---|
530 | if(config::get('008updatestatus') <16) |
---|
531 | { |
---|
532 | $qry->execute('update kb3_kills join ('.$sqlplt.') c on (c.oldid = kll_fb_plt_id) set kll_fb_plt_id = c.newid'); |
---|
533 | config::set('008updatestatus', 16); |
---|
534 | } |
---|
535 | if(config::get('008updatestatus') <17) |
---|
536 | { |
---|
537 | $qry->execute('delete b from kb3_pilots a, kb3_pilots b where a.plt_name = b.plt_name and a.plt_id < b.plt_id'); |
---|
538 | config::set('008updatestatus', 17); |
---|
539 | } |
---|
540 | if(config::get('008updatestatus') <18) |
---|
541 | { |
---|
542 | $qry->execute("SHOW INDEXES FROM kb3_pilots"); |
---|
543 | $indexpexists = false; |
---|
544 | while($testresult = $qry->getRow()) |
---|
545 | { |
---|
546 | if($testresult['Column_name'] == 'plt_name' && $testresult['Seq_in_index'] == 1) |
---|
547 | { |
---|
548 | $indexpname = $testresult['Key_name']; |
---|
549 | $indexpexists = true; |
---|
550 | } |
---|
551 | // Don't replace a custom multi-column index. |
---|
552 | elseif($testresult['Key_name'] == $indexpname && $testresult['Seq_in_index'] == 2) |
---|
553 | $indexpexists = false; |
---|
554 | } |
---|
555 | if($indexpexists) $qry->execute("ALTER TABLE `kb3_pilots` DROP INDEX `".$indexpname."`"); |
---|
556 | $qry->execute("ALTER TABLE `kb3_pilots` ADD UNIQUE INDEX ( `plt_name` ) "); |
---|
557 | config::set('008updatestatus', 18); |
---|
558 | } |
---|
559 | } |
---|
560 | config::del("008updatestatus"); |
---|
561 | config::set('cache_update', '*'); |
---|
562 | config::set('cache_time', '10'); |
---|
563 | config::set("DBUpdate", "008"); |
---|
564 | } |
---|
565 | } |
---|
566 | |
---|
567 | function update_slot_of_group($id,$oldSlot = 0 ,$newSlot){ |
---|
568 | $qry = new DBQuery(); |
---|
569 | $query = "UPDATE kb3_item_types |
---|
570 | SET itt_slot = $newSlot WHERE itt_id = $id and itt_slot = $oldSlot;"; |
---|
571 | $qry->execute($query); |
---|
572 | $query = "UPDATE kb3_items_destroyed |
---|
573 | INNER JOIN kb3_invtypes ON groupID = $id AND itd_itm_id = typeID |
---|
574 | SET itd_itl_id = $newSlot |
---|
575 | WHERE itd_itl_id = $oldSlot;"; |
---|
576 | $qry->execute($query); |
---|
577 | |
---|
578 | $query = "UPDATE kb3_items_dropped |
---|
579 | INNER JOIN kb3_invtypes ON groupID = $id AND itd_itm_id = typeID |
---|
580 | SET itd_itl_id = $newSlot |
---|
581 | WHERE itd_itl_id = $oldSlot;"; |
---|
582 | $qry->execute($query); |
---|
583 | } |
---|
584 | |
---|
585 | function move_item_to_group($id,$oldGroup ,$newGroup){ |
---|
586 | $qry = new DBQuery(); |
---|
587 | $query = "UPDATE kb3_invtypes |
---|
588 | SET groupID = $newGroup |
---|
589 | WHERE typeID = $id AND groupID = $oldGroup;"; |
---|
590 | $qry->execute($query); |
---|
591 | } |
---|
592 | |
---|
593 | ?> |
---|