root/dev/install/install_step4_tblchk.php @ 133

Revision 133, 4.9 KB (checked in by exi, 14 years ago)

Reduced one potential sql-bug.
Added ability to identify items as t2 via their techlevel rather than just 'II'.
Fixed item location 0 to not cause skipping that item.
Added anzahl/quantity-replace for the german killpreparser.
Fixed final blow award to show correct numbers.
Removed unnecessary code from db.php.
Added a table data check to the sql importer and made the importer more verbose, this should minimize support requests caused by empty table data.
Fixed a small misalignment of the comment block.

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