author | Dan |
Fri, 07 Sep 2007 16:27:40 -0400 | |
changeset 119 | 9de392a67964 |
parent 113 | 6f357b951f7a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
|
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
33
diff
changeset
|
5 |
* Version 1.0.1 (Loch Ness) |
0 | 6 |
* upgrade.php - upgrade script |
7 |
* Copyright (C) 2006-2007 Dan Fuhry |
|
8 |
* |
|
9 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
13 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
14 |
*/ |
|
15 |
||
16 |
define('IN_ENANO_INSTALL', 'true'); |
|
17 |
||
18 |
if(!defined('scriptPath')) { |
|
19 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
20 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
21 |
define('scriptPath', $sp); |
|
22 |
} |
|
23 |
||
24 |
if(!defined('contentPath')) { |
|
25 |
$sp = dirname($_SERVER['REQUEST_URI']); |
|
26 |
if($sp == '/' || $sp == '\\') $sp = ''; |
|
27 |
define('contentPath', $sp); |
|
28 |
} |
|
29 |
||
30 |
global $_starttime, $this_page, $sideinfo; |
|
31 |
$_starttime = microtime(true); |
|
32 |
||
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
33 |
// Determine directory (special case for development servers) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
34 |
if ( strpos(__FILE__, '/repo/') && file_exists('.enanodev') ) |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
35 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
36 |
$filename = str_replace('/repo/', '/', __FILE__); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
37 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
38 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
39 |
{ |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
40 |
$filename = __FILE__; |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
41 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
42 |
|
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
43 |
define('ENANO_ROOT', dirname($filename)); |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
44 |
|
0 | 45 |
require(ENANO_ROOT.'/includes/constants.php'); |
46 |
||
47 |
if(defined('ENANO_DEBUG')) |
|
48 |
{ |
|
49 |
require_once(ENANO_ROOT.'/includes/debugger/debugConsole.php'); |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
function dc_here($m) { return false; } |
|
54 |
function dc_dump($a, $g) { return false; } |
|
55 |
function dc_watch($n) { return false; } |
|
56 |
function dc_start_timer($u) { return false; } |
|
57 |
function dc_stop_timer($m) { return false; } |
|
58 |
} |
|
59 |
||
60 |
// SCRIPT CONFIGURATION |
|
61 |
// Everything related to versions goes here! |
|
62 |
||
63 |
// Valid versions to upgrade from |
|
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
33
diff
changeset
|
64 |
$valid_versions = Array('1.0b1', '1.0b2', '1.0b3', '1.0b4', '1.0RC1', '1.0RC2', '1.0RC3', '1.0'); |
0 | 65 |
|
66 |
// Basically a list of dependencies, which should be resolved automatically |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
67 |
// If, for example, upgrading from 1.0b1 to 1.0RC1 requires one extra query that would not |
0 | 68 |
// normally be required (for whatever reason) then you would add a custom version number to the array under key '1.0b1'. |
69 |
$deps_list = Array( |
|
70 |
'1.0b1' => Array('1.0b2'), |
|
71 |
'1.0b2' => Array('1.0b3'), |
|
72 |
'1.0b3' => Array('1.0b4'), |
|
73 |
'1.0b4' => Array('1.0RC1'), |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
74 |
'1.0RC1' => Array('1.0RC2'), |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
33
diff
changeset
|
75 |
'1.0RC2' => Array('1.0RC3'), |
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
33
diff
changeset
|
76 |
'1.0RC3' => Array('1.0') |
0 | 77 |
); |
73
0a74676a2f2f
Made the move to Loch Ness, and got some basic page grouping functionality working. TODO: fix some UI issues in Javascript ACL editor and change non-JS ACL editor to work with page groups too
Dan
parents:
33
diff
changeset
|
78 |
$this_version = '1.0.1'; |
0 | 79 |
$func_list = Array( |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
80 |
'1.0' => Array('u_1_0_1_update_del_votes'), |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
81 |
'1.0b4' => Array('u_1_0_RC1_update_user_ids', 'u_1_0_RC1_add_admins_to_group', 'u_1_0_RC1_alter_files_table', 'u_1_0_RC1_destroy_session_cookie', 'u_1_0_RC1_set_contact_email', 'u_1_0_RC1_update_page_text'), // , |
16
64e0d3d4cf14
Emergency version change to 1.0rc3 to fix XSS vulnerabilities
Dan
parents:
0
diff
changeset
|
82 |
// '1.0RC2' => Array('u_1_0_populate_userpage_comments') |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
83 |
'1.0RC3' => Array('u_1_0_RC3_make_users_extra') |
0 | 84 |
); |
85 |
||
86 |
if(!isset($_GET['mode'])) |
|
87 |
{ |
|
88 |
$_GET['mode'] = 'login'; |
|
89 |
} |
|
90 |
||
91 |
function err($t) |
|
92 |
{ |
|
93 |
global $template; |
|
94 |
echo $t; |
|
95 |
$template->footer(); |
|
96 |
exit; |
|
97 |
} |
|
98 |
||
99 |
require(ENANO_ROOT.'/includes/template.php'); |
|
100 |
||
101 |
// Initialize the session manager |
|
102 |
require(ENANO_ROOT.'/includes/functions.php'); |
|
103 |
require(ENANO_ROOT.'/includes/dbal.php'); |
|
104 |
require(ENANO_ROOT.'/includes/paths.php'); |
|
105 |
require(ENANO_ROOT.'/includes/sessions.php'); |
|
106 |
require(ENANO_ROOT.'/includes/plugins.php'); |
|
107 |
require(ENANO_ROOT.'/includes/rijndael.php'); |
|
108 |
require(ENANO_ROOT.'/includes/render.php'); |
|
109 |
$db = new mysql(); |
|
110 |
$db->connect(); |
|
111 |
||
112 |
$plugins = new pluginLoader(); |
|
113 |
||
114 |
if(!defined('ENANO_CONFIG_FETCHED')) |
|
115 |
{ |
|
116 |
// Select and fetch the site configuration |
|
117 |
$e = $db->sql_query('SELECT config_name, config_value FROM '.table_prefix.'config;'); |
|
118 |
if ( !$e ) |
|
119 |
{ |
|
120 |
$db->_die('Some critical configuration information could not be selected.'); |
|
121 |
} |
|
122 |
else |
|
123 |
{ |
|
124 |
define('ENANO_CONFIG_FETCHED', ''); // Used in die_semicritical to figure out whether to call getConfig() or not |
|
125 |
} |
|
126 |
||
127 |
$enano_config = Array(); |
|
128 |
while($r = $db->fetchrow()) |
|
129 |
{ |
|
130 |
$enano_config[$r['config_name']] = $r['config_value']; |
|
131 |
} |
|
132 |
$db->free_result(); |
|
133 |
} |
|
134 |
||
135 |
$v = enano_version(); |
|
136 |
if(in_array($v, Array(false, '', '1.0b3', '1.0b4'))) |
|
137 |
{ |
|
138 |
$ul_admin = 2; |
|
139 |
$ul_mod = 1; |
|
140 |
$ul_member = 0; |
|
141 |
$ul_guest = -1; |
|
142 |
} |
|
143 |
else |
|
144 |
{ |
|
145 |
$ul_admin = USER_LEVEL_ADMIN; |
|
146 |
$ul_mod = USER_LEVEL_MOD; |
|
147 |
$ul_member = USER_LEVEL_MEMBER; |
|
148 |
$ul_guest = USER_LEVEL_GUEST; |
|
149 |
} |
|
150 |
||
151 |
$_GET['title'] = 'unset'; |
|
152 |
||
153 |
$session = new sessionManager(); |
|
154 |
$paths = new pathManager(); |
|
155 |
$session->start(); |
|
156 |
||
157 |
$template = new template_nodb(); |
|
158 |
$template->load_theme('oxygen', 'bleu', false); |
|
159 |
||
160 |
$modestrings = Array( |
|
161 |
'login' => 'Administrative login', |
|
162 |
'welcome' => 'Welcome', |
|
163 |
'setversion' => 'Select Enano version', |
|
164 |
'confirm' => 'Confirm upgrade', |
|
165 |
'upgrade' => 'Database installation', |
|
166 |
'finish' => 'Upgrade complete' |
|
167 |
); |
|
168 |
||
169 |
$sideinfo = ''; |
|
170 |
$vars = $template->extract_vars('elements.tpl'); |
|
171 |
$p = $template->makeParserText($vars['sidebar_button']); |
|
172 |
foreach ( $modestrings as $id => $str ) |
|
173 |
{ |
|
174 |
if ( $_GET['mode'] == $id ) |
|
175 |
{ |
|
176 |
$flags = 'style="font-weight: bold; text-decoration: underline;"'; |
|
177 |
$this_page = $str; |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
$flags = ''; |
|
182 |
} |
|
183 |
$p->assign_vars(Array( |
|
184 |
'HREF' => '#', |
|
185 |
'FLAGS' => $flags . ' onclick="return false;"', |
|
186 |
'TEXT' => $str |
|
187 |
)); |
|
188 |
$sideinfo .= $p->run(); |
|
189 |
} |
|
190 |
||
191 |
$template->init_vars(); |
|
192 |
||
193 |
function upg_assign_vars($schema) |
|
194 |
{ |
|
195 |
$schema = str_replace('{{SITE_NAME}}', mysql_real_escape_string(getConfig('site_name')), $schema); |
|
196 |
$schema = str_replace('{{SITE_DESC}}', mysql_real_escape_string(getConfig('site_desc')), $schema); |
|
197 |
$schema = str_replace('{{COPYRIGHT}}', mysql_real_escape_string(getConfig('copyright_notice')), $schema); |
|
198 |
$schema = str_replace('{{TABLE_PREFIX}}', table_prefix, $schema); |
|
199 |
if(getConfig('wiki_mode')=='1') $schema = str_replace('{{WIKI_MODE}}', '1', $schema); |
|
200 |
else $schema = str_replace('{{WIKI_MODE}}', '0', $schema); |
|
201 |
return $schema; |
|
202 |
} |
|
203 |
||
204 |
/* Version-specific functions */ |
|
205 |
||
206 |
function u_1_0_RC1_update_user_ids() |
|
207 |
{ |
|
208 |
global $db; |
|
209 |
// First, make sure this hasn't already been done |
|
210 |
$q = $db->sql_query('SELECT username FROM '.table_prefix.'users WHERE user_id=1;'); |
|
211 |
if ( !$q ) |
|
212 |
$db->_die(); |
|
213 |
$row = $db->fetchrow(); |
|
214 |
if ( $row['username'] == 'Anonymous' ) |
|
215 |
return true; |
|
216 |
// Find the first unused user ID |
|
217 |
$used = Array(); |
|
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
218 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users;'); |
0 | 219 |
if ( !$q ) |
220 |
$db->_die(); |
|
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
221 |
$notfirst = false; |
0 | 222 |
while ( $row = $db->fetchrow() ) |
223 |
{ |
|
224 |
$i = intval($row['user_id']); |
|
225 |
$used[$i] = true; |
|
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
226 |
if ( !isset($used[$i - 1]) && $notfirst ) |
0 | 227 |
{ |
228 |
$id = $i - 1; |
|
229 |
break; |
|
230 |
} |
|
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
231 |
$notfirst = true; |
0 | 232 |
} |
233 |
if ( !isset($id) ) |
|
234 |
$id = $i + 1; |
|
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
235 |
if ( $id == 0 ) |
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
236 |
$id = 2; |
0 | 237 |
$db->free_result(); |
238 |
||
239 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=' . $id . ' WHERE user_id=1;'); |
|
240 |
if(!$q) |
|
241 |
$db->_die(); |
|
242 |
$q = $db->sql_query('UPDATE '.table_prefix.'users SET user_id=1 WHERE user_id=-1 AND username=\'Anonymous\';'); |
|
243 |
if(!$q) |
|
244 |
$db->_die(); |
|
245 |
||
246 |
} |
|
247 |
||
248 |
function u_1_0_RC1_add_admins_to_group() |
|
249 |
{ |
|
250 |
global $db; |
|
251 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_level=' . USER_LEVEL_ADMIN . ';'); |
|
252 |
if ( !$q ) |
|
253 |
$db->_die(); |
|
254 |
$base = 'INSERT INTO '.table_prefix.'group_members(group_id,user_id) VALUES'; |
|
255 |
$blocks = Array(); |
|
256 |
while ( $row = $db->fetchrow($q) ) |
|
257 |
{ |
|
258 |
$blocks[] = '(2,' . $row['user_id'] . ')'; |
|
259 |
} |
|
260 |
$blocks = implode(',', $blocks); |
|
261 |
$sql = $base . $blocks . ';'; |
|
262 |
if(!$db->sql_query($sql)) |
|
263 |
$db->_die(); |
|
264 |
} |
|
265 |
||
266 |
function u_1_0_RC1_alter_files_table() |
|
267 |
{ |
|
268 |
global $db; |
|
269 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
270 |
@mkdir(ENANO_ROOT . '/files'); |
|
271 |
if(!is_dir(ENANO_ROOT.'/files')) |
|
272 |
die('ERROR: Couldn\'t create files directory'); |
|
273 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
274 |
if(!$q) $db->_die(); |
|
275 |
while ( $row = $db->fetchrow() ) |
|
276 |
{ |
|
277 |
$file_data = base64_decode($row['data']); |
|
278 |
$path = ENANO_ROOT . '/files/' . md5( $row['filename'] . '_' . $file_data ) . '_' . $row['time_id'] . $row['file_extension']; |
|
279 |
@unlink($path); |
|
280 |
$handle = @fopen($path, 'w'); |
|
281 |
if(!$handle) |
|
282 |
die('fopen failed'); |
|
283 |
fwrite($handle, $file_data); |
|
284 |
fclose($handle); |
|
285 |
||
286 |
} |
|
287 |
||
288 |
$q = $db->sql_query('ALTER TABLE '.table_prefix.'files DROP PRIMARY KEY, ADD COLUMN file_id int(12) NOT NULL auto_increment FIRST, ADD PRIMARY KEY (file_id), ADD COLUMN file_key varchar(32) NOT NULL;'); |
|
289 |
if(!$q) $db->_die(); |
|
290 |
||
291 |
$list = Array(); |
|
292 |
$q = $db->sql_unbuffered_query('SELECT * FROM '.table_prefix.'files;', $db->_conn); |
|
293 |
if(!$q) $db->_die(); |
|
294 |
while ( $row = $db->fetchrow($q) ) |
|
295 |
{ |
|
296 |
$file_data = base64_decode($row['data']); |
|
297 |
$key = md5( $row['filename'] . '_' . $file_data ); |
|
298 |
$list[] = 'UPDATE '.table_prefix.'files SET file_key=\'' . $key . '\' WHERE file_id=' . $row['file_id'] . ';'; |
|
299 |
} |
|
300 |
||
301 |
foreach ( $list as $sql ) |
|
302 |
{ |
|
303 |
if(!$db->sql_query($sql)) $db->_die(); |
|
304 |
} |
|
305 |
||
306 |
if(!$db->sql_query('ALTER TABLE '.table_prefix.'files DROP data')) $db->_die(); |
|
307 |
||
308 |
} |
|
309 |
||
310 |
function u_1_0_RC1_destroy_session_cookie() |
|
311 |
{ |
|
312 |
unset($_COOKIE['sid']); |
|
313 |
setcookie('sid', '', time()-3600*24, scriptPath); |
|
314 |
setcookie('sid', '', time()-3600*24, scriptPath.'/'); |
|
315 |
} |
|
316 |
||
317 |
function u_1_0_RC1_set_contact_email() |
|
318 |
{ |
|
319 |
global $db; |
|
320 |
$q = $db->sql_query('SELECT email FROM '.table_prefix.'users WHERE user_level='.USER_LEVEL_ADMIN.' ORDER BY user_level ASC LIMIT 1;'); |
|
321 |
if(!$q) |
|
322 |
$db->_die(); |
|
323 |
$row = $db->fetchrow(); |
|
324 |
setConfig('contact_email', $row['email']); |
|
325 |
} |
|
326 |
||
327 |
function u_1_0_RC1_update_page_text() |
|
328 |
{ |
|
329 |
global $db; |
|
330 |
$q = $db->sql_unbuffered_query('SELECT page_id,namespace,page_text,char_tag FROM '.table_prefix.'page_text'); |
|
331 |
if (!$q) |
|
332 |
$db->_die(); |
|
333 |
||
334 |
$qs = array(); |
|
335 |
||
336 |
while ( $row = $db->fetchrow($q) ) |
|
337 |
{ |
|
338 |
$row['page_text'] = str_replace(Array( |
|
339 |
"{QUOT:{$row['char_tag']}}", |
|
340 |
"{APOS:{$row['char_tag']}}", |
|
341 |
"{SLASH:{$row['char_tag']}}" |
|
342 |
), Array( |
|
343 |
'"', "'", '\\' |
|
344 |
), $row['page_text']); |
|
345 |
$qs[] = 'UPDATE '.table_prefix.'page_text SET page_text=\'' . mysql_real_escape_string($row['page_text']) . '\' |
|
346 |
WHERE page_id=\'' . mysql_real_escape_string($row['page_id']) . '\' AND |
|
347 |
namespace=\'' . mysql_real_escape_string($row['namespace']) . '\';'; |
|
348 |
} |
|
349 |
||
350 |
foreach($qs as $query) |
|
351 |
{ |
|
352 |
if(!$db->sql_query($query)) |
|
353 |
$db->_die(); |
|
354 |
} |
|
355 |
} |
|
356 |
||
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
357 |
function u_1_0_1_update_del_votes() |
0 | 358 |
{ |
359 |
global $db; |
|
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
360 |
$q = $db->sql_query('SELECT urlname, namespace, delvote_ips FROM '.table_prefix.'pages;'); |
0 | 361 |
if ( !$q ) |
362 |
$db->_die(); |
|
363 |
||
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
364 |
while ( $row = $db->fetchrow($q) ) |
0 | 365 |
{ |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
366 |
$ips = strval($row['delvote_ips']); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
367 |
if ( is_array( @unserialize($ips) ) ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
368 |
continue; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
369 |
$ips = explode('|', $ips); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
370 |
$new = array( |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
371 |
'ip' => array(), |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
372 |
'u' => array() |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
373 |
); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
374 |
$i = 0; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
375 |
$prev = ''; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
376 |
$prev_is_ip = false; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
377 |
foreach ( $ips as $ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
378 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
379 |
$i++; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
380 |
$current_is_ip = is_valid_ip($ip); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
381 |
if ( $current_is_ip && $prev_is_ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
382 |
{ |
113
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
383 |
$i++; |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
384 |
$new['u'][] = $prev; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
385 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
386 |
if ( $current_is_ip ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
387 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
388 |
$new['ip'][] = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
389 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
390 |
else |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
391 |
{ |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
392 |
$new['u'][] = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
393 |
} |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
394 |
$prev = $ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
395 |
$prev_is_ip = $current_is_ip; |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
396 |
} |
113
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
397 |
if ( $i % 2 == 1 && $prev_is_ip ) |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
398 |
{ |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
399 |
$new['u'][] = $ip; |
6f357b951f7a
Oops - fixed small glitch in delvote_ips converter code
Dan
parents:
112
diff
changeset
|
400 |
} |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
401 |
$new = serialize($new); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
402 |
$e = $db->sql_query('UPDATE '.table_prefix.'pages SET delvote_ips=\'' . $db->escape($new) . '\' WHERE urlname=\'' . $db->escape($row['urlname']) . '\' AND namespace=\'' . $db->escape($row['namespace']) . '\';'); |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
403 |
if ( !$e ) |
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
404 |
$db->_die(); |
0 | 405 |
} |
112
008b1c42be72
Rewrote all code related to delvote_ips column to use serialize()
Dan
parents:
110
diff
changeset
|
406 |
$db->free_result($q); |
0 | 407 |
} |
408 |
||
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
409 |
function u_1_0_RC3_make_users_extra() |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
410 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
411 |
global $db; |
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
412 |
$q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_id > 0;'); |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
413 |
if ( !$q ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
414 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
415 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
416 |
$ids = array(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
417 |
while ( $row = $db->fetchrow() ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
418 |
{ |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
419 |
$ids[] = intval($row['user_id']); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
420 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
421 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
422 |
$ids = '(' . implode('),(', $ids) . ')'; |
95
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
423 |
if ( $ids == '' ) |
1dac77b46f07
Changed style of copyright in St. Patty; first attempt at fixing some upgrade issues from beta 3 or so
dan
parents:
91
diff
changeset
|
424 |
return false; |
31
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
425 |
$sql = "INSERT INTO " . table_prefix . "users_extra(user_id) VALUES$ids;"; |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
426 |
|
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
427 |
if ( !$db->sql_query($sql) ) |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
428 |
$db->_die(); |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
429 |
} |
dc8741857bde
Finished Special:Preferences/Profile page! Only the wikitext parser cleanup left, yay!
Dan
parents:
21
diff
changeset
|
430 |
|
0 | 431 |
switch($_GET['mode']) |
432 |
{ |
|
433 |
case "login": |
|
110 | 434 |
if ( $session->user_logged_in && $session->user_level < $ul_admin ) |
435 |
{ |
|
436 |
$template->header(); |
|
437 |
echo '<p>Your user account does not have permission to perform an upgrade of Enano. Return to the <a href="index.php">index page</a>.</p>'; |
|
438 |
$template->footer(); |
|
439 |
exit; |
|
440 |
} |
|
0 | 441 |
if($session->user_logged_in && $session->user_level >= $ul_admin) |
442 |
{ |
|
443 |
if(isset($_POST['login'])) |
|
444 |
{ |
|
445 |
$session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_admin); |
|
446 |
if($session->sid_super) |
|
447 |
{ |
|
448 |
header('Location: upgrade.php?mode=welcome&auth='.$session->sid_super); |
|
449 |
exit; |
|
450 |
} |
|
451 |
} |
|
452 |
$template->header(); |
|
453 |
?> |
|
454 |
<form action="upgrade.php?mode=login" method="post"> |
|
455 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
456 |
<tr> |
|
457 |
<th colspan="2">You must re-authenticate to perform this upgrade.</th> |
|
458 |
</tr> |
|
459 |
<?php |
|
460 |
if(isset($_POST['login'])) |
|
461 |
{ |
|
462 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
463 |
} |
|
464 |
?> |
|
465 |
<tr> |
|
466 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
467 |
</tr> |
|
468 |
<tr> |
|
469 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
470 |
</tr> |
|
471 |
<tr> |
|
472 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
473 |
</tr> |
|
474 |
</table> |
|
475 |
</form> |
|
476 |
<?php |
|
477 |
} |
|
478 |
else |
|
479 |
{ |
|
480 |
if(isset($_POST['login'])) |
|
481 |
{ |
|
482 |
$result = $session->login_without_crypto($_POST['username'], $_POST['password'], false, $ul_member); |
|
483 |
if($result == 'success') |
|
484 |
{ |
|
485 |
header('Location: upgrade.php'); |
|
486 |
exit; |
|
487 |
} |
|
488 |
} |
|
489 |
$template->header(); |
|
490 |
?> |
|
491 |
<form action="upgrade.php?mode=login" method="post"> |
|
492 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
493 |
<tr> |
|
494 |
<th colspan="2">Please log in to continue with this upgrade.</th> |
|
495 |
</tr> |
|
496 |
<?php |
|
497 |
if(isset($_POST['login'])) |
|
498 |
{ |
|
499 |
echo '<tr><td colspan="2"><p style="color: red;">Login failed. Bad password?</p></td></tr>'; |
|
500 |
} |
|
501 |
?> |
|
502 |
<tr> |
|
503 |
<td>Username:</td><td><input type="text" name="username" size="30" /></td> |
|
504 |
</tr> |
|
505 |
<tr> |
|
506 |
<td>Password:</td><td><input type="password" name="password" size="30" /></td> |
|
507 |
</tr> |
|
508 |
<tr> |
|
509 |
<td colspan="2" style="text-align: center;"><input type="submit" name="login" value="Log in" /> |
|
510 |
</tr> |
|
511 |
</table> |
|
512 |
</form> |
|
513 |
<?php |
|
514 |
} |
|
515 |
break; |
|
516 |
case "welcome": |
|
517 |
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
518 |
||
519 |
// Just show a simple welcome page to display version information |
|
520 |
$template->header(); |
|
521 |
require('config.php'); |
|
522 |
||
523 |
?> |
|
524 |
||
525 |
<div style="text-align: center; margin-top: 10px;"> |
|
526 |
<img alt="[ Enano CMS Project logo ]" src="images/enano-artwork/installer-greeting-blue.png" style="display: block; margin: 0 auto; padding-left: 134px;" /> |
|
527 |
<h2>Welcome to the Enano upgrade wizard</h2> |
|
528 |
<?php |
|
529 |
if ( file_exists('./_nightly.php') ) |
|
530 |
{ |
|
531 |
echo '<div class="warning-box" style="text-align: left; margin: 10px auto; display: table; width: 60%;"><b>You are about to upgrade to a NIGHTLY BUILD of Enano.</b><br />Nightly builds CANNOT be re-upgraded to the final release. They may also contain serious flaws, security problems, or extraneous debugging information. Continuing this process on a production site is NOT recommended.</div>'; |
|
532 |
} |
|
533 |
?> |
|
534 |
</div> |
|
535 |
<div style="display: table; margin: 0 auto;"> |
|
536 |
<p>You are about to upgrade Enano to version <b><?php echo $this_version; ?></b>. Before you continue, please ensure that:</p> |
|
537 |
<ul> |
|
538 |
<li>You have completely backed up your database (<b><?php echo "$dbhost:$dbname"; ?></b>)</li> |
|
539 |
<li>You have backed up the entire Enano directory (<b><?php echo ENANO_ROOT; ?></b>)</li> |
|
540 |
<li>You have reviewed the release notes for this version, and you<br />are comfortable with any known bugs or issues</li> |
|
91 | 541 |
<li>If you've configured Enano to work using a MySQL user with restricted<br />privileges, you need to enable ALTER, CREATE TABLE, and CREATE INDEX privileges<br />for this upgrade to work.</li> |
0 | 542 |
</ul> |
543 |
</div> |
|
544 |
<div style="text-align: center; margin-top: 10px;"> |
|
545 |
<form action="upgrade.php?mode=setversion&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
546 |
<input type="submit" value="Continue with upgrade" /> |
|
547 |
</form> |
|
548 |
</div> |
|
549 |
||
550 |
<?php |
|
551 |
||
552 |
break; |
|
553 |
case "setversion": |
|
554 |
if(!$session->sid_super) { $template->header(); echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
555 |
$v = ( function_exists('enano_version') ) ? enano_version() : ''; |
|
556 |
if(!in_array($v, $valid_versions) && $v != '') |
|
557 |
{ |
|
558 |
$template->header(); |
|
559 |
?> |
|
560 |
<p>Your version of Enano (<?php echo $v; ?>) can't be upgraded to this version (<?php echo $this_version; ?>).</p> |
|
561 |
<?php |
|
562 |
break; |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
563 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
564 |
else if($v == '') |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
565 |
{ |
0 | 566 |
// OK, we don't know which version he's running. So we'll cheat ;-) |
567 |
$template->header(); |
|
568 |
echo "<form action='upgrade.php?mode=confirm&auth={$session->sid_super}' method='post'>"; |
|
569 |
?> |
|
570 |
<p>Sorry, we couldn't detect which version of Enano you're running on your server. Please select which version of Enano you have below, and make absolutely sure that you're correct.</p> |
|
571 |
<p><select name="version"><?php |
|
572 |
foreach($valid_versions as $c) |
|
573 |
{ |
|
574 |
echo "<option value='{$c}'>{$c}</option>"; |
|
575 |
} |
|
576 |
?></select></p> |
|
577 |
<p> |
|
578 |
<input type="submit" value="Continue" /> |
|
579 |
</p> |
|
580 |
<?php |
|
581 |
echo `</form>`; |
|
582 |
break; |
|
21
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
583 |
} |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
584 |
else |
663fcf528726
Updated all version numbers back to Banshee; a few preliminary steps towards full UTF-8 support in page URLs
Dan
parents:
16
diff
changeset
|
585 |
{ |
0 | 586 |
header('Location: upgrade.php?mode=confirm&auth='.$session->sid_super); |
587 |
} |
|
588 |
break; |
|
589 |
case "confirm": |
|
590 |
$enano_version = ( isset($_POST['version']) ) ? $_POST['version'] : enano_version(); |
|
591 |
||
592 |
$template->header(); |
|
593 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
594 |
?> |
|
595 |
<form action="upgrade.php?mode=upgrade&auth=<?php echo $session->sid_super; ?>" method="post"> |
|
596 |
<table border="0" style="margin-left: auto; margin-right: auto; margin-top: 5px;" cellspacing="1" cellpadding="4"> |
|
597 |
<tr> |
|
598 |
<td colspan="2"><p><b>Are you sure you want to perform this upgrade?</b></p><p>You can still cancel the upgrade process now. If<br />the upgrade fails, you will need to roll back<br />any actions made using manual SQL queries.</p><p><b>Please clear your browser cache or<br />shift-reload after the upgrade.</b><br />If you fail to do so, some page elements may<br />be broken.</td> |
|
599 |
</tr> |
|
600 |
<tr> |
|
601 |
<td colspan="2" style="text-align: center;"> |
|
602 |
<input type="hidden" name="enano_version" value="<?php echo $enano_version; ?>" /> |
|
603 |
<input type="submit" name="doit" value="Upgrade Enano!" /> |
|
604 |
</td> |
|
605 |
</tr> |
|
606 |
</table> |
|
607 |
</form> |
|
608 |
<?php |
|
609 |
break; |
|
610 |
case "upgrade": |
|
611 |
$template->header(); |
|
612 |
if(!$session->sid_super) { echo '<p>No admin session found! Please <a href="upgrade.php">restart the upgrade</a>.</p>'; $template->footer(); exit; } |
|
613 |
if(!isset($_POST['enano_version'])) { echo '<p>Can\'t find the version information on the POST query, are you trying to do this upgrade directly? Please <a href="upgrade.php">restart the upgrade</a>.</p>'; break; } |
|
614 |
$enano_version = $_POST['enano_version']; |
|
615 |
echo '<p>Preparing for schema execution...'; |
|
616 |
// Build an array of queries |
|
617 |
$schema = file_get_contents('upgrade.sql'); |
|
618 |
||
619 |
// Strip out and process version blocks |
|
620 |
preg_match_all('#---BEGIN ([0-9A-z\.\-]*?)---'."\n".'(.*?)'."\n".'---END \\1---#is', $schema, $matches); |
|
621 |
||
622 |
$from_list =& $matches[1]; |
|
623 |
$query_list =& $matches[2]; |
|
624 |
||
625 |
foreach($matches[0] as $m) |
|
626 |
{ |
|
627 |
$schema = str_replace($m, '', $schema); |
|
628 |
} |
|
629 |
$schema = explode("\n", $schema); |
|
630 |
foreach($schema as $k => $q) |
|
631 |
{ |
|
632 |
if(substr($q, 0, 2) == '--' || $q == '') |
|
633 |
{ |
|
634 |
unset($schema[$k]); |
|
635 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
636 |
} |
|
637 |
else |
|
638 |
{ |
|
639 |
$schema[$k] = upg_assign_vars($schema[$k]); |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
foreach($query_list as $k => $q) |
|
644 |
{ |
|
645 |
$query_list[$k] = explode("\n", $query_list[$k]); |
|
646 |
foreach($query_list[$k] as $i => $s) |
|
647 |
{ |
|
648 |
$tq =& $query_list[$k][$i]; |
|
649 |
if(substr($s, 0, 2) == '--' || $s == '') |
|
650 |
{ |
|
651 |
unset($query_list[$k][$i]); |
|
652 |
//die('<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'); |
|
653 |
} |
|
654 |
else |
|
655 |
{ |
|
656 |
$query_list[$k][$i] = upg_assign_vars($query_list[$k][$i]); |
|
657 |
} |
|
658 |
} |
|
659 |
$query_list[$k] = array_values($query_list[$k]); |
|
660 |
} |
|
661 |
||
662 |
$assoc_list = Array(); |
|
663 |
||
664 |
foreach($from_list as $i => $v) |
|
665 |
{ |
|
666 |
$assoc_list[$v] = $query_list[$i]; |
|
667 |
} |
|
668 |
||
669 |
$schema = array_values($schema); |
|
670 |
||
671 |
$deps_resolved = false; |
|
672 |
$installing_versions = Array($enano_version); |
|
673 |
||
674 |
while(true) |
|
675 |
{ |
|
676 |
$v = array_keys($deps_list); |
|
677 |
foreach($v as $i => $ver) |
|
678 |
{ |
|
679 |
if(in_array($ver, $installing_versions)) |
|
680 |
{ |
|
681 |
// $ver is on the list of versions to be installed. Add its dependencies to the list of versions to install. |
|
682 |
foreach($deps_list[$ver] as $dep) |
|
683 |
{ |
|
684 |
if(!in_array($dep, $installing_versions)) |
|
685 |
{ |
|
686 |
$installing_versions[] = $dep; |
|
687 |
} |
|
688 |
} |
|
689 |
} |
|
690 |
if($i == count($deps_list) - 1) |
|
691 |
{ |
|
692 |
break 2; |
|
693 |
} |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
foreach($installing_versions as $this_ver) |
|
698 |
{ |
|
699 |
$schema = array_merge($schema, $assoc_list[$this_ver]); |
|
700 |
} |
|
701 |
||
702 |
// Time for some proper SQL syntax! |
|
703 |
// Also check queries for so-called injection attempts to make |
|
704 |
// sure that it doesn't fail during the upgrade process and |
|
705 |
// leave the user with a half-upgraded database |
|
706 |
foreach($schema as $s => $q) |
|
707 |
{ |
|
708 |
if(substr($q, strlen($q)-1, 1) != ';') |
|
709 |
{ |
|
710 |
$schema[$s] .= ';'; |
|
711 |
} |
|
712 |
if ( !$db->check_query($schema[$s]) ) |
|
713 |
{ |
|
714 |
// Uh-oh, the check failed, bail out |
|
715 |
// The DBAL runs sanity checks on all queries for safety, |
|
716 |
// so if the check fails in mid-upgrade we are in deep |
|
717 |
// dodo doo-doo. |
|
718 |
echo 'Query failed sanity check, this should never happen and is a bug.</p><p>Query was:</p><pre>'.$schema[$s].'</pre>'; |
|
719 |
break 2; |
|
720 |
} |
|
721 |
} |
|
722 |
||
723 |
$schema = array_values($schema); |
|
724 |
||
725 |
// Used extensively for debugging |
|
726 |
// echo '<pre>'.htmlspecialchars(print_r($schema, true)).'</pre>'; |
|
727 |
// break; |
|
728 |
||
729 |
echo 'done!<br />Executing upgrade schema...'; |
|
730 |
||
731 |
// OK, do the loop, baby!!! |
|
732 |
foreach($schema as $q) |
|
733 |
{ |
|
734 |
$r = $db->sql_query($q); |
|
735 |
if(!$r) |
|
736 |
{ |
|
737 |
echo $db->get_error(); |
|
738 |
break 2; |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
// Call any custom functions |
|
743 |
foreach ( $installing_versions as $ver ) |
|
744 |
{ |
|
745 |
if ( isset($func_list[$ver]) ) |
|
746 |
{ |
|
747 |
foreach($func_list[$ver] as $function) |
|
748 |
{ |
|
749 |
@call_user_func($function); |
|
750 |
} |
|
751 |
} |
|
752 |
} |
|
753 |
||
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
73
diff
changeset
|
754 |
// Log the upgrade |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
73
diff
changeset
|
755 |
$q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,date_string,author,page_text,edit_summary) VALUES(\'security\', \'upgrade_enano\', ' . time() . ', \'' . date('d M Y h:i a') . '\', \'' . mysql_real_escape_string($session->username) . '\', \'' . mysql_real_escape_string($this_version) . '\', \'' . mysql_real_escape_string($_SERVER['REMOTE_ADDR']) . '\');'); |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
73
diff
changeset
|
756 |
|
0 | 757 |
echo 'done!</p>'; |
758 |
echo '<p>You will be redirected shortly. If you aren\'t redirected, <a href="index.php">click here</a>.</p> |
|
759 |
<script type="text/javascript">setTimeout("window.location=\'index.php\'", 2000)</script>'; |
|
760 |
break; |
|
761 |
} |
|
762 |
$template->footer(); |
|
763 |
||
764 |
?> |