root / tags / release_2_0_1 / phpBB / upgrade.php
View | Annotate | Download (55.6 KB)
| 1 | <?php
|
|---|---|
| 2 | /***************************************************************************
|
| 3 | * upgrade.php |
| 4 | * ------------------- |
| 5 | * begin : Wed Sep 05 2001 |
| 6 | * copyright : (C) 2001 The phpBB Group |
| 7 | * email : support@phpbb.com |
| 8 | * |
| 9 | * $Id: upgrade.php 2610 2002-05-20 13:52:12Z $ |
| 10 | * |
| 11 | ****************************************************************************/ |
| 12 | |
| 13 | /***************************************************************************
|
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | define('IN_PHPBB', true); |
| 23 | |
| 24 | if ( !defined('INSTALLING') ) |
| 25 | {
|
| 26 | error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
|
| 27 | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
| 28 | |
| 29 | //
|
| 30 | // If we are being called from the install script then we don't need these
|
| 31 | // as they are already included.
|
| 32 | //
|
| 33 | include('extension.inc'); |
| 34 | include('config.'.$phpEx); |
| 35 | include('includes/constants.'.$phpEx); |
| 36 | include('includes/functions.'.$phpEx); |
| 37 | |
| 38 | if( defined("PHPBB_INSTALLED") ) |
| 39 | {
|
| 40 | $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: '; |
| 41 | header($header_location . " index.$phpEx");
|
| 42 | exit;
|
| 43 | } |
| 44 | } |
| 45 | |
| 46 | //
|
| 47 | // Force the DB type to be MySQL
|
| 48 | //
|
| 49 | $dbms = 'mysql';
|
| 50 | |
| 51 | include('includes/db.'.$phpEx); |
| 52 | include('includes/bbcode.'.$phpEx); |
| 53 | include('includes/functions_search.'.$phpEx); |
| 54 | |
| 55 | set_time_limit(0); // Unlimited execution time |
| 56 | |
| 57 | $months = array(
|
| 58 | 'Jan' => 1, |
| 59 | 'Feb' => 2, |
| 60 | 'Mar' => 3, |
| 61 | 'Apr' => 4, |
| 62 | 'May' => 5, |
| 63 | 'Jun' => 6, |
| 64 | 'Jul' => 7, |
| 65 | 'Aug' => 8, |
| 66 | 'Sep' => 9, |
| 67 | 'Sept' => 9, |
| 68 | 'Oct' => 10, |
| 69 | 'Nov' => 11, |
| 70 | 'Dec' => 12 |
| 71 | ); |
| 72 | |
| 73 | // ---------------
|
| 74 | // Begin functions
|
| 75 | //
|
| 76 | function common_header()
|
| 77 | {
|
| 78 | ?> |
| 79 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 80 | <html> |
| 81 | <head> |
| 82 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| 83 | <meta http-equiv="Content-Style-Type" content="text/css"> |
| 84 | <style type="text/css"> |
| 85 | <!-- |
| 86 | /* Specifiy background images for selected styles |
| 87 | This can't be done within the external style sheet as NS4 sees image paths relative to |
| 88 | the page which called the style sheet (i.e. this page in the root phpBB directory) |
| 89 | whereas all other browsers see image paths relative to the style sheet. Stupid NS again! |
| 90 | */ |
| 91 | TH { background-image: url(templates/subSilver/images/cellpic3.gif) }
|
| 92 | TD.cat { background-image: url(templates/subSilver/images/cellpic1.gif) }
|
| 93 | TD.rowpic { background-image: url(templates/subSilver/images/cellpic2.jpg); background-repeat: repeat-y }
|
| 94 | td.icqback { background-image: url(templates/subSilver/images/icon_icq_add.gif); background-repeat: no-repeat }
|
| 95 | TD.catHead,TD.catSides,TD.catLeft,TD.catRight,TD.catBottom { background-image: url(templates/subSilver/images/cellpic1.gif) }
|
| 96 | |
| 97 | font,th,td,p,body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt }
|
| 98 | a:link,a:active,a:visited { font-family: Verdana, Arial, Helvetica, sans-serif; color : #006699; font-size:11pt }
|
| 99 | a:hover { font-family: Verdana, Arial, Helvetica, sans-serif; text-decoration: underline; color : #DD6900; font-size:11pt }
|
| 100 | hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
|
| 101 | |
| 102 | .maintitle,h1,h2 {font-weight: bold; font-size: 22px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; text-decoration: none; line-height : 120%; color : #000000;}
|
| 103 | |
| 104 | .ok {color:green}
|
| 105 | |
| 106 | /* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */ |
| 107 | @import url("templates/subSilver/formIE.css");
|
| 108 | --> |
| 109 | </style> |
| 110 | </head> |
| 111 | <body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA"> |
| 112 | |
| 113 | <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center"> |
| 114 | <tr> |
| 115 | <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> |
| 116 | <tr> |
| 117 | <td><img src="templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td> |
| 118 | <td align="center" width="100%" valign="middle"><span class="maintitle">Upgrading to phpBB 2.0</span></td> |
| 119 | </tr> |
| 120 | </table></td> |
| 121 | </tr> |
| 122 | </table> |
| 123 | |
| 124 | <br clear="all" /> |
| 125 | |
| 126 | <? |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | function common_footer() |
| 131 | {
|
| 132 | ?> |
| 133 | |
| 134 | <br clear="all" /> |
| 135 | |
| 136 | </body> |
| 137 | </html> |
| 138 | <? |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | function query($sql, $errormsg) |
| 143 | {
|
| 144 | global $db; |
| 145 | |
| 146 | if ( !($result = $db->sql_query($sql)) ) |
| 147 | {
|
| 148 | print "<br><font color=\"red\">\n"; |
| 149 | print "$errormsg<br>"; |
| 150 | |
| 151 | $sql_error = $db->sql_error(); |
| 152 | print $sql_error['code'] .": ". $sql_error['message']. "<br>\n"; |
| 153 | |
| 154 | print "<pre>$sql</pre>"; |
| 155 | print "</font>\n"; |
| 156 | |
| 157 | return FALSE; |
| 158 | } |
| 159 | else |
| 160 | {
|
| 161 | return $result; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | function smiley_replace($text = '') |
| 166 | {
|
| 167 | global $db; |
| 168 | |
| 169 | static $search, $replace; |
| 170 | |
| 171 | // Did we get the smiley info in a previous call? |
| 172 | if ( !is_array($search) ) |
| 173 | {
|
| 174 | $sql = "SELECT code, smile_url |
| 175 | FROM smiles"; |
| 176 | $result = query($sql, "Unable to get list of smilies from the DB"); |
| 177 | |
| 178 | $smilies = $db->sql_fetchrowset($result); |
| 179 | @usort($smilies, 'smiley_sort'); |
| 180 | |
| 181 | $search = array(); |
| 182 | $replace = array(); |
| 183 | for($i = 0; $i < count($smilies); $i++) |
| 184 | {
|
| 185 | $search[] = '/<IMG SRC=".*?\/' . phpbb_preg_quote($smilies[$i]['smile_url'], '/') .'">/i'; |
| 186 | $replace[] = $smilies[$i]['code']; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | return ( $text != '' ) ? preg_replace($search, $replace, $text) : ''; |
| 191 | |
| 192 | } |
| 193 | |
| 194 | function get_schema() |
| 195 | {
|
| 196 | global $table_prefix; |
| 197 | |
| 198 | $schemafile = file('db/schemas/mysql_schema.sql');
|
| 199 | $tabledata = 0; |
| 200 | |
| 201 | for($i=0; $i < count($schemafile); $i++) |
| 202 | {
|
| 203 | $line = $schemafile[$i]; |
| 204 | |
| 205 | if ( preg_match('/^CREATE TABLE (\w+)/i', $line, $matches) )
|
| 206 | {
|
| 207 | // Start of a new table definition, set some variables and go to the next line. |
| 208 | $tabledata = 1; |
| 209 | // Replace the 'phpbb_' prefix by the user defined prefix. |
| 210 | $table = str_replace('phpbb_', $table_prefix, $matches[1]);
|
| 211 | $table_def[$table] = "CREATE TABLE $table (\n"; |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | if ( preg_match('/^\);/', $line) )
|
| 216 | {
|
| 217 | // End of the table definition |
| 218 | // After this we will skip everything until the next 'CREATE' line |
| 219 | $tabledata = 0; |
| 220 | $table_def[$table] .= ')'; // We don't need the closing semicolon |
| 221 | } |
| 222 | |
| 223 | if ( $tabledata == 1 ) |
| 224 | {
|
| 225 | // We are inside a table definition, parse this line. |
| 226 | // Add the current line to the complete table definition: |
| 227 | $table_def[$table] .= $line; |
| 228 | if ( preg_match('/^\s*(\w+)\s+(\w+)\(([\d,]+)\)(.*)$/', $line, $matches) )
|
| 229 | {
|
| 230 | // This is a column definition |
| 231 | $field = $matches[1]; |
| 232 | $type = $matches[2]; |
| 233 | $size = $matches[3]; |
| 234 | |
| 235 | preg_match('/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i', $matches[4], $match);
|
| 236 | $default = $match[1]; |
| 237 | |
| 238 | $notnull = ( preg_match('/NOT NULL/i', $matches[4]) ) ? 1 : 0;
|
| 239 | $auto_increment = ( preg_match('/auto_increment/i', $matches[4]) ) ? 1 : 0;
|
| 240 | |
| 241 | $field_def[$table][$field] = array( |
| 242 | 'type' => $type, |
| 243 | 'size' => $size, |
| 244 | 'default' => $default, |
| 245 | 'notnull' => $notnull, |
| 246 | 'auto_increment' => $auto_increment |
| 247 | ); |
| 248 | } |
| 249 | |
| 250 | if ( preg_match('/\s*PRIMARY\s+KEY\s*\((.*)\).*/', $line, $matches) )
|
| 251 | {
|
| 252 | // Primary key |
| 253 | $key_def[$table]['PRIMARY'] = $matches[1]; |
| 254 | } |
| 255 | else if ( preg_match('/\s*KEY\s+(\w+)\s*\((.*)\)/', $line, $matches) )
|
| 256 | {
|
| 257 | // Normal key |
| 258 | $key_def[$table][$matches[1]] = $matches[2]; |
| 259 | } |
| 260 | else if ( preg_match('/^\s*(\w+)\s*(.*?),?\s*$/', $line, $matches) )
|
| 261 | {
|
| 262 | // Column definition |
| 263 | $create_def[$table][$matches[1]] = $matches[2]; |
| 264 | } |
| 265 | else |
| 266 | {
|
| 267 | // It's a bird! It's a plane! It's something we didn't expect ;( |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | $schema['field_def'] = $field_def; |
| 273 | $schema['table_def'] = $table_def; |
| 274 | $schema['create_def'] = $create_def; |
| 275 | $schema['key_def'] = $key_def; |
| 276 | |
| 277 | return $schema; |
| 278 | } |
| 279 | |
| 280 | function get_inserts() |
| 281 | {
|
| 282 | global $table_prefix; |
| 283 | |
| 284 | $insertfile = file('db/schemas/mysql_basic.sql');
|
| 285 | |
| 286 | for($i = 0; $i < count($insertfile); $i++) |
| 287 | {
|
| 288 | if ( preg_match('/(INSERT INTO (\w+)\s.*);/i', str_replace('phpbb_', $table_prefix, $insertfile[$i]), $matches) )
|
| 289 | {
|
| 290 | $returnvalue[$matches[2]][] = $matches[1]; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return $returnvalue; |
| 295 | } |
| 296 | |
| 297 | function lock_tables($state, $tables= '') |
| 298 | {
|
| 299 | if ( $state == 1 ) |
| 300 | {
|
| 301 | if ( is_array($tables) ) |
| 302 | {
|
| 303 | $tables = join(' WRITE, ', $tables);
|
| 304 | } |
| 305 | |
| 306 | query("LOCK TABLES $tables WRITE", "Couldn't do: $sql");
|
| 307 | } |
| 308 | else |
| 309 | {
|
| 310 | query("UNLOCK TABLES", "Couldn't unlock all tables");
|
| 311 | } |
| 312 | } |
| 313 | |
| 314 | function output_table_content($content) |
| 315 | {
|
| 316 | echo $content . "\n"; |
| 317 | |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | // |
| 322 | // Nathan's bbcode2 conversion routines |
| 323 | // |
| 324 | function bbdecode($message) |
| 325 | {
|
| 326 | // Undo [code] |
| 327 | $code_start_html = '<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>'; |
| 328 | $code_end_html = '</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->'; |
| 329 | $message = str_replace($code_start_html, '[code]', $message); |
| 330 | $message = str_replace($code_end_html, '[/code]', $message); |
| 331 | |
| 332 | // Undo [quote] |
| 333 | $quote_start_html = '<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>'; |
| 334 | $quote_end_html = '</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->'; |
| 335 | $message = str_replace($quote_start_html, '[quote]', $message); |
| 336 | $message = str_replace($quote_end_html, '[/quote]', $message); |
| 337 | |
| 338 | // Undo [b] and [i] |
| 339 | $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
|
| 340 | $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
|
| 341 | |
| 342 | // Undo [url] (long form) |
| 343 | $message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message);
|
| 344 | |
| 345 | // Undo [url] (short form) |
| 346 | $message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message);
|
| 347 | |
| 348 | // Undo [email] |
| 349 | $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
|
| 350 | |
| 351 | // Undo [img] |
| 352 | $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
|
| 353 | |
| 354 | // Undo lists (unordered/ordered) |
| 355 | |
| 356 | // <li> tags: |
| 357 | $message = str_replace('<!-- BBCode --><LI>', '[*]', $message);
|
| 358 | |
| 359 | // [list] tags: |
| 360 | $message = str_replace('<!-- BBCode ulist Start --><UL>', '[list]', $message);
|
| 361 | |
| 362 | // [list=x] tags: |
| 363 | $message = preg_replace('#<!-- BBCode olist Start --><OL TYPE=([A1])>#si', "[list=\\1]", $message);
|
| 364 | |
| 365 | // [/list] tags: |
| 366 | $message = str_replace('</UL><!-- BBCode ulist End -->', '[/list]', $message);
|
| 367 | $message = str_replace('</OL><!-- BBCode olist End -->', '[/list]', $message);
|
| 368 | |
| 369 | return $message; |
| 370 | } |
| 371 | |
| 372 | // |
| 373 | // Alternative for in_array() which is only available in PHP4 |
| 374 | // |
| 375 | function inarray($needle, $haystack) |
| 376 | {
|
| 377 | for( $i = 0 ; $i < sizeof($haystack) ; $i++ ) |
| 378 | {
|
| 379 | if ( $haystack[$i] == $needle ) |
| 380 | {
|
| 381 | return true; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return false; |
| 386 | } |
| 387 | |
| 388 | function end_step($next) |
| 389 | {
|
| 390 | global $debug; |
| 391 | |
| 392 | print "<hr /><a href=\"$PHP_SELF?next=$next\">Next step: <b>$next</b></a><br /><br />\n"; |
| 393 | } |
| 394 | // |
| 395 | // End functions |
| 396 | // ------------- |
| 397 | |
| 398 | |
| 399 | // |
| 400 | // Start at the beginning if the user hasn't specified a specific starting point. |
| 401 | // |
| 402 | $next = ( isset($HTTP_GET_VARS['next']) ) ? $HTTP_GET_VARS['next'] : 'start'; |
| 403 | |
| 404 | // If debug is set we'll do all steps in one go. |
| 405 | $debug = 1; |
| 406 | |
| 407 | // Parse the MySQL schema file into some arrays. |
| 408 | $schema = get_schema(); |
| 409 | |
| 410 | $table_def = $schema['table_def']; |
| 411 | $field_def = $schema['field_def']; |
| 412 | $key_def = $schema['key_def']; |
| 413 | $create_def = $schema['create_def']; |
| 414 | |
| 415 | // |
| 416 | // Get mysql_basic data |
| 417 | // |
| 418 | $inserts = get_inserts(); |
| 419 | |
| 420 | // |
| 421 | // Get smiley data |
| 422 | // |
| 423 | smiley_replace(); |
| 424 | |
| 425 | common_header(); |
| 426 | |
| 427 | if ( !empty($next) ) |
| 428 | {
|
| 429 | switch($next) |
| 430 | {
|
| 431 | case 'start': |
| 432 | end_step('initial_drops');
|
| 433 | |
| 434 | case 'initial_drops': |
| 435 | print " * Dropping sessions and themes tables :: "; |
| 436 | flush(); |
| 437 | |
| 438 | query("DROP TABLE sessions", "Couldn't drop table 'sessions'");
|
| 439 | query("DROP TABLE themes", "Couldn't drop table 'themes'");
|
| 440 | |
| 441 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 442 | |
| 443 | end_step('mod_old_tables');
|
| 444 | |
| 445 | case 'mod_old_tables': |
| 446 | $modtables = array( |
| 447 | "banlist" => "banlist", |
| 448 | "catagories" => "categories", |
| 449 | "config" => "old_config", |
| 450 | "forums" => "forums", |
| 451 | "disallow" => "disallow", |
| 452 | "posts" => "posts", |
| 453 | "posts_text" => "posts_text", |
| 454 | "priv_msgs" => "privmsgs", |
| 455 | "ranks" => "ranks", |
| 456 | "smiles" => "smilies", |
| 457 | "topics" => "topics", |
| 458 | "users" => "users", |
| 459 | "words" => "words" |
| 460 | ); |
| 461 | |
| 462 | while( list($old, $new) = each($modtables) ) |
| 463 | {
|
| 464 | $result = query("SHOW INDEX FROM $old", "Couldn't get list of indices for table $old");
|
| 465 | |
| 466 | while( $row = $db->sql_fetchrow($result) ) |
| 467 | {
|
| 468 | $index = $row['Key_name']; |
| 469 | if ( $index != 'PRIMARY' ) |
| 470 | {
|
| 471 | query("ALTER TABLE $old DROP INDEX $index", "Couldn't DROP INDEX $old.$index");
|
| 472 | } |
| 473 | } |
| 474 | |
| 475 | // Rename table |
| 476 | $new = $table_prefix . $new; |
| 477 | |
| 478 | print " * Renaming '$old' to '$new' :: "; |
| 479 | flush(); |
| 480 | query("ALTER TABLE $old RENAME $new", "Failed to rename $old to $new");
|
| 481 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 482 | |
| 483 | } |
| 484 | end_step('create_tables');
|
| 485 | |
| 486 | case 'create_tables': |
| 487 | // Create array with tables in 'old' database |
| 488 | $result = query('SHOW TABLES', "Couldn't get list of current tables");
|
| 489 | |
| 490 | while( $table = $db->sql_fetchrow($result) ) |
| 491 | {
|
| 492 | $currenttables[] = $table[0]; |
| 493 | } |
| 494 | |
| 495 | // Check what tables we need to CREATE |
| 496 | while( list($table, $definition) = each($table_def) ) |
| 497 | {
|
| 498 | if ( !inarray($table, $currenttables) ) |
| 499 | {
|
| 500 | print " * Creating $table :: "; |
| 501 | |
| 502 | query($definition, "Couldn't create table $table"); |
| 503 | |
| 504 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | end_step('create_config');
|
| 509 | |
| 510 | case 'create_config': |
| 511 | print " * Inserting new values into new layout config table :: "; |
| 512 | |
| 513 | @reset($inserts); |
| 514 | while( list($table, $inserts_table) = each($inserts) ) |
| 515 | {
|
| 516 | if ( $table == CONFIG_TABLE ) |
| 517 | {
|
| 518 | $per_pct = ceil( count($inserts_table) / 40 ); |
| 519 | $inc = 0; |
| 520 | |
| 521 | while( list($nr, $insert) = each($inserts_table) ) |
| 522 | {
|
| 523 | query($insert, "Couldn't insert value into config table"); |
| 524 | |
| 525 | $inc++; |
| 526 | if ( $inc == $per_pct ) |
| 527 | {
|
| 528 | print "."; |
| 529 | flush(); |
| 530 | $inc = 0; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 537 | |
| 538 | end_step('convert_config');
|
| 539 | |
| 540 | case 'convert_config': |
| 541 | print " * Converting configuration table :: "; |
| 542 | |
| 543 | $sql = "SELECT * |
| 544 | FROM $table_prefix" . "old_config"; |
| 545 | $result = query($sql, "Couldn't get info from old config table"); |
| 546 | |
| 547 | $oldconfig = $db->sql_fetchrow($result); |
| 548 | |
| 549 | // |
| 550 | // We don't need several original config types and two others |
| 551 | // have changed name ... so take account of this. |
| 552 | // |
| 553 | $ignore_configs = array("selected", "admin_passwd", "override_themes", "allow_sig");
|
| 554 | $rename_configs = array( |
| 555 | "email_from" => "board_email", |
| 556 | "email_sig" => "board_email_sig" |
| 557 | ); |
| 558 | |
| 559 | while( list($name, $value) = each($oldconfig) ) |
| 560 | {
|
| 561 | if ( is_int($name) ) |
| 562 | {
|
| 563 | continue; |
| 564 | } |
| 565 | |
| 566 | if ( !inarray($name, $ignore_configs) ) |
| 567 | {
|
| 568 | $name = ( !empty($rename_configs[$name]) ) ? $rename_configs[$name] : $name; |
| 569 | |
| 570 | $sql = "REPLACE INTO " . CONFIG_TABLE . " (config_name, config_value) |
| 571 | VALUES ('$name', '" . stripslashes($value) . "')";
|
| 572 | query($sql, "Couldn't update config table with values from old config table"); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | $sql = "UPDATE " . CONFIG_TABLE . " |
| 577 | SET config_value = 'dutch' |
| 578 | WHERE config_name = 'default_lang' && config_value = 'nederlands'"; |
| 579 | query($sql, "Couldn't rename 'nederlands' to 'dutch' in config table"); |
| 580 | |
| 581 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 582 | end_step('convert_ips');
|
| 583 | |
| 584 | case 'convert_ips': |
| 585 | $names = array( |
| 586 | POSTS_TABLE => array( |
| 587 | 'id' => 'post_id', |
| 588 | 'field' => 'poster_ip' |
| 589 | ), |
| 590 | PRIVMSGS_TABLE => array( |
| 591 | 'id' => 'msg_id', |
| 592 | 'field' => 'poster_ip' |
| 593 | ), |
| 594 | BANLIST_TABLE => array( |
| 595 | 'id' => 'ban_id', |
| 596 | 'field' => 'ban_ip' |
| 597 | ) |
| 598 | ); |
| 599 | |
| 600 | lock_tables(1, array(POSTS_TABLE, PRIVMSGS_TABLE, BANLIST_TABLE)); |
| 601 | |
| 602 | $batchsize = 2000; |
| 603 | while( list($table, $data_array) = each($names) ) |
| 604 | {
|
| 605 | $sql = "SELECT MAX(" . $data_array['id'] . ") AS max_id
|
| 606 | FROM $table"; |
| 607 | $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
|
| 608 | |
| 609 | $row = $db->sql_fetchrow($result); |
| 610 | |
| 611 | $maxid = $row['max_id']; |
| 612 | |
| 613 | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 614 | {
|
| 615 | $batchstart = $i; |
| 616 | $batchend = $i + $batchsize; |
| 617 | |
| 618 | $field_id = $data_array['id']; |
| 619 | $field = $data_array['field']; |
| 620 | |
| 621 | print " * Converting IP format '" . $field . "' / '$table' ( $batchstart to $batchend ) :: "; |
| 622 | flush(); |
| 623 | |
| 624 | $sql = "SELECT $field_id, $field |
| 625 | FROM $table |
| 626 | WHERE $field_id |
| 627 | BETWEEN $batchstart |
| 628 | AND $batchend"; |
| 629 | $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
|
| 630 | |
| 631 | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 632 | $inc = 0; |
| 633 | |
| 634 | while( $row = $db->sql_fetchrow($result) ) |
| 635 | {
|
| 636 | $sql = "UPDATE $table |
| 637 | SET $field = '" . encode_ip($row[$field]) . "' |
| 638 | WHERE $field_id = " . $row[$field_id]; |
| 639 | query($sql, "Couldn't convert IP format of $field in $table with $field_id of " . $rowset[$field_id]); |
| 640 | |
| 641 | $inc++; |
| 642 | if ( $inc == $per_pct ) |
| 643 | {
|
| 644 | print "."; |
| 645 | flush(); |
| 646 | $inc = 0; |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | lock_tables(0); |
| 655 | end_step('convert_dates');
|
| 656 | |
| 657 | case 'convert_dates': |
| 658 | $names = array( |
| 659 | POSTS_TABLE => array('post_time'),
|
| 660 | TOPICS_TABLE => array('topic_time'),
|
| 661 | PRIVMSGS_TABLE => array('msg_time')
|
| 662 | ); |
| 663 | |
| 664 | lock_tables(1, array(POSTS_TABLE, TOPICS_TABLE, PRIVMSGS_TABLE)); |
| 665 | |
| 666 | while( list($table, $fields) = each($names) ) |
| 667 | {
|
| 668 | print " * Converting date format of $fields[$i] in $table :: "; |
| 669 | flush(); |
| 670 | |
| 671 | for($i = 0; $i < count($fields); $i++) |
| 672 | {
|
| 673 | $sql = "UPDATE $table |
| 674 | SET " . $fields[$i] . " = UNIX_TIMESTAMP(" . $fields[$i] . ")";
|
| 675 | query($sql, "Couldn't convert date format of $table(" . $fields[$i] . ")");
|
| 676 | } |
| 677 | |
| 678 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 679 | } |
| 680 | |
| 681 | lock_tables(0); |
| 682 | end_step('fix_addslashes');
|
| 683 | |
| 684 | case 'fix_addslashes': |
| 685 | $slashfields[TOPICS_TABLE] = array('topic_title');
|
| 686 | $slashfields[FORUMS_TABLE] = array('forum_desc', 'forum_name');
|
| 687 | $slashfields[CATEGORIES_TABLE] = array('cat_title');
|
| 688 | $slashfields[WORDS_TABLE] = array('word', 'replacement');
|
| 689 | $slashfields[RANKS_TABLE] = array('rank_title');
|
| 690 | $slashfields[DISALLOW_TABLE] = array('disallow_username');
|
| 691 | |
| 692 | //convert smilies? |
| 693 | $slashes = array( |
| 694 | "\\'" => "'", |
| 695 | "\\\"" => "\"", |
| 696 | "\\\\" => "\\"); |
| 697 | $slashes = array( |
| 698 | "\\'" => "'", |
| 699 | "\\\"" => "\"", |
| 700 | "\\\\" => "\\"); |
| 701 | |
| 702 | lock_tables(1, array(TOPICS_TABLE, FORUMS_TABLE, CATEGORIES_TABLE, WORDS_TABLE, RANKS_TABLE, DISALLOW_TABLE, SMILIES_TABLE)); |
| 703 | |
| 704 | while( list($table, $fields) = each($slashfields) ) |
| 705 | {
|
| 706 | print " * Removing slashes from $table table :: "; |
| 707 | flush(); |
| 708 | |
| 709 | while( list($nr, $field) = each($fields) ) |
| 710 | {
|
| 711 | @reset($slashes); |
| 712 | while( list($search, $replace) = each($slashes) ) |
| 713 | {
|
| 714 | $sql = "UPDATE $table |
| 715 | SET $field = REPLACE($field, '" . addslashes($search) . "', '" . addslashes($replace) . "')"; |
| 716 | query($sql, "Couldn't remove extraneous slashes from the old data."); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 721 | } |
| 722 | |
| 723 | lock_tables(0); |
| 724 | end_step('remove_topics');
|
| 725 | |
| 726 | case 'remove_topics': |
| 727 | print " * Removing posts with no corresponding topics :: "; |
| 728 | flush(); |
| 729 | |
| 730 | $sql = "SELECT p.post_id |
| 731 | FROM " . POSTS_TABLE . " p |
| 732 | LEFT JOIN " . TOPICS_TABLE . " t ON p.topic_id = t.topic_id |
| 733 | WHERE t.topic_id IS NULL"; |
| 734 | $result = query($sql, "Couldn't obtain list of deleted topics"); |
| 735 | |
| 736 | $post_total = $db->sql_numrows($result); |
| 737 | |
| 738 | if ( $post_total ) |
| 739 | {
|
| 740 | $post_id_ary = array(); |
| 741 | while( $row = $db->sql_fetchrow($result) ) |
| 742 | {
|
| 743 | $post_id_ary[] = $row['post_id']; |
| 744 | } |
| 745 | |
| 746 | $sql = "DELETE FROM " . POSTS_TABLE . " |
| 747 | WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
|
| 748 | query($sql, "Couldn't update posts to remove deleted user poster_id values"); |
| 749 | |
| 750 | $sql = "DELETE FROM " . POSTS_TEXT_TABLE . " |
| 751 | WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
|
| 752 | query($sql, "Couldn't update posts to remove deleted user poster_id values"); |
| 753 | } |
| 754 | |
| 755 | echo "<span class=\"ok\"><b>OK</b></span> ( Removed $post_total posts )<br />\n"; |
| 756 | end_step('convert_users');
|
| 757 | |
| 758 | case 'convert_users': |
| 759 | // |
| 760 | // Completely remove old soft-deleted users |
| 761 | // |
| 762 | $sql = "DELETE FROM " . USERS_TABLE . " |
| 763 | WHERE user_level = -1"; |
| 764 | query($sql, "Couldn't delete old soft-deleted users"); |
| 765 | |
| 766 | $sql = "SELECT COUNT(*) AS total, MAX(user_id) AS maxid |
| 767 | FROM " . USERS_TABLE; |
| 768 | $result = query($sql, "Couldn't get max post_id."); |
| 769 | |
| 770 | $maxid = $db->sql_fetchrow($result); |
| 771 | |
| 772 | $totalposts = $maxid['total']; |
| 773 | $maxid = $maxid['maxid']; |
| 774 | |
| 775 | $sql = "ALTER TABLE " . USERS_TABLE . " |
| 776 | ADD user_sig_bbcode_uid CHAR(10), |
| 777 | MODIFY user_sig text"; |
| 778 | query($sql, "Couldn't add user_sig_bbcode_uid field to users table"); |
| 779 | |
| 780 | $super_mods = array(); |
| 781 | $first_admin = -2; |
| 782 | |
| 783 | $batchsize = 1000; |
| 784 | for($i = -1; $i <= $maxid; $i += $batchsize) |
| 785 | {
|
| 786 | $batchstart = $i; |
| 787 | $batchend = $i + $batchsize; |
| 788 | |
| 789 | print " * Converting Users ( $batchstart to $batchend ) :: "; |
| 790 | flush(); |
| 791 | |
| 792 | $sql = "SELECT * |
| 793 | FROM " . USERS_TABLE . " |
| 794 | WHERE user_id |
| 795 | BETWEEN $batchstart |
| 796 | AND $batchend"; |
| 797 | $result = query($sql, "Couldn't get ". USERS_TABLE .".user_id $batchstart to $batchend"); |
| 798 | |
| 799 | // Array with user fields that we want to check for invalid data (to few characters) |
| 800 | $checklength = array( |
| 801 | 'user_occ', |
| 802 | 'user_website', |
| 803 | 'user_email', |
| 804 | 'user_from', |
| 805 | 'user_intrest', |
| 806 | 'user_aim', |
| 807 | 'user_yim', |
| 808 | 'user_msnm'); |
| 809 | |
| 810 | lock_tables(1, array(USERS_TABLE, GROUPS_TABLE, USER_GROUP_TABLE, POSTS_TABLE)); |
| 811 | |
| 812 | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 813 | $inc = 0; |
| 814 | |
| 815 | while( $row = $db->sql_fetchrow($result) ) |
| 816 | {
|
| 817 | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user) |
| 818 | VALUES ('" . addslashes($row['username']) . "', 'Personal User', 1)";
|
| 819 | query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".GROUPS_TABLE); |
| 820 | |
| 821 | $group_id = $db->sql_nextid(); |
| 822 | |
| 823 | if ( $group_id != 0 ) |
| 824 | {
|
| 825 | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 826 | VALUES ($group_id, " . $row['user_id'] . ", 0)"; |
| 827 | query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".USER_GROUP_TABLE); |
| 828 | } |
| 829 | else |
| 830 | {
|
| 831 | print "Couldn't get insert ID for " . GROUPS_TABLE . " table<br>\n"; |
| 832 | } |
| 833 | |
| 834 | if ( is_int($row['user_regdate']) ) |
| 835 | {
|
| 836 | // We already converted this post to the new style BBcode, skip this post. |
| 837 | continue; |
| 838 | } |
| 839 | |
| 840 | // |
| 841 | // Nathan's bbcode2 conversion |
| 842 | // |
| 843 | |
| 844 | // undo 1.2.x encoding.. |
| 845 | $row['user_sig'] = bbdecode(stripslashes($row['user_sig'])); |
| 846 | $row['user_sig'] = undo_make_clickable($row['user_sig']); |
| 847 | $row['user_sig'] = str_replace("<BR>", "\n", $row['user_sig']);
|
| 848 | |
| 849 | // make a uid |
| 850 | $uid = make_bbcode_uid(); |
| 851 | |
| 852 | // do 2.x first-pass encoding.. |
| 853 | $row['user_sig'] = bbencode_first_pass($row['user_sig'], $uid); |
| 854 | $row['user_sig'] = addslashes($row['user_sig']); |
| 855 | |
| 856 | // Check for invalid info like '-' and '?' for a lot of fields |
| 857 | @reset($checklength); |
| 858 | while($field = each($checklength)) |
| 859 | {
|
| 860 | $row[$field[1]] = strlen($row[$field[1]]) < 3 ? '' : $row[$field[1]]; |
| 861 | } |
| 862 | |
| 863 | preg_match('/(.*?) (\d{1,2}), (\d{4})/', $row['user_regdate'], $parts);
|
| 864 | $row['user_regdate'] = gmmktime(0, 0, 0, $months[$parts[1]], $parts[2], $parts[3]); |
| 865 | |
| 866 | $website = $row['user_website']; |
| 867 | if ( substr(strtolower($website), 0, 7) != "http://" ) |
| 868 | {
|
| 869 | $website = "http://" . $website; |
| 870 | } |
| 871 | if( strtolower($website) == 'http://' ) |
| 872 | {
|
| 873 | $website = ''; |
| 874 | } |
| 875 | $row['user_website'] = addslashes($website); |
| 876 | |
| 877 | $row['user_icq'] = (ereg("^[0-9]+$", $row['user_icq'])) ? $row['user_icq'] : '';
|
| 878 | reset($checklength); |
| 879 | |
| 880 | while($field = each($checklength)) |
| 881 | {
|
| 882 | if ( strlen($row[$field[1]]) < 3 ) |
| 883 | {
|
| 884 | $row[$field[1]] = ''; |
| 885 | } |
| 886 | $row[$field[1]] = addslashes($row[$field[1]]); |
| 887 | } |
| 888 | |
| 889 | // |
| 890 | // Is user a super moderator? |
| 891 | // |
| 892 | if( $row['user_level'] == 3 ) |
| 893 | {
|
| 894 | $super_mods[] = $row['user_id']; |
| 895 | } |
| 896 | |
| 897 | $row['user_level'] = ( $row['user_level'] == 4 ) ? ADMIN : USER; |
| 898 | |
| 899 | // |
| 900 | // Used to define a 'practical' group moderator user_id |
| 901 | // for super mods a little latter. |
| 902 | // |
| 903 | if( $first_admin == -2 && $row['user_level'] == ADMIN ) |
| 904 | {
|
| 905 | $first_admin = $row['user_id']; |
| 906 | } |
| 907 | |
| 908 | // |
| 909 | // Dutch language files have been renamed from 'nederlands' to 'dutch' |
| 910 | // |
| 911 | if( $row['user_lang'] == 'nederlands' ) |
| 912 | {
|
| 913 | $row['user_lang'] = 'dutch'; |
| 914 | } |
| 915 | |
| 916 | $sql = "UPDATE " . USERS_TABLE . " |
| 917 | SET |
| 918 | user_sig = '" . $row['user_sig'] . "', |
| 919 | user_sig_bbcode_uid = '$uid', |
| 920 | user_regdate = '" . $row['user_regdate'] . "', |
| 921 | user_website = '" . $row['user_website'] . "', |
| 922 | user_occ = '" . $row['user_occ'] . "', |
| 923 | user_email = '" . $row['user_email'] . "', |
| 924 | user_from = '" . $row['user_from'] . "', |
| 925 | user_intrest = '" . $row['user_intrest'] . "', |
| 926 | user_aim = '" . $row['user_aim'] . "', |
| 927 | user_yim = '" . $row['user_yim'] . "', |
| 928 | user_msnm = '" . $row['user_msnm'] . "', |
| 929 | user_level = '" . $row['user_level'] . "', |
| 930 | user_desmile = NOT(user_desmile), |
| 931 | user_bbcode = 1, |
| 932 | user_theme = 1 |
| 933 | WHERE user_id = " . $row['user_id']; |
| 934 | query($sql, "Couldn't update ".USERS_TABLE." table with new BBcode and regdate for user_id ".$row['user_id']); |
| 935 | |
| 936 | $inc++; |
| 937 | if ( $inc == $per_pct ) |
| 938 | {
|
| 939 | print "."; |
| 940 | flush(); |
| 941 | $inc = 0; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 946 | |
| 947 | lock_tables(0); |
| 948 | } |
| 949 | |
| 950 | // |
| 951 | // Handle super-mods, create hidden group for them |
| 952 | // |
| 953 | // Iterate trough access table |
| 954 | if( count($super_mods) && $first_admin != -2 ) |
| 955 | {
|
| 956 | print "\n<br />\n * Creating new group for super moderators :: "; |
| 957 | flush(); |
| 958 | |
| 959 | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user) |
| 960 | VALUES (" . GROUP_HIDDEN . ", 'Super Moderators', 'Converted super moderators', $first_admin, 0)";
|
| 961 | $result = query($sql, "Couldn't create group for ".$row['forum_name']); |
| 962 | |
| 963 | $group_id = $db->sql_nextid(); |
| 964 | |
| 965 | if ( $group_id <= 0 ) |
| 966 | {
|
| 967 | print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n"; |
| 968 | continue 2; |
| 969 | } |
| 970 | |
| 971 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 972 | |
| 973 | print " * Updating auth_access for super moderator group :: "; |
| 974 | flush(); |
| 975 | |
| 976 | $sql = "SELECT forum_id |
| 977 | FROM " . FORUMS_TABLE; |
| 978 | $result = query($sql, "Couldn't obtain forum_id list"); |
| 979 | |
| 980 | while( $row = $db->sql_fetchrow($result) ) |
| 981 | {
|
| 982 | $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) |
| 983 | VALUES ($group_id, " . $row['forum_id'] . ", 1)"; |
| 984 | $result_insert = query($sql, "Unable to set group auth access for super mods."); |
| 985 | } |
| 986 | |
| 987 | for($i = 0; $i < count($super_mods); $i++) |
| 988 | {
|
| 989 | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 990 | VALUES ($group_id, " . $super_mods[$i] . ", 0)"; |
| 991 | query($sql, "Unable to add user_id $user_id to group_id $group_id (super mods)<br>\n"); |
| 992 | } |
| 993 | |
| 994 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 995 | } |
| 996 | |
| 997 | end_step('convert_posts');
|
| 998 | |
| 999 | case 'convert_posts': |
| 1000 | print " * Adding enable_sig field to " . POSTS_TABLE . " :: "; |
| 1001 | flush(); |
| 1002 | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1003 | ADD enable_sig tinyint(1) DEFAULT '1' NOT NULL"; |
| 1004 | $result = query($sql, "Couldn't add enable_sig field to " . POSTS_TABLE . "."); |
| 1005 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1006 | |
| 1007 | print " * Adding enable_bbcode field to " . POSTS_TEXT_TABLE . " :: "; |
| 1008 | flush(); |
| 1009 | $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . " |
| 1010 | ADD enable_bbcode tinyint(1) DEFAULT '1' NOT NULL"; |
| 1011 | $result = query($sql, "Couldn't add enable_bbcode field to " . POSTS_TABLE . "."); |
| 1012 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1013 | |
| 1014 | print " * Adding bbcode_uid field to " . POSTS_TEXT_TABLE . " :: "; |
| 1015 | flush(); |
| 1016 | $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . " |
| 1017 | ADD bbcode_uid char(10) NOT NULL"; |
| 1018 | $result = query($sql, "Couldn't add bbcode_uid field to " . POSTS_TABLE . "."); |
| 1019 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1020 | |
| 1021 | print " * Adding post_edit_time field to " . POSTS_TABLE . " :: "; |
| 1022 | flush(); |
| 1023 | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1024 | ADD post_edit_time int(11)"; |
| 1025 | $result = query($sql, "Couldn't add post_edit_time field to " . POSTS_TABLE . "."); |
| 1026 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1027 | |
| 1028 | print " * Adding post_edit_count field to " . POSTS_TABLE . " :: "; |
| 1029 | flush(); |
| 1030 | $sql = "ALTER TABLE " . POSTS_TABLE . " |
| 1031 | ADD post_edit_count smallint(5) UNSIGNED DEFAULT '0' NOT NULL"; |
| 1032 | $result = query($sql, "Couldn't add post_edit_count field to " . POSTS_TABLE . "."); |
| 1033 | print "<span class=\"ok\"><b>OK</b></span><br />\n<br />\n"; |
| 1034 | |
| 1035 | $sql = "SELECT COUNT(*) as total, MAX(post_id) as maxid |
| 1036 | FROM " . POSTS_TEXT_TABLE; |
| 1037 | $result = query($sql, "Couldn't get max post_id."); |
| 1038 | |
| 1039 | $maxid = $db->sql_fetchrow($result); |
| 1040 | |
| 1041 | $totalposts = $maxid['total']; |
| 1042 | $maxid = $maxid['maxid']; |
| 1043 | |
| 1044 | $batchsize = 2000; |
| 1045 | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1046 | {
|
| 1047 | $batchstart = $i + 1; |
| 1048 | $batchend = $i + $batchsize; |
| 1049 | |
| 1050 | print " * Converting BBcode ( $batchstart to $batchend ) :: "; |
| 1051 | flush(); |
| 1052 | |
| 1053 | $sql = "SELECT * |
| 1054 | FROM " . POSTS_TEXT_TABLE . " |
| 1055 | WHERE post_id |
| 1056 | BETWEEN $batchstart |
| 1057 | AND $batchend"; |
| 1058 | $result = query($sql, "Couldn't get ". POSTS_TEXT_TABLE .".post_id $batchstart to $batchend"); |
| 1059 | |
| 1060 | lock_tables(1, array(POSTS_TEXT_TABLE, POSTS_TABLE)); |
| 1061 | |
| 1062 | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1063 | $inc = 0; |
| 1064 | |
| 1065 | while( $row = $db->sql_fetchrow($result) ) |
| 1066 | {
|
| 1067 | if ( $row['bbcode_uid'] != '' ) |
| 1068 | {
|
| 1069 | // We already converted this post to the new style BBcode, skip this post. |
| 1070 | continue; |
| 1071 | } |
| 1072 | |
| 1073 | // |
| 1074 | // Nathan's bbcode2 conversion |
| 1075 | // |
| 1076 | // undo 1.2.x encoding.. |
| 1077 | $row['post_text'] = bbdecode(stripslashes($row['post_text'])); |
| 1078 | $row['post_text'] = undo_make_clickable($row['post_text']); |
| 1079 | $row['post_text'] = str_replace('<BR>', "\n", $row['post_text']);
|
| 1080 | |
| 1081 | // make a uid |
| 1082 | $uid = make_bbcode_uid(); |
| 1083 | |
| 1084 | // do 2.x first-pass encoding.. |
| 1085 | $row['post_text'] = smiley_replace($row['post_text']); |
| 1086 | $row['post_text'] = bbencode_first_pass($row['post_text'], $uid); |
| 1087 | $row['post_text'] = addslashes($row['post_text']); |
| 1088 | |
| 1089 | $edited_sql = ""; |
| 1090 | if ( preg_match('/^(.*?)([\n]+<font size=\-1>\[ This message was .*?)$/s', $row['post_text'], $matches) )
|
| 1091 | {
|
| 1092 | $row['post_text'] = $matches[1]; |
| 1093 | $edit_info = $matches[2]; |
| 1094 | |
| 1095 | $edit_times = count(explode(' message ', $edit_info)) - 1; // Taken from example for substr_count in annotated PHP manual
|
| 1096 | |
| 1097 | if ( preg_match('/^.* by: (.*?) on (....)-(..)-(..) (..):(..) \]<\/font>/s', $edit_info, $matches) )
|
| 1098 | {
|
| 1099 | $edited_user = $matches[1]; |
| 1100 | $edited_time = gmmktime($matches[5], $matches[6], 0, $matches[3], $matches[4], $matches[2]); |
| 1101 | |
| 1102 | // |
| 1103 | // This isn't strictly correct since 2.0 won't include and edit |
| 1104 | // statement if the edit wasn't by the user who posted ... |
| 1105 | // |
| 1106 | $edited_sql = ", post_edit_time = $edited_time, post_edit_count = $edit_times"; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $row['post_text'], $matches) )
|
| 1111 | {
|
| 1112 | $row['post_text'] = $matches[1]; |
| 1113 | $enable_sig = 1; |
| 1114 | } |
| 1115 | else |
| 1116 | {
|
| 1117 | $checksig = preg_replace('/\[addsig\]$/', '', $row['post_text']);
|
| 1118 | $enable_sig = ( strlen($checksig) == strlen($row['post_text']) ) ? 0 : 1; |
| 1119 | } |
| 1120 | |
| 1121 | $sql = "UPDATE " . POSTS_TEXT_TABLE . " |
| 1122 | SET post_text = '$checksig', bbcode_uid = '$uid' |
| 1123 | WHERE post_id = " . $row['post_id']; |
| 1124 | query($sql, "Couldn't update " . POSTS_TEXT_TABLE . " table with new BBcode for post_id :: " . $row['post_id']); |
| 1125 | |
| 1126 | $sql = "UPDATE " . POSTS_TABLE . " |
| 1127 | SET enable_sig = $enable_sig" . $edited_sql . " |
| 1128 | WHERE post_id = " . $row['post_id']; |
| 1129 | query($sql, "Couldn't update " . POSTS_TABLE . " table with signature status for post with post_id :: " . $row['post_id']); |
| 1130 | |
| 1131 | $inc++; |
| 1132 | if ( $inc == $per_pct ) |
| 1133 | {
|
| 1134 | print '.'; |
| 1135 | flush(); |
| 1136 | $inc = 0; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1141 | |
| 1142 | lock_tables(0); |
| 1143 | } |
| 1144 | |
| 1145 | print "<br />\n * Updating poster_id for deleted users :: "; |
| 1146 | flush(); |
| 1147 | |
| 1148 | $sql = "SELECT DISTINCT p.post_id |
| 1149 | FROM " . POSTS_TABLE . " p |
| 1150 | LEFT JOIN " . USERS_TABLE . " u ON p.poster_id = u.user_id |
| 1151 | WHERE u.user_id IS NULL"; |
| 1152 | $result = query($sql, "Couldn't obtain list of deleted users"); |
| 1153 | |
| 1154 | $users_removed = $db->sql_numrows($result); |
| 1155 | |
| 1156 | if ( $users_removed ) |
| 1157 | {
|
| 1158 | $post_id_ary = array(); |
| 1159 | while( $row = $db->sql_fetchrow($result) ) |
| 1160 | {
|
| 1161 | $post_id_ary[] = $row['post_id']; |
| 1162 | } |
| 1163 | |
| 1164 | $sql = "UPDATE " . POSTS_TABLE . " |
| 1165 | SET poster_id = " . ANONYMOUS . ", enable_sig = 0 |
| 1166 | WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
|
| 1167 | query($sql, "Couldn't update posts to remove deleted user poster_id values"); |
| 1168 | } |
| 1169 | |
| 1170 | print "<span class=\"ok\"><b>OK</b></span> ( Removed $users_removed non-existent user references )<br />\n"; |
| 1171 | |
| 1172 | end_step('convert_privmsgs');
|
| 1173 | |
| 1174 | case 'convert_privmsgs': |
| 1175 | $sql = "SELECT COUNT(*) as total, max(msg_id) as maxid |
| 1176 | FROM " . PRIVMSGS_TABLE; |
| 1177 | $result = query($sql, "Couldn't get max privmsgs_id."); |
| 1178 | |
| 1179 | $maxid = $db->sql_fetchrow($result); |
| 1180 | |
| 1181 | $totalposts = $maxid['total']; |
| 1182 | $maxid = $maxid['maxid']; |
| 1183 | |
| 1184 | $sql = "ALTER TABLE " . PRIVMSGS_TABLE . " |
| 1185 | ADD privmsgs_subject VARCHAR(255), |
| 1186 | ADD privmsgs_attach_sig TINYINT(1) DEFAULT 1"; |
| 1187 | query($sql, "Couldn't add privmsgs_subject field to " . PRIVMSGS_TABLE . " table"); |
| 1188 | |
| 1189 | $batchsize = 2000; |
| 1190 | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1191 | {
|
| 1192 | $batchstart = $i + 1; |
| 1193 | $batchend = $i + $batchsize; |
| 1194 | |
| 1195 | print " * Converting Private Message ( $batchstart to $batchend ) :: "; |
| 1196 | flush(); |
| 1197 | |
| 1198 | $sql = "SELECT * |
| 1199 | FROM " . PRIVMSGS_TABLE . " |
| 1200 | WHERE msg_id |
| 1201 | BETWEEN $batchstart |
| 1202 | AND $batchend"; |
| 1203 | $result = query($sql, "Couldn't get " . POSTS_TEXT_TABLE . " post_id $batchstart to $batchend"); |
| 1204 | |
| 1205 | lock_tables(1, array(PRIVMSGS_TABLE, PRIVMSGS_TEXT_TABLE)); |
| 1206 | |
| 1207 | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1208 | $inc = 0; |
| 1209 | |
| 1210 | while( $row = $db->sql_fetchrow($result) ) |
| 1211 | {
|
| 1212 | if ( $row['msg_text'] == NULL ) |
| 1213 | {
|
| 1214 | // We already converted this post to the new style BBcode, skip this post. |
| 1215 | continue; |
| 1216 | } |
| 1217 | // |
| 1218 | // Nathan's bbcode2 conversion |
| 1219 | // |
| 1220 | // undo 1.2.x encoding.. |
| 1221 | $row['msg_text'] = bbdecode(stripslashes($row['msg_text'])); |
| 1222 | $row['msg_text'] = undo_make_clickable($row['msg_text']); |
| 1223 | $row['msg_text'] = str_replace("<BR>", "\n", $row['msg_text']);
|
| 1224 | |
| 1225 | // make a uid |
| 1226 | $uid = make_bbcode_uid(); |
| 1227 | |
| 1228 | // do 2.x first-pass encoding.. |
| 1229 | $row['msg_text'] = smiley_replace($row['msg_text']); |
| 1230 | $row['msg_text'] = bbencode_first_pass($row['msg_text'], $uid); |
| 1231 | |
| 1232 | $checksig = preg_replace('/\[addsig\]$/', '', $row['msg_text']);
|
| 1233 | $enable_sig = (strlen($checksig) == strlen($row['msg_text'])) ? 0 : 1; |
| 1234 | |
| 1235 | if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $checksig, $matches) )
|
| 1236 | {
|
| 1237 | $checksig = $matches[1]; |
| 1238 | $enable_sig = 1; |
| 1239 | } |
| 1240 | |
| 1241 | $row['msg_text'] = $checksig; |
| 1242 | |
| 1243 | $row['msg_status'] = ($row['msg_status'] == 1) ? PRIVMSGS_READ_MAIL : PRIVMSGS_NEW_MAIL; |
| 1244 | |
| 1245 | // Subject contains first 60 characters of msg, remove any BBCode tags |
| 1246 | $subject = addslashes(strip_tags(substr($row['msg_text'], 0, 60))); |
| 1247 | $subject = preg_replace("/\[.*?\:(([a-z0-9]:)?)$uid.*?\]/si", "", $subject);
|
| 1248 | |
| 1249 | $row['msg_text'] = addslashes($row['msg_text']); |
| 1250 | |
| 1251 | $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text) |
| 1252 | VALUES ('" . $row['msg_id'] . "', '$uid', '" . $row['msg_text'] . "')";
|
| 1253 | query($sql, "Couldn't insert PrivMsg text into " . PRIVMSGS_TEXT_TABLE . " table msg_id " . $row['msg_id']); |
| 1254 | |
| 1255 | $sql = "UPDATE " . PRIVMSGS_TABLE . " |
| 1256 | SET msg_text = NULL, msg_status = " . $row['msg_status'] . ", privmsgs_subject = '$subject', privmsgs_attach_sig = $enable_sig |
| 1257 | WHERE msg_id = " . $row['msg_id']; |
| 1258 | query($sql, "Couldn't update " . PRIVMSGS_TABLE . " table for msg_id " . $row['post_id']); |
| 1259 | |
| 1260 | $inc++; |
| 1261 | if ( $inc == $per_pct ) |
| 1262 | {
|
| 1263 | print '.'; |
| 1264 | flush(); |
| 1265 | $inc = 0; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1270 | } |
| 1271 | |
| 1272 | lock_tables(0); |
| 1273 | end_step('convert_moderators');
|
| 1274 | |
| 1275 | case 'convert_moderators'; |
| 1276 | $sql = "SELECT * |
| 1277 | FROM forum_mods"; |
| 1278 | $result = query($sql, "Couldn't get list with all forum moderators"); |
| 1279 | |
| 1280 | while( $row = $db->sql_fetchrow($result) ) |
| 1281 | {
|
| 1282 | // Check if this moderator and this forum still exist |
| 1283 | $sql = "SELECT user_id |
| 1284 | FROM " . USERS_TABLE . ", " . FORUMS_TABLE . " |
| 1285 | WHERE user_id = " . $row['user_id'] . " |
| 1286 | AND forum_id = " . $row['forum_id']; |
| 1287 | $check_data = query($sql, "Couldn't check if user " . $row['user_id'] . " and forum " . $row['forum_id'] . " exist"); |
| 1288 | |
| 1289 | if ( !($rowtest = $db->sql_fetchrow($check_data)) ) |
| 1290 | {
|
| 1291 | // Either the moderator or the forum have been deleted, this line in forum_mods was redundant, skip it. |
| 1292 | continue; |
| 1293 | } |
| 1294 | |
| 1295 | $sql = "SELECT g.group_id |
| 1296 | FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug |
| 1297 | WHERE g.group_id = ug.group_id |
| 1298 | AND ug.user_id = " . $row['user_id'] . " |
| 1299 | AND g.group_single_user = 1"; |
| 1300 | $insert_group = query($sql, "Couldn't get group number for user " . $row['user_id'] . "."); |
| 1301 | |
| 1302 | $group_id = $db->sql_fetchrow($insert_group); |
| 1303 | $group_id = $group_id['group_id']; |
| 1304 | |
| 1305 | print " * Adding moderator for forum " . $row['forum_id'] . " :: "; |
| 1306 | flush(); |
| 1307 | |
| 1308 | $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) VALUES ($group_id, ".$row['forum_id'].", 1)"; |
| 1309 | query($sql, "Couldn't set moderator (user_id = " . $row['user_id'] . ") for forum " . $row['forum_id'] . "."); |
| 1310 | |
| 1311 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1312 | } |
| 1313 | |
| 1314 | print " * Setting correct user_level for moderators ::"; |
| 1315 | flush(); |
| 1316 | |
| 1317 | $sql = "SELECT DISTINCT u.user_id |
| 1318 | FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa |
| 1319 | WHERE aa.auth_mod = 1 |
| 1320 | AND ug.group_id = aa.group_id |
| 1321 | AND u.user_id = ug.user_id |
| 1322 | AND u.user_level <> " . ADMIN; |
| 1323 | $result = query($sql, "Couldn't obtain list of moderators"); |
| 1324 | |
| 1325 | if ( $row = $db->sql_fetchrow($result) ) |
| 1326 | {
|
| 1327 | $ug_sql = ''; |
| 1328 | |
| 1329 | do |
| 1330 | {
|
| 1331 | $ug_sql .= ( ( $ug_sql != '' ) ? ', ' : '' ) . $row['user_id']; |
| 1332 | } |
| 1333 | while ( $row = $db->sql_fetchrow($result) ); |
| 1334 | |
| 1335 | $sql = "UPDATE " . USERS_TABLE . " |
| 1336 | SET user_level = " . MOD . " |
| 1337 | WHERE user_id IN ($ug_sql)"; |
| 1338 | query($sql, "Couldn't set moderator status for users"); |
| 1339 | } |
| 1340 | |
| 1341 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1342 | |
| 1343 | end_step('convert_privforums');
|
| 1344 | |
| 1345 | case 'convert_privforums': |
| 1346 | $sql = "SELECT fa.*, f.forum_name |
| 1347 | FROM forum_access fa |
| 1348 | LEFT JOIN " . FORUMS_TABLE . " f ON fa.forum_id = f.forum_id |
| 1349 | ORDER BY fa.forum_id, fa.user_id"; |
| 1350 | $forum_access = query($sql, "Couldn't get list with special forum access (forum_access)"); |
| 1351 | |
| 1352 | $forum_id = -1; |
| 1353 | while( $row = $db->sql_fetchrow($forum_access) ) |
| 1354 | {
|
| 1355 | // Iterate trough access table |
| 1356 | if ( $row['forum_id'] != $forum_id ) |
| 1357 | {
|
| 1358 | // This is a new forum, create new group. |
| 1359 | $forum_id = $row['forum_id']; |
| 1360 | |
| 1361 | print " * Creating new group for forum $forum_id :: "; |
| 1362 | flush(); |
| 1363 | |
| 1364 | $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user) |
| 1365 | VALUES (" . GROUP_HIDDEN . ", '" . addslashes($row['forum_name']) . " Group', 'Converted Private Forum Group', " . $row['user_id'] . ", 0)";
|
| 1366 | $result = query($sql, "Couldn't create group for ".$row['forum_name']); |
| 1367 | |
| 1368 | $group_id = $db->sql_nextid(); |
| 1369 | |
| 1370 | if ( $group_id <= 0 ) |
| 1371 | {
|
| 1372 | print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n"; |
| 1373 | continue 2; |
| 1374 | } |
| 1375 | |
| 1376 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1377 | |
| 1378 | print " * Creating auth_access group for forum $forum_id :: "; |
| 1379 | flush(); |
| 1380 | |
| 1381 | $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_view, auth_read, auth_post, auth_reply, auth_edit, auth_delete, auth_sticky, auth_announce, auth_vote, auth_pollcreate) |
| 1382 | VALUES ($group_id, $forum_id, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)"; |
| 1383 | $result = query($sql, "Unable to set group auth access."); |
| 1384 | |
| 1385 | if ( $db->sql_affectedrows($result) <= 0 ) |
| 1386 | {
|
| 1387 | print "<font color=\"red\">Group creation failed. Aborting creation of groups...</font><br>\n"; |
| 1388 | continue 2; |
| 1389 | } |
| 1390 | |
| 1391 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1392 | } |
| 1393 | |
| 1394 | // Add user to the group |
| 1395 | $user_id = $row['user_id']; |
| 1396 | |
| 1397 | $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) |
| 1398 | VALUES ($group_id, $user_id, 0)"; |
| 1399 | query($sql, "Unable to add user_id $user_id to group_id $group_id <br>\n"); |
| 1400 | } |
| 1401 | |
| 1402 | end_step('update_schema');
|
| 1403 | |
| 1404 | case 'update_schema': |
| 1405 | $rename = array( |
| 1406 | $table_prefix . "users" => array( |
| 1407 | "user_interests" => "user_intrest", |
| 1408 | "user_allowsmile" => "user_desmile", |
| 1409 | "user_allowhtml" => "user_html", |
| 1410 | "user_allowbbcode" => "user_bbcode", |
| 1411 | "user_style" => "user_theme" |
| 1412 | ), |
| 1413 | $table_prefix . "privmsgs" => array( |
| 1414 | "privmsgs_id" => "msg_id", |
| 1415 | "privmsgs_from_userid" => "from_userid", |
| 1416 | "privmsgs_to_userid" => "to_userid", |
| 1417 | "privmsgs_date" => "msg_time", |
| 1418 | "privmsgs_ip" => "poster_ip", |
| 1419 | "privmsgs_type" => "msg_status" |
| 1420 | ), |
| 1421 | $table_prefix . "smilies" => array( |
| 1422 | "smilies_id" => "id" |
| 1423 | ) |
| 1424 | ); |
| 1425 | |
| 1426 | $schema = get_schema(); |
| 1427 | |
| 1428 | $table_def = $schema['table_def']; |
| 1429 | $field_def = $schema['field_def']; |
| 1430 | |
| 1431 | // Loop tables in schema |
| 1432 | while (list($table, $table_def) = @each($field_def)) |
| 1433 | {
|
| 1434 | // Loop fields in table |
| 1435 | print " * Updating table '$table' :: "; |
| 1436 | flush(); |
| 1437 | |
| 1438 | $sql = "SHOW FIELDS |
| 1439 | FROM $table"; |
| 1440 | $result = query($sql, "Can't get definition of current $table table"); |
| 1441 | |
| 1442 | while( $row = $db->sql_fetchrow($result) ) |
| 1443 | {
|
| 1444 | $current_fields[] = $row['Field']; |
| 1445 | } |
| 1446 | |
| 1447 | $alter_sql = "ALTER TABLE $table "; |
| 1448 | while (list($field, $definition) = each($table_def)) |
| 1449 | {
|
| 1450 | if ( $field == '' ) |
| 1451 | {
|
| 1452 | // Skip empty fields if any (shouldn't be needed) |
| 1453 | continue; |
| 1454 | } |
| 1455 | |
| 1456 | $type = $definition['type']; |
| 1457 | $size = $definition['size']; |
| 1458 | |
| 1459 | $default = isset($definition['default']) ? "DEFAULT " . $definition['default'] : ''; |
| 1460 | |
| 1461 | $notnull = $definition['notnull'] == 1 ? 'NOT NULL' : ''; |
| 1462 | |
| 1463 | $auto_increment = $definition['auto_increment'] == 1 ? 'auto_increment' : ''; |
| 1464 | |
| 1465 | $oldfield = isset($rename[$table][$field]) ? $rename[$table][$field] : $field; |
| 1466 | |
| 1467 | if ( !inarray($field, $current_fields) && $oldfield == $field ) |
| 1468 | {
|
| 1469 | // If the current is not a key of $current_def and it is not a field that is |
| 1470 | // to be renamed then the field doesn't currently exist. |
| 1471 | $changes[] = " ADD $field " . $create_def[$table][$field]; |
| 1472 | } |
| 1473 | else |
| 1474 | {
|
| 1475 | $changes[] = " CHANGE $oldfield $field " . $create_def[$table][$field]; |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | $alter_sql .= join(',', $changes);
|
| 1480 | unset($changes); |
| 1481 | unset($current_fields); |
| 1482 | |
| 1483 | $sql = "SHOW INDEX |
| 1484 | FROM $table"; |
| 1485 | $result = query($sql, "Couldn't get list of indices for table $table"); |
| 1486 | |
| 1487 | unset($indices); |
| 1488 | |
| 1489 | while( $row = $db->sql_fetchrow($result) ) |
| 1490 | {
|
| 1491 | $indices[] = $row['Key_name']; |
| 1492 | } |
| 1493 | |
| 1494 | while ( list($key_name, $key_field) = each($key_def[$table]) ) |
| 1495 | {
|
| 1496 | if ( !inarray($key_name, $indices) ) |
| 1497 | {
|
| 1498 | $alter_sql .= ($key_name == 'PRIMARY') ? ", ADD PRIMARY KEY ($key_field)" : ", ADD INDEX $key_name ($key_field)"; |
| 1499 | } |
| 1500 | } |
| 1501 | query($alter_sql, "Couldn't alter table $table"); |
| 1502 | |
| 1503 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1504 | flush(); |
| 1505 | } |
| 1506 | |
| 1507 | end_step('convert_forums');
|
| 1508 | |
| 1509 | case 'convert_forums': |
| 1510 | $sql = "SELECT * |
| 1511 | FROM " . FORUMS_TABLE; |
| 1512 | $result = query($sql, "Couldn't get list with all forums"); |
| 1513 | |
| 1514 | while( $row = $db->sql_fetchrow($result) ) |
| 1515 | {
|
| 1516 | print " * Converting forum '" . $row['forum_name'] . "' :: "; |
| 1517 | flush(); |
| 1518 | |
| 1519 | // forum_access: (only concerns posting) |
| 1520 | // 1 = Registered users only |
| 1521 | // 2 = Anonymous Posting |
| 1522 | // 3 = Moderators/Administrators only |
| 1523 | switch( $row['forum_access'] ) |
| 1524 | {
|
| 1525 | case 1: |
| 1526 | // Public forum, no anonymous posting |
| 1527 | $auth_view = AUTH_ALL; |
| 1528 | $auth_read = AUTH_ALL; |
| 1529 | $auth_post = AUTH_REG; |
| 1530 | $auth_reply = AUTH_REG; |
| 1531 | $auth_edit = AUTH_REG; |
| 1532 | $auth_delete = AUTH_REG; |
| 1533 | $auth_vote = AUTH_REG; |
| 1534 | $auth_pollcreate = AUTH_REG; |
| 1535 | $auth_sticky = AUTH_MOD; |
| 1536 | $auth_announce = AUTH_MOD; |
| 1537 | break; |
| 1538 | case 2: |
| 1539 | $auth_post = AUTH_ALL; |
| 1540 | $auth_reply = AUTH_ALL; |
| 1541 | $auth_edit = AUTH_REG; |
| 1542 | $auth_delete = AUTH_REG; |
| 1543 | $auth_vote = AUTH_ALL; |
| 1544 | $auth_pollcreate = AUTH_ALL; |
| 1545 | $auth_sticky = AUTH_MOD; |
| 1546 | $auth_announce = AUTH_MOD; |
| 1547 | break; |
| 1548 | default: |
| 1549 | $auth_post = AUTH_MOD; |
| 1550 | $auth_reply = AUTH_MOD; |
| 1551 | $auth_edit = AUTH_MOD; |
| 1552 | $auth_delete = AUTH_MOD; |
| 1553 | $auth_vote = AUTH_MOD; |
| 1554 | $auth_pollcreate = AUTH_MOD; |
| 1555 | $auth_sticky = AUTH_MOD; |
| 1556 | $auth_announce = AUTH_MOD; |
| 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | // Old auth structure: |
| 1561 | // forum_type: (only concerns viewing) |
| 1562 | // 0 = Public |
| 1563 | // 1 = Private |
| 1564 | switch( $row['forum_type'] ) |
| 1565 | {
|
| 1566 | case 0: |
| 1567 | $auth_view = AUTH_ALL; |
| 1568 | $auth_read = AUTH_ALL; |
| 1569 | break; |
| 1570 | default: |
| 1571 | // |
| 1572 | // Make it really private ... |
| 1573 | // |
| 1574 | $auth_view = AUTH_ACL; |
| 1575 | $auth_read = AUTH_ACL; |
| 1576 | $auth_post = AUTH_ACL; |
| 1577 | $auth_reply = AUTH_ACL; |
| 1578 | $auth_edit = AUTH_ACL; |
| 1579 | $auth_delete = AUTH_ACL; |
| 1580 | $auth_vote = AUTH_ACL; |
| 1581 | $auth_pollcreate = AUTH_ACL; |
| 1582 | $auth_sticky = AUTH_ACL; |
| 1583 | $auth_announce = AUTH_MOD; |
| 1584 | break; |
| 1585 | } |
| 1586 | |
| 1587 | $sql = "UPDATE " . FORUMS_TABLE . " SET |
| 1588 | auth_view = $auth_view, |
| 1589 | auth_read = $auth_read, |
| 1590 | auth_post = $auth_post, |
| 1591 | auth_reply = $auth_reply, |
| 1592 | auth_edit = $auth_edit, |
| 1593 | auth_delete = $auth_delete, |
| 1594 | auth_vote = $auth_vote, |
| 1595 | auth_pollcreate = $auth_pollcreate, |
| 1596 | auth_sticky = $auth_sticky, |
| 1597 | auth_announce = $auth_announce |
| 1598 | WHERE forum_id = ". $row['forum_id']; |
| 1599 | query($sql, "Was unable to update forum permissions!"); |
| 1600 | |
| 1601 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1602 | } |
| 1603 | |
| 1604 | end_step('insert_themes');
|
| 1605 | |
| 1606 | case 'insert_themes': |
| 1607 | print " * Inserting new values into themes table :: "; |
| 1608 | |
| 1609 | @reset($inserts); |
| 1610 | while( list($table, $inserts_table) = each($inserts) ) |
| 1611 | {
|
| 1612 | if ( $table == THEMES_TABLE ) |
| 1613 | {
|
| 1614 | $per_pct = ceil( count($inserts_table) / 40 ); |
| 1615 | $inc = 0; |
| 1616 | |
| 1617 | while( list($nr, $insert) = each($inserts_table) ) |
| 1618 | {
|
| 1619 | query($insert, "Couldn't insert value into " . THEMES_TABLE); |
| 1620 | |
| 1621 | $inc++; |
| 1622 | if ( $inc == $per_pct ) |
| 1623 | {
|
| 1624 | print "."; |
| 1625 | flush(); |
| 1626 | $inc = 0; |
| 1627 | } |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1633 | end_step('fulltext_search_indexing');
|
| 1634 | |
| 1635 | case 'fulltext_search_indexing': |
| 1636 | // |
| 1637 | // Generate search word list |
| 1638 | // |
| 1639 | // Fetch a batch of posts_text entries |
| 1640 | // |
| 1641 | $sql = "SELECT COUNT(*) as total, MAX(post_id) as max_post_id |
| 1642 | FROM " . POSTS_TEXT_TABLE; |
| 1643 | $result = query($sql, "Couldn't get post count totals"); |
| 1644 | |
| 1645 | $max_post_id = $db->sql_fetchrow($result); |
| 1646 | |
| 1647 | $totalposts = $max_post_id['total']; |
| 1648 | $max_post_id = $max_post_id['max_post_id']; |
| 1649 | $per_percent = round(( $totalposts / 500 ) * 10); |
| 1650 | |
| 1651 | $postcounter = ( !isset($HTTP_GET_VARS['batchstart']) ) ? 0 : $HTTP_GET_VARS['batchstart']; |
| 1652 | |
| 1653 | $batchsize = 150; // Process this many posts per loop |
| 1654 | $batchcount = 0; |
| 1655 | $total_percent = 0; |
| 1656 | |
| 1657 | for(;$postcounter <= $max_post_id; $postcounter += $batchsize) |
| 1658 | {
|
| 1659 | $batchstart = $postcounter + 1; |
| 1660 | $batchend = $postcounter + $batchsize; |
| 1661 | $batchcount++; |
| 1662 | |
| 1663 | print " * Fulltext Indexing ( $batchstart to $batchend ) :: "; |
| 1664 | flush(); |
| 1665 | |
| 1666 | $sql = "SELECT * |
| 1667 | FROM " . POSTS_TEXT_TABLE ." |
| 1668 | WHERE post_id |
| 1669 | BETWEEN $batchstart |
| 1670 | AND $batchend"; |
| 1671 | $posts_result = query($sql, "Couldn't obtain post_text"); |
| 1672 | |
| 1673 | $per_pct = ceil( $db->sql_numrows($posts_result) / 40 ); |
| 1674 | $inc = 0; |
| 1675 | |
| 1676 | if ( $row = $db->sql_fetchrow($posts_result) ) |
| 1677 | {
|
| 1678 | do |
| 1679 | {
|
| 1680 | add_search_words($row['post_id'], $row['post_text'], $row['post_subject']); |
| 1681 | |
| 1682 | $inc++; |
| 1683 | if ( $inc == $per_pct ) |
| 1684 | {
|
| 1685 | print "."; |
| 1686 | flush(); |
| 1687 | $inc = 0; |
| 1688 | } |
| 1689 | } |
| 1690 | while( $row = $db->sql_fetchrow($posts_result) ); |
| 1691 | } |
| 1692 | |
| 1693 | $db->sql_freeresult($posts_result); |
| 1694 | |
| 1695 | // Remove common words after the first 2 batches and after every 4th batch after that. |
| 1696 | if ( $batchcount % 4 == 3 ) |
| 1697 | {
|
| 1698 | remove_common('global', 0.4);
|
| 1699 | } |
| 1700 | |
| 1701 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1702 | } |
| 1703 | |
| 1704 | end_step('update_topics');
|
| 1705 | |
| 1706 | case 'update_topics': |
| 1707 | $sql = "SELECT MAX(topic_id) AS max_topic |
| 1708 | FROM " . TOPICS_TABLE; |
| 1709 | $result = query($sql, "Couldn't get max topic id"); |
| 1710 | |
| 1711 | $row = $db->sql_fetchrow($result); |
| 1712 | |
| 1713 | $maxid = $row['max_topic']; |
| 1714 | |
| 1715 | lock_tables(1, array(TOPICS_TABLE, POSTS_TABLE)); |
| 1716 | |
| 1717 | $batchsize = 1000; |
| 1718 | for($i = 0; $i <= $maxid; $i += $batchsize) |
| 1719 | {
|
| 1720 | $batchstart = $i + 1; |
| 1721 | $batchend = $i + $batchsize; |
| 1722 | |
| 1723 | print " * Setting topic first post_id ( $batchstart to $batchend ) :: "; |
| 1724 | flush(); |
| 1725 | |
| 1726 | $sql = "SELECT MIN(post_id) AS first_post_id, topic_id |
| 1727 | FROM " . POSTS_TABLE . " |
| 1728 | WHERE topic_id |
| 1729 | BETWEEN $batchstart |
| 1730 | AND $batchend |
| 1731 | GROUP BY topic_id |
| 1732 | ORDER BY topic_id ASC"; |
| 1733 | $result = query($sql, "Couldn't get post id data"); |
| 1734 | |
| 1735 | $per_pct = ceil( $db->sql_numrows($result) / 40 ); |
| 1736 | $inc = 0; |
| 1737 | |
| 1738 | if ( $row = $db->sql_fetchrow($result) ) |
| 1739 | {
|
| 1740 | do |
| 1741 | {
|
| 1742 | $sql = "UPDATE " . TOPICS_TABLE . " |
| 1743 | SET topic_first_post_id = " . $row['first_post_id'] . " |
| 1744 | WHERE topic_id = " . $row['topic_id']; |
| 1745 | query($sql, "Couldn't update topic first post id in topic :: $topic_id"); |
| 1746 | |
| 1747 | $inc++; |
| 1748 | if ( $inc == $per_pct ) |
| 1749 | {
|
| 1750 | print "."; |
| 1751 | flush(); |
| 1752 | $inc = 0; |
| 1753 | } |
| 1754 | } |
| 1755 | while ( $row = $db->sql_fetchrow($result) ); |
| 1756 | } |
| 1757 | |
| 1758 | print " <span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1759 | } |
| 1760 | |
| 1761 | lock_tables(0); |
| 1762 | end_step('final_configuration');
|
| 1763 | |
| 1764 | case 'final_configuration': |
| 1765 | // |
| 1766 | // Update forum last post information |
| 1767 | // |
| 1768 | $sql = "SELECT forum_id, forum_name |
| 1769 | FROM " . FORUMS_TABLE; |
| 1770 | $f_result = query($sql, "Couldn't obtain forum_ids"); |
| 1771 | |
| 1772 | while( $forum_row = $db->sql_fetchrow($f_result) ) |
| 1773 | {
|
| 1774 | print " * Updating '" . $forum_row['forum_name'] . "' post info :: "; |
| 1775 | flush(); |
| 1776 | |
| 1777 | $id = $forum_row['forum_id']; |
| 1778 | |
| 1779 | $sql = "SELECT MIN(p.post_id) AS first_post, MAX(p.post_id) AS last_post |
| 1780 | FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t |
| 1781 | WHERE p.forum_id = $id |
| 1782 | AND p.topic_id = t.topic_id"; |
| 1783 | $result = query($sql, "Could not get post ID forum post information :: $id"); |
| 1784 | |
| 1785 | if ( $row = $db->sql_fetchrow($result) ) |
| 1786 | {
|
| 1787 | $first_post = ( $row['first_post'] ) ? $row['first_post'] : 0; |
| 1788 | $last_post = ($row['last_post']) ? $row['last_post'] : 0; |
| 1789 | } |
| 1790 | else |
| 1791 | {
|
| 1792 | $first_post = 0; |
| 1793 | $last_post = 0; |
| 1794 | } |
| 1795 | |
| 1796 | $sql = "SELECT COUNT(post_id) AS total |
| 1797 | FROM " . POSTS_TABLE . " |
| 1798 | WHERE forum_id = $id"; |
| 1799 | $result = query($sql, "Could not get post count forum post information :: $id"); |
| 1800 | |
| 1801 | if ( $row = $db->sql_fetchrow($result) ) |
| 1802 | {
|
| 1803 | $total_posts = ($row['total']) ? $row['total'] : 0; |
| 1804 | } |
| 1805 | else |
| 1806 | {
|
| 1807 | $total_posts = 0; |
| 1808 | } |
| 1809 | |
| 1810 | $sql = "SELECT COUNT(topic_id) AS total |
| 1811 | FROM " . TOPICS_TABLE . " |
| 1812 | WHERE forum_id = $id |
| 1813 | AND topic_status <> " . TOPIC_MOVED; |
| 1814 | $result = query($sql, "Could not get topic count forum post information :: $id"); |
| 1815 | |
| 1816 | if ( $row = $db->sql_fetchrow($result) ) |
| 1817 | {
|
| 1818 | $total_topics = ($row['total']) ? $row['total'] : 0; |
| 1819 | } |
| 1820 | else |
| 1821 | {
|
| 1822 | $total_topics = 0; |
| 1823 | } |
| 1824 | |
| 1825 | $sql = "UPDATE " . FORUMS_TABLE . " |
| 1826 | SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics |
| 1827 | WHERE forum_id = $id"; |
| 1828 | query($sql, "Could not update forum post information :: $id"); |
| 1829 | |
| 1830 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1831 | } |
| 1832 | |
| 1833 | print "<br />\n * Update default user and finalise configuration :: "; |
| 1834 | flush(); |
| 1835 | |
| 1836 | // |
| 1837 | // Update the default admin user with their information. |
| 1838 | // |
| 1839 | $sql = "SELECT MIN(user_regdate) AS oldest_time |
| 1840 | FROM " . USERS_TABLE . " |
| 1841 | WHERE user_regdate > 0 AND user_id > 0"; |
| 1842 | $result = query($sql, "Couldn't obtain oldest post time"); |
| 1843 | |
| 1844 | $row = $db->sql_fetchrow($result); |
| 1845 | |
| 1846 | $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value) |
| 1847 | VALUES ('board_startdate', " . $row['oldest_time'] . ")";
|
| 1848 | query($sql, "Couldn't insert board_startdate"); |
| 1849 | |
| 1850 | $sql = "UPDATE " . $table_prefix . "config |
| 1851 | SET config_value = '" . $server_name . "' |
| 1852 | WHERE config_name = 'server_name' |
| 1853 | OR config_name = 'cookie_domain'"; |
| 1854 | query($sql, "Couldn't insert Board Server domain"); |
| 1855 | |
| 1856 | $sql = "UPDATE " . $table_prefix . "config |
| 1857 | SET config_value = '" . $server_port . "' |
| 1858 | WHERE config_name = 'server_port'"; |
| 1859 | query($sql, "Couldn't insert Board server port"); |
| 1860 | |
| 1861 | $sql = "UPDATE " . $table_prefix . "config |
| 1862 | SET config_value = '" . $board_email . "' |
| 1863 | WHERE config_name = 'board_email'"; |
| 1864 | query($sql, "Couldn't insert Board admin email"); |
| 1865 | |
| 1866 | $sql = "UPDATE " . $table_prefix . "config |
| 1867 | SET config_value = '" . $script_path . "' |
| 1868 | WHERE config_name = 'script_path'"; |
| 1869 | query($sql, "Couldn't insert Board admin email"); |
| 1870 | |
| 1871 | // |
| 1872 | // Change session table to HEAP if MySQL version matches |
| 1873 | // |
| 1874 | $sql = "SELECT VERSION() AS mysql_version"; |
| 1875 | $result = query($sql, "Couldn't obtain MySQL Version"); |
| 1876 | |
| 1877 | $row = $db->sql_fetchrow($result); |
| 1878 | |
| 1879 | $version = $row['mysql_version']; |
| 1880 | |
| 1881 | if ( preg_match("/^(3\.23)|(4\.)/", $version) )
|
| 1882 | {
|
| 1883 | $sql = "ALTER TABLE " . $table_prefix . "sessions |
| 1884 | TYPE=HEAP"; |
| 1885 | $db->sql_query($sql); |
| 1886 | } |
| 1887 | |
| 1888 | echo "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1889 | end_step('drop_fields');
|
| 1890 | |
| 1891 | case 'drop_fields': |
| 1892 | $fields = array( |
| 1893 | BANLIST_TABLE => array("ban_start", "ban_end", "ban_time_type"),
|
| 1894 | FORUMS_TABLE => array("forum_access", "forum_moderator", "forum_type"),
|
| 1895 | PRIVMSGS_TABLE => array("msg_text"),
|
| 1896 | RANKS_TABLE => array("rank_max"),
|
| 1897 | SMILIES_TABLE => array("emotion"),
|
| 1898 | TOPICS_TABLE => array("topic_notify")
|
| 1899 | ); |
| 1900 | |
| 1901 | while( list($table, $field_data) = each($fields) ) |
| 1902 | {
|
| 1903 | for($i = 0; $i < count($field_data); $i++) |
| 1904 | {
|
| 1905 | print " * Drop field '" . $field_data[$i] . "' in '$table' :: "; |
| 1906 | flush(); |
| 1907 | |
| 1908 | $sql = "ALTER TABLE $table |
| 1909 | DROP COLUMN " . $field_data[$i]; |
| 1910 | query($sql, "Couldn't drop field :: " . $field_data[$i] . " from table :: $table"); |
| 1911 | |
| 1912 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1913 | |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | end_step('drop_tables');
|
| 1918 | |
| 1919 | case 'drop_tables': |
| 1920 | $drop_tables = array('access', 'forum_access', 'forum_mods', 'headermetafooter', 'whosonline', $table_prefix . 'old_config');
|
| 1921 | |
| 1922 | for($i = 0; $i < count($drop_tables); $i++) |
| 1923 | {
|
| 1924 | print " * Dropping table '" . $drop_tables[$i] . "' :: "; |
| 1925 | flush(); |
| 1926 | |
| 1927 | $sql = "DROP TABLE " . $drop_tables[$i]; |
| 1928 | query($sql, "Couldn't drop table :: " . $drop_tables[$i]); |
| 1929 | |
| 1930 | print "<span class=\"ok\"><b>OK</b></span><br />\n"; |
| 1931 | } |
| 1932 | |
| 1933 | echo "\n<br /><br />\n\n<font size=\"+3\"><b>UPGRADE COMPLETED</b></font><br />\n"; |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | print "<br />If the upgrade completed without error you may click <a href=\"index.$phpEx\">Here</a> to proceed to the index<br />"; |
| 1938 | |
| 1939 | common_footer(); |
| 1940 | |
| 1941 | ?> |
| 1942 |