]> src.bluestatic.org Git - bugdar.git/blob - install/upgrade2.php
r1384: It was actually bug 66...
[bugdar.git] / install / upgrade2.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 define('STOP_MARK', 7);
23 define('ACTIVE_SITE', 'upgrade2.php');
24
25 require_once('./global.php');
26
27 page_start();
28
29 // ###################################################################
30
31 if ($bugsys->in['mark'] == 0)
32 {
33 ?>
34 <h1>Welcome to Bugdar</h1>
35
36 <p>This upgrade will take from Bugdar 1.0.1 to Bugdar 1.1.0 Beta 1.</p>
37
38 <p>The following steps will make changes to your database schema so that you can run Bugdar 1.1.0 Beta 1. Please note that this upgrade requires the clearing of any stored searches; we apologize for this inconvenience.</p>
39
40 <p>To begin the process, please click the button below.</p>
41 <?php
42 }
43
44 // ###################################################################
45
46 if ($bugsys->in['mark'] == 1)
47 {
48 ?>
49 <h1>Major Table Changes</h1>
50
51 <p>Major table additions and deletions are being performed on your database.</p>
52 <?php
53
54 $db->query("
55 CREATE TABLE " . TABLE_PREFIX . "useremail
56 (
57 userid int unsigned not null,
58 relation int unsigned not null,
59 mask int unsigned not null
60 )
61 ");
62
63 echo "Adding the useremail table to store email preferences<br />\n";
64
65 $db->query("DROP TABLE " . TABLE_PREFIX . "dependency");
66
67 echo "Dropping the unused dependency table (this was never used and was from a 1.0.0 pre-release version, so data has been lost)<br />\n";
68 }
69
70 // ###################################################################
71
72 if ($bugsys->in['mark'] == 2)
73 {
74 ?>
75 <h1>User Table Changes</h1>
76
77 <p>Changes are now being done on the user table.</p>
78 <?php
79
80 $db->query("ALTER TABLE " . TABLE_PREFIX . "user ADD usedst BOOL NOT NULL");
81
82 echo "Adding user.usedst, a daylight savings time option<br />\n";
83
84 $db->query("ALTER TABLE " . TABLE_PREFIX . "user ADD hidestatuses mediumtext NOT NULL");
85
86 echo "Adding user.hidestatuses to allow users to opt to not display certain statuses<br />\n";
87
88 $db->query("ALTER TABLE " . TABLE_PREFIX . "user ADD defaultsortkey varchar(50) NULL");
89 $db->query("ALTER TABLE " . TABLE_PREFIX . "user ADD defaultsortas varchar(10) NULL");
90
91 echo "Adding user.defaultsortkey and user.defaultsortas for bug list sorting options<br />\n";
92 }
93
94 // ###################################################################
95
96 if ($bugsys->in['mark'] == 3)
97 {
98 ?>
99 <h1>Minor Table Changes</h1>
100
101 <p>Minor, miscellaneous modifications are now being performed on database tables.</p>
102 <?php
103
104 $db->query("DELETE FROM " . TABLE_PREFIX . "search");
105
106 echo "Clearing the search table because new features make changes to the way data is stored in this table<br />\n";
107
108 $db->query("ALTER TABLE " . TABLE_PREFIX . "search ADD resultcount INT(10) NULL");
109
110 echo "Adding search.resultcount as an internal counter for search features<br />\n";
111
112 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug CHANGE productid product INT(10) UNSIGNED NOT NULL DEFAULT '0'");
113
114 echo "Renaming bug.productid to bug.product<br />\n";
115
116 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug CHANGE componentid component INT(10) UNSIGNED NOT NULL DEFAULT '0'");
117
118 echo "Renaming bug.componentid to bug.component<br />\n";
119
120 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug CHANGE versionid version INT(10) UNSIGNED NOT NULL DEFAULT '0'");
121
122 echo "Renaming bug.versionid to bug.version<br />\n";
123 }
124
125 // ###################################################################
126
127 if ($bugsys->in['mark'] == 4)
128 {
129 ?>
130 <h1>Caching User Data in Bug Table</h1>
131
132 <p>To decrease load times and complex queries, user information is now stored in the bug table. This step will add additional fields for this data and then will populate those same fields.</p>
133 <?php
134
135 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD username varchar(255) NOT NULL");
136 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD lastpostbyname varchar(255) NOT NULL");
137 $db->query("ALTER TABLE " . TABLE_PREFIX . "bug ADD hiddenlastpostbyname varchar(255) NOT NULL");
138
139 echo "Adding bug.username, bug.lastpostbyname, and bug.hiddenlastpostbyname to store cached user name data<br />\n";
140
141 echo "Caching bug data";
142
143 $userlist = array();
144 $users = $db->query("SELECT userid, displayname FROM " . TABLE_PREFIX . "user");
145 while ($user = $db->fetch_array($users))
146 {
147 $userlist["$user[userid]"] = $user['displayname'];
148 }
149
150 $bugs = $db->query("SELECT * FROM " . TABLE_PREFIX . "bug");
151 while ($bug = $db->fetch_array($bugs))
152 {
153 $db->query("
154 UPDATE " . TABLE_PREFIX . "bug
155 SET username = '" . $db->escape_string($userlist["$bug[userid]"]) . "',
156 lastpostbyname = '" . $db->escape_string($userlist["$bug[lastpostby]"]) . "',
157 hiddenlastpostbyname = '" . $db->escape_string($userlist["$bug[hiddenlastpostby]"]) . "'
158 WHERE bugid = $bug[bugid]
159 ");
160 echo ".";
161 }
162
163 echo " done<br />\n";
164 }
165
166 // ###################################################################
167
168 if ($bugsys->in['mark'] == 5)
169 {
170 ?>
171 <h1>Updating Old History Items</h1>
172
173 <p>In Bugdar 1.1.0, the bug history feature has been improved significantly. To bring old history messages up to date, processing has to be done. Please wait while historical records are updated.</p>
174 <?php
175
176 echo "Updating historical records";
177
178 $history = $db->query("SELECT * FROM " . TABLE_PREFIX . "history");
179 while ($log = $db->fetch_array($history))
180 {
181 $matches = array();
182 if (preg_match('#custom_field([0-9]+?)#i', $log['field'], $matches))
183 {
184 $db->query("UPDATE " . TABLE_PREFIX . "history SET field = 'custom.field{$matches[1]}' WHERE historyid = $log[historyid]");
185 }
186 else if (preg_match('#comment ([0-9]+?) (hidden|text)#i', $log['field'], $matches))
187 {
188 $db->query("UPDATE " . TABLE_PREFIX . "history SET field = 'comment.{$matches[2]}', commentid = {$matches[1]} WHERE historyid = $log[historyid]");
189 }
190 else if ($log['attachmentid'] != 0)
191 {
192 $db->query("UPDATE " . TABLE_PREFIX . "history SET field = 'attachment.{$log['field']}' WHERE historyid = $log[historyid]");
193 }
194 else if (!preg_match('#^(comment|attachment)?\.#', $log['field']))
195 {
196 foreach (array('original', 'changed') AS $array)
197 {
198 if (preg_match('# \(id: ([0-9]+?)\)$#i', $log["$array"], $matches))
199 {
200 $db->query("UPDATE " . TABLE_PREFIX . "history SET $array = {$matches[1]} WHERE historyid = $log[historyid]");
201 }
202 else if (preg_match('#user ?id:? ([0-9]+?)#i', $log["$array"], $matches))
203 {
204 $db->query("UPDATE " . TABLE_PREFIX . "history SET $array = {$matches[1]} WHERE historyid = $log[historyid]");
205 }
206 $db->query("UPDATE " . TABLE_PREFIX . "history SET field = '.{$log['field']}' WHERE historyid = $log[historyid]");
207 }
208 }
209 echo ".";
210 }
211
212 echo " done<br />\n";
213 }
214
215 // ###################################################################
216
217 if ($bugsys->in['mark'] == 6)
218 {
219 ?>
220 <h1>Adding User Email Options</h1>
221
222 <p>In Bugdar 1.1.0, users can receive email notifications on various bug events. We are now setting the default email settings for all users.</p>
223 <?php
224
225 echo "Setting email options";
226
227 $users = $db->query("SELECT userid FROM " . TABLE_PREFIX . "user");
228 while ($user = $db->fetch_array($users))
229 {
230 $db->query("
231 INSERT INTO " . TABLE_PREFIX . "useremail
232 (userid, mask, relation)
233 VALUES
234 ($user[userid], 32, 0),
235 ($user[userid], 320, 1),
236 ($user[userid], 1984, 2),
237 ($user[userid], 64, 4),
238 ($user[userid], 64, 8),
239 ($user[userid], 256, 16
240 )
241 ");
242 echo ".";
243 }
244
245 echo " done<br />\n";
246 }
247
248 // ###################################################################
249
250 if ($bugsys->in['mark'] == 7)
251 {
252 ?>
253 <h1>Version Number Change</h1>
254
255 <p>This step finishes the upgrade by inreasing your version number and then updating other settings.</p>
256
257 <?php
258
259 require_once('./includes/settings.php');
260
261 $db->query("UPDATE " . TABLE_PREFIX . "setting SET value = '1.1.0 Beta 1' WHERE varname = 'trackerversion'");
262
263 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('syndicateditems', '" . $settings['general']['syndicateditems'][1] . "')");
264 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('hidestatuses', '" . $settings['display']['hidestatuses'][1] . "')");
265 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('defaultsortkey', '" . $settings['display']['defaultsortkey'][1] . "')");
266 $db->query("INSERT INTO " . TABLE_PREFIX . "setting (varname, value) VALUES ('defaultsortas', '" . $settings['display']['defaultsortas'][1] . "')");
267
268 build_settings();
269
270 ?>
271
272 ... done.
273
274 <?php
275 }
276
277 // ###################################################################
278
279 page_end();
280
281 /*=====================================================================*\
282 || ###################################################################
283 || # $HeadURL$
284 || # $Id$
285 || ###################################################################
286 \*=====================================================================*/
287 ?>