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