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 | define(LASTEST_DB_UPDATE,"003"); |
---|
15 | |
---|
16 | function updateDB(){ |
---|
17 | // if update nesseary run updates |
---|
18 | if (CURRENT_DB_UPDATE < LASTEST_DB_UPDATE ){ |
---|
19 | update001(); |
---|
20 | update002(); |
---|
21 | update003(); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | function update001(){ |
---|
26 | //Checking if this Update already done |
---|
27 | if (CURRENT_DB_UPDATE < "001" ) |
---|
28 | { |
---|
29 | require_once("common/includes/class.item.php"); |
---|
30 | // Changing ShieldBooster Slot from None to Mid Slot |
---|
31 | $ShieldBoosterGroup = item::get_group_id("Small Shield Booster I"); |
---|
32 | update_slot_of_group($ShieldBoosterGroup,0,2); |
---|
33 | |
---|
34 | // Changing Tracking Scripts Slot from None to Mid Slot |
---|
35 | $ScriptGroupID1 = item::get_group_id("Optimal Range"); |
---|
36 | update_slot_of_group($ScriptGroupID1,0,2); |
---|
37 | |
---|
38 | // Changing Warp Disruption Scripts Slot from None to Mid Slot |
---|
39 | $ScriptGroupID2 = item::get_group_id("Focused Warp Disruption"); |
---|
40 | update_slot_of_group($ScriptGroupID2,0,2); |
---|
41 | |
---|
42 | // Changing Tracking Disruption Scripts Slot from None to Mid Slot |
---|
43 | $ScriptGroupID3 = item::get_group_id("Optimal Range Disruption"); |
---|
44 | update_slot_of_group($ScriptGroupID3,0,2); |
---|
45 | |
---|
46 | // Changing Sensor Booster Scripts Slot from None to Mid Slot |
---|
47 | $ScriptGroupID4 = item::get_group_id("Targeting Range"); |
---|
48 | update_slot_of_group($ScriptGroupID4,0,2); |
---|
49 | |
---|
50 | // Changing Sensor Dampener Scripts Slot from None to Mid Slot |
---|
51 | $ScriptGroupID5 = item::get_group_id("Scan Resolution Dampening"); |
---|
52 | update_slot_of_group($ScriptGroupID5,0,2); |
---|
53 | |
---|
54 | // Changing Energy Weapon Slot from None to High Slot |
---|
55 | $EnergyWeaponGroup = item::get_group_id("Gatling Pulse Laser I"); |
---|
56 | update_slot_of_group($EnergyWeaponGroup,0,1); |
---|
57 | |
---|
58 | // Changing Group of Salvager I to same as Small Tractor Beam I |
---|
59 | $item = new Item(); |
---|
60 | $item->lookup("Salvager I"); |
---|
61 | $SalvagerTypeId = $item->getId(); |
---|
62 | $SalvagerGroup = item::get_group_id("Salvager I"); |
---|
63 | $TractorBeam = item::get_group_id("Small Tractor Beam I"); |
---|
64 | move_item_to_group($SalvagerTypeId,$SalvagerGroup ,$TractorBeam); |
---|
65 | |
---|
66 | //writing Update Status into ConfigDB |
---|
67 | config::set("DBUpdate","001"); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | function update002(){ |
---|
72 | // to correct the already existing Salvager in med slots. |
---|
73 | // missed it in update001 |
---|
74 | if (CURRENT_DB_UPDATE < "002" ) |
---|
75 | { |
---|
76 | require_once("common/includes/class.item.php"); |
---|
77 | $SalvagerGroup = item::get_group_id("Salvager I"); |
---|
78 | update_slot_of_group($SalvagerGroup,2,1); |
---|
79 | config::set("DBUpdate","002"); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | function update003(){ |
---|
84 | // Warefare Links and Command Prozessor were midslot items in install file, should be high slot |
---|
85 | if (CURRENT_DB_UPDATE < "003" ) |
---|
86 | { |
---|
87 | require_once("common/includes/class.item.php"); |
---|
88 | $WarfareLinkGroup = item::get_group_id("Skirmish Warfare Link - Rapid Deployment"); |
---|
89 | update_slot_of_group($WarfareLinkGroup,2,1); |
---|
90 | config::set("DBUpdate","003"); |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | function update_slot_of_group($id,$oldSlot = 0 ,$newSlot){ |
---|
95 | $qry = new DBQuery(); |
---|
96 | $query = "UPDATE kb3_item_types |
---|
97 | SET itt_slot = $newSlot WHERE itt_id = $id and itt_slot = $oldSlot;"; |
---|
98 | $qry->execute($query); |
---|
99 | $query = "UPDATE kb3_items_destroyed |
---|
100 | INNER JOIN kb3_invtypes ON groupID = $id AND itd_itm_id = typeID |
---|
101 | SET itd_itl_id = $newSlot |
---|
102 | WHERE itd_itl_id = $oldSlot;"; |
---|
103 | $qry->execute($query); |
---|
104 | |
---|
105 | $query = "UPDATE kb3_items_dropped |
---|
106 | INNER JOIN kb3_invtypes ON groupID = $id AND itd_itm_id = typeID |
---|
107 | SET itd_itl_id = $newSlot |
---|
108 | WHERE itd_itl_id = $oldSlot;"; |
---|
109 | $qry->execute($query); |
---|
110 | } |
---|
111 | |
---|
112 | function move_item_to_group($id,$oldGroup ,$newGroup){ |
---|
113 | $qry = new DBQuery(); |
---|
114 | $query = "UPDATE kb3_invtypes |
---|
115 | SET groupID = $newGroup |
---|
116 | WHERE typeID = $id AND groupID = $oldGroup;"; |
---|
117 | $qry->execute($query); |
---|
118 | } |
---|
119 | |
---|
120 | ?> |
---|