1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
<html> <head> <title>upgrading database</title> </head> <body> <? function dosquery($query) { // Actually do some error checking $result=doquery($query); if ($result==FALSE) { die("The following error occured: <BR /><BR />\n".mysql_error()."\n\n</body></html>\n"); } } require("inc/db.php");
// 0.5 pre3
$test=@doquery("select count(*) from config");
if (mysql_errno()=="1146") { // 1146 = Table not found // Config table does not exist. Create and populate. dosquery("create table config (item varchar(255), value varchar(255), comments varchar(255))"); $settings=array(); $settings[]=array("item" => "sitename", "value" => "An Unconfigured DVD Database", "comments" => ""); $settings[]=array("item" => "webmaster", "value" => "your@email.address.here", "comments" => ""); $settings[]=array("item" => "home", "value" => "http://your.site.com/dvddb", "comments" => "No trailing slash on the URL"); $settings[]=array("item" => "approvalemail", "value" => "approvalmail@yourdomain.com", "comments" => "Address to which new user requests are sent"); $settings[]=array("item" => "siteemail", "value" => "siteemail@yourdomain.com", "comments" => "Address from which site emails are sent"); $settings[]=array("item" => "lowdate", "value" => "1950", "comments" => "Lowest date for date dropdowns"); $settings[]=array("item" => "highdate", "value" => "2005", "comments" => "Highest date for date dropdowns"); $settings[]=array("item" => "defregion", "value" => "1", "comments" => "Default region for new DVDs"); $settings[]=array("item" => "showimdb", "value" => "1", "comments" => "Generate auto-IMDb link"); $settings[]=array("item" => "numperpage", "value" => "20", "comments" => "Number of results per page"); $settings[]=array("item" => "version", "value" => "0.5pre3", "comments" => "Database version - Do NOT change this value");
foreach ($settings as $setting) { dosquery("insert config values (\"".$setting["item"]."\", \"".$setting["value"]."\", \"".$setting["comments"]."\")"); }
dosquery("alter table dvd add fulltext title (vchDVDTitle)");
dosquery("update dvd set vchComments = replace(vchComments,\""\",\"\\\"\")"); dosquery("update dvd set vchDVDTitle = replace(vchDVDTitle,\""\",\"\\\"\")"); dosquery("update dvd set vchComments = replace(vchComments,\"&\",\"&\")"); dosquery("update dvd set vchDVDTitle = replace(vchDVDTitle,\"&\",\"&\")"); dosquery("update dvd set vchComments = replace(vchComments,\"<\",\"<\")"); dosquery("update dvd set vchDVDTitle = replace(vchDVDTitle,\"<\",\"<\")"); dosquery("update dvd set vchComments = replace(vchComments,\">\",\">\")"); dosquery("update dvd set vchDVDTitle = replace(vchDVDTitle,\">\",\">\")");
dosquery("alter table dvd add column iRuntime int(11) default '0'"); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.5pre3") { dosquery("alter table loan add column loanee varchar(255) after iUserId"); dosquery("alter table loan add column loaneeemail varchar(255) after loanee"); dosquery("update config set value=\"0.5pre4\" where item=\"version\""); dosquery("insert config values (\"dateformat\", \"%W %D %M, %Y\", \"Format used to display date fields. See <A HREF=\\\"http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1333\\\">the mysql docs</A> for more options.\")"); dosquery("insert config values (\"graphwidth\",\"600\",\"Width of stats graphs, in pixels\")"); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.5pre4") { dosquery("update config set value=\"0.5\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.5") { dosquery("alter table country change column chCountryCode code char(2) not null"); dosquery("alter table country change column vchCountryDesc name varchar(255) not null"); dosquery("alter table country drop index chCountryCode"); dosquery("alter table country add index code (code)");
dosquery("alter table genre change column iGenreId id int not null auto_increment"); dosquery("alter table genre change column vchGenreDesc name varchar(64) not null");
dosquery("alter table loan change column iLoanId id int not null auto_increment"); dosquery("alter table loan change column iDVDId movieid int not null"); dosquery("alter table loan change column iUserId userid int not null"); dosquery("alter table loan change column dtLoanDate loandate date not null"); dosquery("alter table loan drop tiReturned"); dosquery("alter table loan drop index iDVDId"); dosquery("alter table loan drop index iUserId"); dosquery("alter table loan add index movieid (movieid)"); dosquery("alter table loan add index userid (userid)");
dosquery("alter table region change column chRegionCode code char(2) not null"); dosquery("alter table region change column vchRegionDesc name varchar(255) not null"); dosquery("alter table region drop index chRegionCode"); dosquery("alter table region add index code (code)");
dosquery("alter table user change column iUserId id int not null auto_increment"); dosquery("alter table user change column vchEmail email varchar(255) not null"); dosquery("alter table user change column vchPassword password varchar(32) not null"); dosquery("alter table user change column vchFirstName fname varchar(255) not null"); dosquery("alter table user change column vchLastName lname varchar(255) not null"); dosquery("alter table user change column vchCity city varchar(255) not null"); dosquery("alter table user change column chRegionCode regioncode char(2) not null"); dosquery("alter table user change column chCountryCode countrycode char(2) not null"); dosquery("alter table user change column tiEnabled enabled bit not null"); dosquery("alter table user change column tiAdmin admin bit not null"); dosquery("alter table user change column dtLastVisit lastvisit datetime not null"); dosquery("alter table user change column dtLastCheck lastcheck datetime not null");
dosquery("alter table dvd change column iDVDId id int not null auto_increment"); dosquery("alter table dvd change column iUserId userid int not null"); dosquery("alter table dvd change column vchDVDTitle title varchar(255) not null"); dosquery("alter table dvd change column dtDVDDate reldate year not null"); dosquery("alter table dvd change column vchComments comments text null"); dosquery("alter table dvd change column irating rating int not null"); dosquery("alter table dvd change column iGenreId genreid int not null"); dosquery("alter table dvd change column iRegion region int null"); dosquery("alter table dvd change column dtInsertDate insertdate datetime not null"); dosquery("alter table dvd change column iRuntime runtime int null"); dosquery("alter table dvd add column mediaid int not null"); dosquery("alter table dvd drop index iUserId"); dosquery("alter table dvd add index userid (userid)"); dosquery("alter table dvd add index genreid (genreid)"); dosquery("alter table dvd add index region (region)"); dosquery("alter table dvd add index insertdate (insertdate)"); dosquery("alter table dvd rename movie"); dosquery("update movie set mediaid=1");
dosquery("create table media (id int not null auto_increment, name varchar(32), primary key (id))"); dosquery("insert media values (NULL, \"DVD\")"); dosquery("insert media values (NULL, \"VHS\")"); dosquery("insert media values (NULL, \"LD\")");
dosquery("update config set value=\"0.6pre1\" where item=\"version\""); dosquery("insert config values (\"defmedia\", \"1\", \"Default media type. See <A HREF=\\\"tableedit.php\\\">table edit</A> for values\")"); dosquery("insert config values (\"theme\", \"classic\", \"Default theme\")"); dosquery("insert config values (\"yearwindow\", \"20\", \"Number of years back to display on stats page. Will be rounded down to the nearest decade\")"); dosquery("update config set value=\"0.6pre1\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.6pre1") { dosquery("alter table config add column visible bit default \"1\""); dosquery("update config set visible=0 where item in (\"version\", \"theme\")"); dosquery("update config set value=\"0.6pre2\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.6pre2") { dosquery("create table userprefs (userid int not null, item varchar(255) not null, value varchar(255) not null, key userid (userid))"); dosquery("update config set value=\"0.6pre3\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.6pre3") { dosquery("delete from userprefs where item=\"showimdb\""); dosquery("delete from config where item=\"showimdb\""); dosquery("insert config values (\"commentchars\",\"255\", \"Number of characters of comment to display on list movie page\", 1)"); dosquery("insert config values (\"movcolumns\",\"2047\", \"Columns to display on list movies page.\", 0)"); dosquery("insert config values (\"showall\",\"0\", \"Enable show all link on movie list page\", 1)"); dosquery("update config set value=\"0.6pre4\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.6pre4") { dosquery("insert config values (\"allowadminedit\",\"1\", \"Allow admin to edit all movies in the system, regardless of owner.\", 1)"); dosquery("insert config values (\"movienav\",\"3\", \"Show movie navigation at top/bottom or both. Bitmask value. 1=top, 2=bottom, 3=both\", 1)"); dosquery("alter table movie add column director varchar(255)"); dosquery("alter table movie add column sound varchar(255)"); dosquery("alter table movie add column video varchar(255)"); dosquery("alter table movie add column extra varchar(255)"); dosquery("delete from config where item=\"highdate\""); dosquery("alter table movie change column genreid genreid varchar(255) not null"); dosquery("update config set value=\"0.6pre5\" where item=\"version\""); }
$test=mysql_result(doquery("select value from config where item = \"version\""),0); if ($test=="0.6pre5") { dosquery("update config set value=\"0.6\" where item=\"version\""); }
// Always update the mysql version. If you upgrade mysql, re-run upgradedb.php to // make sure the right version number gets into the config.
// Parsing the version number is tricky at the best of times. MySQL returns // different format version numbers, so it's possible this will end up // wrong on some systems.
$version=mysql_get_server_info(); $spos=0;
// Make sure first char is numeric.
if (!is_numeric($version[0])) { for ($i=0;$i<=strlen($version);$i++) { if (is_numeric($version[$i])) { $spos=$i; break; } } }
// Get the position of the first character that isn't numeric or a . for ($i=0;$i<=strlen($version);$i++) { if (!is_numeric($version[$i])&&$version[$i]!=".") { $epos=$i; break; } }
$version=substr($version,$spos,$epos-$spos);
// Now we should have a number in the format x.xx.xx - we only care about the first 2 digits, so lose the third.
$bits=explode(".",$version); $version=$bits[0].".".$bits[1];
// See if it's already in the table..
$test=doquery("select * from config where item=\"mysqlversion\""); if (mysql_num_rows($test)==0) { $query="insert config values (\"mysqlversion\", \"".$version."\", \"Mysql version\", 0)"; } else { $query="update config set value=\"".$version."\" where item=\"mysqlversion\""; } dosquery($query);
echo "<BR /><BR />If no errors appear above, you may now <A HREF=\"index.php\">proceed to the site.</A><BR />\n"; echo "If errors appeared, contact <A HREF=\"mailto:james@globalmegacorp.org\">james@globalmegacorp.org</A><BR />\n";
?> </body> </html>
|