root/dev/common/autoupgrade.php @ 95

Revision 95, 5.0 KB (checked in by exi, 16 years ago)

Added Logout option to admin menu.
Autoupgrade now checks for index rather than just creating it.
Fixed that no system error for contracts during upgrade.
Added a warning to the installer in case it doesnt get any id on step5.

Line 
1<?php
2require_once("db.php");
3function check_commenttable()
4{
5    $qry = new DBQuery();
6    $query = 'select count(*) from kb3_comments';
7    $result = mysql_query($query);
8    if ($result)
9    {
10        check_commenttablerow();
11        return;
12    }
13    $query = 'CREATE TABLE `kb3_comments` (
14`ID` INT NOT NULL AUTO_INCREMENT ,
15`kll_id` INT NOT NULL ,
16`comment` TEXT NOT NULL ,
17`name` TINYTEXT NOT NULL ,
18`posttime` TIMESTAMP DEFAULT \'0000-00-00 00:00:00\' NOT NULL,
19PRIMARY KEY ( `ID` )
20) TYPE = MYISAM';
21    $qry->execute($query);
22}
23
24function check_commenttablerow()
25{
26    $qry = new DBQuery();
27    $query = 'select posttime from kb3_comments limit 1';
28    $result = mysql_query($query);
29    if ($result)
30    {
31        $query = 'ALTER TABLE `kb3_comments` CHANGE `ID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT';
32        $qry->execute($query);
33        return;
34    }
35    $query = 'ALTER TABLE `kb3_comments` ADD `posttime` TIMESTAMP DEFAULT \'0000-00-00 00:00:00\' NOT NULL';
36    $qry->execute($query);
37}
38
39function check_shipvaltable()
40{
41    $qry = new DBQuery();
42    $query = 'select count(*) from kb3_ships_values';
43    $result = mysql_query($query);
44    if ($result)
45    {
46        return;
47    }
48    $query = 'CREATE TABLE `kb3_ships_values` (
49`shp_id` INT( 11 ) NOT NULL ,
50`shp_value` BIGINT( 4 ) NOT NULL ,
51INDEX ( `shp_id` )
52) TYPE = MYISAM ;';
53    $qry->execute($query);
54    $qry->execute('ALTER TABLE `kb3_ships_values` ADD PRIMARY KEY ( `shp_id` ) ');
55    $qry->execute('UPDATE kb3_ships set shp_class = 8 WHERE shp_id=257 limit 1');
56    $qry->execute('UPDATE kb3_ships set shp_class = 8 WHERE shp_id=252 limit 1');
57    $qry->execute('UPDATE kb3_ships set shp_class = 4 WHERE shp_id=266 limit 1');
58    $qry->execute('UPDATE kb3_ships set shp_class = 4 WHERE shp_id=275 limit 1');
59    $qry->execute('UPDATE kb3_ships set shp_class = 4 WHERE shp_id=272 limit 1');
60    $qry->execute('UPDATE kb3_ships set shp_class = 4 WHERE shp_id=246 limit 1');
61    $qry->execute('UPDATE kb3_ships set shp_class = 4 WHERE shp_id=249 limit 1');
62    $qry->execute('UPDATE kb3_ships set shp_techlevel = 2 where shp_class = 22');
63}
64
65function check_invdetail()
66{
67    $qry = new DBQuery();
68    $query = 'select ind_sec_status from kb3_inv_detail limit 1';
69    $qry->execute($query);
70    $len = mysql_field_len($qry->resid_,0);
71    if ($len == 4)
72    {
73        $query = 'ALTER TABLE `kb3_inv_detail` CHANGE `ind_sec_status` `ind_sec_status` VARCHAR(5)';
74        $qry->execute($query);
75    }
76}
77
78function check_pilots()
79{
80    $qry = new DBQuery();
81    $query = 'select plt_name from kb3_pilots limit 1';
82    $qry->execute($query);
83    $len = mysql_field_len($qry->resid_,0);
84    if ($len == 32)
85    {
86        $query = 'ALTER TABLE `kb3_pilots` CHANGE `plt_name` `plt_name` VARCHAR(64) NOT NULL';
87        $qry->execute($query);
88    }
89}
90
91function check_contracts()
92{
93    $qry = new DBQuery();
94    $query = 'select ctd_sys_id from kb3_contract_details limit 1';
95    $result = mysql_query($query);
96    if ($result)
97    {
98        return;
99    }
100    $qry->execute('ALTER TABLE `kb3_contract_details` ADD `ctd_sys_id` INT(11) NOT NULL DEFAULT \'0\'');
101
102    $qry->execute('SHOW columns from `kb3_contract_details` like \'ctd_ctr_id\'');
103    $arr = $qry->getRow();
104    if ($arr['Key'] == 'PRI')
105    {
106        return;
107    }
108    $qry->execute('ALTER TABLE `kb3_contract_details` ADD INDEX (`ctd_ctr_id`) ');
109}
110function check_index()
111{
112    $qry = new DBQuery();
113    $qry->execute('SHOW columns from kb3_item_types like \'itt_id\'');
114    $arr = $qry->getRow();
115    if ($arr['Key'] == 'PRI')
116    {
117        return;
118    }
119    $qry->execute('ALTER TABLE `kb3_item_types` ADD PRIMARY KEY ( `itt_id` ) ');
120}
121function check_tblstrct1()
122{
123    $qry = new DBQuery();
124    $query = 'select shp_description from kb3_ships limit 1';
125    $result = mysql_query($query);
126    if (!$result)
127    {
128        return;
129    }
130    $query = 'ALTER TABLE `kb3_ships` DROP `shp_description`';
131    $qry->execute($query);
132}
133function check_tblstrct2()
134{
135    $qry = new DBQuery();
136    $query = 'select itm_description from kb3_items limit 1';
137    $result = mysql_query($query);
138    if (!$result)
139    {
140        return;
141    }
142    $query = 'ALTER TABLE `kb3_items` DROP `itm_description`';
143    $qry->execute($query);
144}
145function check_tblstrct3()
146{
147    $qry = new DBQuery();
148    $query = 'select Value from kb3_items limit 1';
149    $result = mysql_query($query);
150    if ($result)
151    {
152        $query = 'ALTER TABLE `kb3_items` CHANGE `Value` `itm_value` INT( 11 ) NOT NULL DEFAULT \'0\'';
153        $qry->execute($query);
154    }
155}
156function check_tblstrct4()
157{
158    $qry = new DBQuery();
159    $query = 'select itm_value from kb3_items limit 1';
160    $result = mysql_query($query);
161    if ($result)
162    {
163        return;
164    }
165    $query = 'ALTER TABLE `kb3_items` ADD `itm_value` INT( 11 ) NOT NULL DEFAULT \'0\'';
166    $qry->execute($query);
167    $qry->execute('ALTER TABLE `kb3_items` CHANGE `itm_externalid` `itm_externalid` INT( 11 ) NOT NULL DEFAULT \'0\'');
168}
169?>
Note: See TracBrowser for help on using the browser.