Verzeichnisstruktur phpBB-2.0.0
- Veröffentlicht
- 03.04.2002
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
upgrade.php
0001 <?php
0002 /***************************************************************************
0003 * upgrade.php
0004 * -------------------
0005 * begin : Wed Sep 05 2001
0006 * copyright : (C) 2001 The phpBB Group
0007 * email : support@phpbb.com
0008 *
0009 * $Id$
0010 *
0011 ****************************************************************************/
0012
0013 /***************************************************************************
0014 *
0015 * This program is free software; you can redistribute it and/or modify
0016 * it under the terms of the GNU General Public License as published by
0017 * the Free Software Foundation; either version 2 of the License, or
0018 * (at your option) any later version.
0019 *
0020 ***************************************************************************/
0021
0022 define('IN_PHPBB', true);
0023
0024 $phpbb_root_path = './../';
0025
0026 if ( !defined('INSTALLING') )
0027 {
0028 error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
0029 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
0030
0031 //
0032 // If we are being called from the install script then we don't need these
0033 // as they are already included.
0034 //
0035 include($phpbb_root_path . 'extension.inc');
0036 include($phpbb_root_path . 'config.'.$phpEx);
0037 include($phpbb_root_path . 'includes/constants.'.$phpEx);
0038 include($phpbb_root_path . 'includes/functions.'.$phpEx);
0039
0040 if( defined("PHPBB_INSTALLED") )
0041 {
0042 redirect("../index.$phpEx");
0043 }
0044 }
0045
0046 //
0047 // Force the DB type to be MySQL
0048 //
0049 $dbms = 'mysql';
0050
0051 include($phpbb_root_path . 'includes/db.'.$phpEx);
0052 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
0053 include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
0054
0055 set_time_limit(0); // Unlimited execution time
0056
0057 $months = array(
0058 'Jan' => 1,
0059 'Feb' => 2,
0060 'Mar' => 3,
0061 'Apr' => 4,
0062 'May' => 5,
0063 'Jun' => 6,
0064 'Jul' => 7,
0065 'Aug' => 8,
0066 'Sep' => 9,
0067 'Sept' => 9,
0068 'Oct' => 10,
0069 'Nov' => 11,
0070 'Dec' => 12
0071 );
0072
0073 // ---------------
0074 // Begin functions
0075 //
0076 function common_header()
0077 {
0078 ?>
0079 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
0080 <html>
0081 <head>
0082 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
0083 <meta http-equiv="Content-Style-Type" content="text/css">
0084 <style type="text/css">
0085 <!--
0086 /* Specifiy background images for selected styles
0087 This can't be done within the external style sheet as NS4 sees image paths relative to
0088 the page which called the style sheet (i.e. this page in the root phpBB directory)
0089 whereas all other browsers see image paths relative to the style sheet. Stupid NS again!
0090 */
0091 th { background-image: url('../templates/subSilver/images/cellpic3.gif') }
0092 td.cat { background-image: url('../templates/subSilver/images/cellpic1.gif') }
0093 td.rowpic { background-image: url('../templates/subSilver/images/cellpic2.jpg'); background-repeat: repeat-y }
0094 td.catHead,td.catSides,td.catLeft,td.catRight,td.catBottom { background-image: url('../templates/subSilver/images/cellpic1.gif') }
0095
0096 font,th,td,p,body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt }
0097 a:link,a:active,a:visited { font-family: Verdana, Arial, Helvetica, sans-serif; color : #006699; font-size:11pt }
0098 a:hover { font-family: Verdana, Arial, Helvetica, sans-serif; text-decoration: underline; color : #DD6900; font-size:11pt }
0099 hr { height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
0100
0101 .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;}
0102
0103 .ok {color:green}
0104
0105 /* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
0106 @import url("../templates/subSilver/formIE.css");
0107 -->
0108 </style>
0109 </head>
0110 <body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">
0111
0112 <table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
0113 <tr>
0114 <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
0115 <tr>
0116 <td><img src="../templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
0117 <td align="center" width="100%" valign="middle"><span class="maintitle">Upgrading to phpBB 2.0</span></td>
0118 </tr>
0119 </table></td>
0120 </tr>
0121 </table>
0122
0123 <br clear="all" />
0124
0125 <?
0126 return;
0127 }
0128
0129 function common_footer()
0130 {
0131 ?>
0132
0133 <br clear="all" />
0134
0135 </body>
0136 </html>
0137 <?
0138 return;
0139 }
0140
0141 function query($sql, $errormsg)
0142 {
0143 global $db;
0144
0145 if ( !($result = $db->sql_query($sql)) )
0146 {
0147 print "<br><font color=\"red\">\n";
0148 print "$errormsg<br>";
0149
0150 $sql_error = $db->sql_error();
0151 print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
0152
0153 print "<pre>$sql</pre>";
0154 print "</font>\n";
0155
0156 return FALSE;
0157 }
0158 else
0159 {
0160 return $result;
0161 }
0162 }
0163
0164 function smiley_replace($text = '')
0165 {
0166 global $db;
0167
0168 static $search, $replace;
0169
0170 // Did we get the smiley info in a previous call?
0171 if ( !is_array($search) )
0172 {
0173 $sql = "SELECT code, smile_url
0174 FROM smiles";
0175 $result = query($sql, "Unable to get list of smilies from the DB");
0176
0177 $smilies = $db->sql_fetchrowset($result);
0178 @usort($smilies, 'smiley_sort');
0179
0180 $search = array();
0181 $replace = array();
0182 for($i = 0; $i < count($smilies); $i++)
0183 {
0184 $search[] = '/<IMG SRC=".*?\/' . phpbb_preg_quote($smilies[$i]['smile_url'], '/') .'">/i';
0185 $replace[] = $smilies[$i]['code'];
0186 }
0187 }
0188
0189 return ( $text != '' ) ? preg_replace($search, $replace, $text) : '';
0190
0191 }
0192
0193 function get_schema()
0194 {
0195 global $table_prefix;
0196
0197 $schemafile = file('schemas/mysql_schema.sql');
0198 $tabledata = 0;
0199
0200 for($i=0; $i < count($schemafile); $i++)
0201 {
0202 $line = $schemafile[$i];
0203
0204 if ( preg_match('/^CREATE TABLE (\w+)/i', $line, $matches) )
0205 {
0206 // Start of a new table definition, set some variables and go to the next line.
0207 $tabledata = 1;
0208 // Replace the 'phpbb_' prefix by the user defined prefix.
0209 $table = str_replace('phpbb_', $table_prefix, $matches[1]);
0210 $table_def[$table] = "CREATE TABLE $table (\n";
0211 continue;
0212 }
0213
0214 if ( preg_match('/^\);/', $line) )
0215 {
0216 // End of the table definition
0217 // After this we will skip everything until the next 'CREATE' line
0218 $tabledata = 0;
0219 $table_def[$table] .= ')'; // We don't need the closing semicolon
0220 }
0221
0222 if ( $tabledata == 1 )
0223 {
0224 // We are inside a table definition, parse this line.
0225 // Add the current line to the complete table definition:
0226 $table_def[$table] .= $line;
0227 if ( preg_match('/^\s*(\w+)\s+(\w+)\(([\d,]+)\)(.*)$/', $line, $matches) )
0228 {
0229 // This is a column definition
0230 $field = $matches[1];
0231 $type = $matches[2];
0232 $size = $matches[3];
0233
0234 preg_match('/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i', $matches[4], $match);
0235 $default = $match[1];
0236
0237 $notnull = ( preg_match('/NOT NULL/i', $matches[4]) ) ? 1 : 0;
0238 $auto_increment = ( preg_match('/auto_increment/i', $matches[4]) ) ? 1 : 0;
0239
0240 $field_def[$table][$field] = array(
0241 'type' => $type,
0242 'size' => $size,
0243 'default' => $default,
0244 'notnull' => $notnull,
0245 'auto_increment' => $auto_increment
0246 );
0247 }
0248
0249 if ( preg_match('/\s*PRIMARY\s+KEY\s*\((.*)\).*/', $line, $matches) )
0250 {
0251 // Primary key
0252 $key_def[$table]['PRIMARY'] = $matches[1];
0253 }
0254 else if ( preg_match('/\s*KEY\s+(\w+)\s*\((.*)\)/', $line, $matches) )
0255 {
0256 // Normal key
0257 $key_def[$table][$matches[1]] = $matches[2];
0258 }
0259 else if ( preg_match('/^\s*(\w+)\s*(.*?),?\s*$/', $line, $matches) )
0260 {
0261 // Column definition
0262 $create_def[$table][$matches[1]] = $matches[2];
0263 }
0264 else
0265 {
0266 // It's a bird! It's a plane! It's something we didn't expect ;(
0267 }
0268 }
0269 }
0270
0271 $schema['field_def'] = $field_def;
0272 $schema['table_def'] = $table_def;
0273 $schema['create_def'] = $create_def;
0274 $schema['key_def'] = $key_def;
0275
0276 return $schema;
0277 }
0278
0279 function get_inserts()
0280 {
0281 global $table_prefix;
0282
0283 $insertfile = file('schemas/mysql_basic.sql');
0284
0285 for($i = 0; $i < count($insertfile); $i++)
0286 {
0287 if ( preg_match('/(INSERT INTO (\w+)\s.*);/i', str_replace('phpbb_', $table_prefix, $insertfile[$i]), $matches) )
0288 {
0289 $returnvalue[$matches[2]][] = $matches[1];
0290 }
0291 }
0292
0293 return $returnvalue;
0294 }
0295
0296 function lock_tables($state, $tables= '')
0297 {
0298 if ( $state == 1 )
0299 {
0300 if ( is_array($tables) )
0301 {
0302 $tables = join(' WRITE, ', $tables);
0303 }
0304
0305 query("LOCK TABLES $tables WRITE", "Couldn't do: $sql");
0306 }
0307 else
0308 {
0309 query("UNLOCK TABLES", "Couldn't unlock all tables");
0310 }
0311 }
0312
0313 function output_table_content($content)
0314 {
0315 echo $content . "\n";
0316
0317 return;
0318 }
0319
0320 //
0321 // Nathan's bbcode2 conversion routines
0322 //
0323 function bbdecode($message)
0324 {
0325 // Undo [code]
0326 $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>';
0327 $code_end_html = '</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->';
0328 $message = str_replace($code_start_html, '[code]', $message);
0329 $message = str_replace($code_end_html, '[/code]', $message);
0330
0331 // Undo [quote]
0332 $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>';
0333 $quote_end_html = '</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->';
0334 $message = str_replace($quote_start_html, '[quote]', $message);
0335 $message = str_replace($quote_end_html, '[/quote]', $message);
0336
0337 // Undo [b] and [i]
0338 $message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
0339 $message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
0340
0341 // Undo [url] (long form)
0342 $message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message);
0343
0344 // Undo [url] (short form)
0345 $message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message);
0346
0347 // Undo [email]
0348 $message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
0349
0350 // Undo [img]
0351 $message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
0352
0353 // Undo lists (unordered/ordered)
0354
0355 // <li> tags:
0356 $message = str_replace('<!-- BBCode --><LI>', '[*]', $message);
0357
0358 // [list] tags:
0359 $message = str_replace('<!-- BBCode ulist Start --><UL>', '[list]', $message);
0360
0361 // [list=x] tags:
0362 $message = preg_replace('#<!-- BBCode olist Start --><OL TYPE=([A1])>#si', "[list=\\1]", $message);
0363
0364 // [/list] tags:
0365 $message = str_replace('</UL><!-- BBCode ulist End -->', '[/list]', $message);
0366 $message = str_replace('</OL><!-- BBCode olist End -->', '[/list]', $message);
0367
0368 return $message;
0369 }
0370
0371 //
0372 // Alternative for in_array() which is only available in PHP4
0373 //
0374 function inarray($needle, $haystack)
0375 {
0376 for( $i = 0 ; $i < sizeof($haystack) ; $i++ )
0377 {
0378 if ( $haystack[$i] == $needle )
0379 {
0380 return true;
0381 }
0382 }
0383
0384 return false;
0385 }
0386
0387 function end_step($next)
0388 {
0389 print "<hr /><a href=\"$PHP_SELF?next=$next\">Next step: <b>$next</b></a><br /><br />\n";
0390 exit;
0391 }
0392 //
0393 // End functions
0394 // -------------
0395
0396
0397 //
0398 // Start at the beginning if the user hasn't specified a specific starting point.
0399 //
0400 $next = ( isset($HTTP_GET_VARS['next']) ) ? $HTTP_GET_VARS['next'] : 'start';
0401
0402 // If debug is set we'll do all steps in one go.
0403 $debug = 1;
0404
0405 // Parse the MySQL schema file into some arrays.
0406 $schema = get_schema();
0407
0408 $table_def = $schema['table_def'];
0409 $field_def = $schema['field_def'];
0410 $key_def = $schema['key_def'];
0411 $create_def = $schema['create_def'];
0412
0413 //
0414 // Get mysql_basic data
0415 //
0416 $inserts = get_inserts();
0417
0418 //
0419 // Get smiley data
0420 //
0421 smiley_replace();
0422
0423 common_header();
0424
0425 if ( !empty($next) )
0426 {
0427 switch($next)
0428 {
0429 case 'start':
0430 end_step('initial_drops');
0431
0432 case 'initial_drops':
0433 print " * Dropping sessions and themes tables :: ";
0434 flush();
0435
0436 query("DROP TABLE sessions", "Couldn't drop table 'sessions'");
0437 query("DROP TABLE themes", "Couldn't drop table 'themes'");
0438
0439 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0440
0441 end_step('mod_old_tables');
0442
0443 case 'mod_old_tables':
0444 $modtables = array(
0445 "banlist" => "banlist",
0446 "catagories" => "categories",
0447 "config" => "old_config",
0448 "forums" => "forums",
0449 "disallow" => "disallow",
0450 "posts" => "posts",
0451 "posts_text" => "posts_text",
0452 "priv_msgs" => "privmsgs",
0453 "ranks" => "ranks",
0454 "smiles" => "smilies",
0455 "topics" => "topics",
0456 "users" => "users",
0457 "words" => "words"
0458 );
0459
0460 while( list($old, $new) = each($modtables) )
0461 {
0462 $result = query("SHOW INDEX FROM $old", "Couldn't get list of indices for table $old");
0463
0464 while( $row = $db->sql_fetchrow($result) )
0465 {
0466 $index = $row['Key_name'];
0467 if ( $index != 'PRIMARY' )
0468 {
0469 query("ALTER TABLE $old DROP INDEX $index", "Couldn't DROP INDEX $old.$index");
0470 }
0471 }
0472
0473 // Rename table
0474 $new = $table_prefix . $new;
0475
0476 print " * Renaming '$old' to '$new' :: ";
0477 flush();
0478 query("ALTER TABLE $old RENAME $new", "Failed to rename $old to $new");
0479 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0480
0481 }
0482 end_step('create_tables');
0483
0484 case 'create_tables':
0485 // Create array with tables in 'old' database
0486 $result = query('SHOW TABLES', "Couldn't get list of current tables");
0487
0488 while( $table = $db->sql_fetchrow($result) )
0489 {
0490 $currenttables[] = $table[0];
0491 }
0492
0493 // Check what tables we need to CREATE
0494 while( list($table, $definition) = each($table_def) )
0495 {
0496 if ( !inarray($table, $currenttables) )
0497 {
0498 print " * Creating $table :: ";
0499
0500 query($definition, "Couldn't create table $table");
0501
0502 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0503 }
0504 }
0505
0506 end_step('create_config');
0507
0508 case 'create_config':
0509 print " * Inserting new values into new layout config table :: ";
0510
0511 @reset($inserts);
0512 while( list($table, $inserts_table) = each($inserts) )
0513 {
0514 if ( $table == CONFIG_TABLE )
0515 {
0516 $per_pct = ceil( count($inserts_table) / 40 );
0517 $inc = 0;
0518
0519 while( list($nr, $insert) = each($inserts_table) )
0520 {
0521 query($insert, "Couldn't insert value into config table");
0522
0523 $inc++;
0524 if ( $inc == $per_pct )
0525 {
0526 print ".";
0527 flush();
0528 $inc = 0;
0529 }
0530 }
0531 }
0532 }
0533
0534 print " <span class=\"ok\"><b>OK</b></span><br />\n";
0535
0536 end_step('convert_config');
0537
0538 case 'convert_config':
0539 print " * Converting configuration table :: ";
0540
0541 $sql = "SELECT *
0542 FROM $table_prefix" . "old_config";
0543 $result = query($sql, "Couldn't get info from old config table");
0544
0545 $oldconfig = $db->sql_fetchrow($result);
0546
0547 //
0548 // We don't need several original config types and two others
0549 // have changed name ... so take account of this.
0550 //
0551 $ignore_configs = array("selected", "admin_passwd", "override_themes", "allow_sig");
0552 $rename_configs = array(
0553 "email_from" => "board_email",
0554 "email_sig" => "board_email_sig"
0555 );
0556
0557 while( list($name, $value) = each($oldconfig) )
0558 {
0559 if ( is_int($name) )
0560 {
0561 continue;
0562 }
0563
0564 if ( !inarray($name, $ignore_configs) )
0565 {
0566 $name = ( !empty($rename_configs[$name]) ) ? $rename_configs[$name] : $name;
0567
0568 // phpBB 1.x has some problems with escaping strings in the database. Try to correct for
0569 // this by removing all slashes and then escaping once.
0570 $sql = "REPLACE INTO " . CONFIG_TABLE . " (config_name, config_value)
0571 VALUES ('$name', '".addslashes(stripslashes(stripslashes($value)))."')";
0572 query($sql, "Couldn't update config table with values from old config table");
0573 }
0574 }
0575
0576 $sql = "UPDATE " . CONFIG_TABLE . "
0577 SET config_value = 'dutch'
0578 WHERE config_name = 'default_lang' && config_value = 'nederlands'";
0579 query($sql, "Couldn't rename 'nederlands' to 'dutch' in config table");
0580
0581 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0582 end_step('convert_ips');
0583
0584 case 'convert_ips':
0585 $names = array(
0586 POSTS_TABLE => array(
0587 'id' => 'post_id',
0588 'field' => 'poster_ip'
0589 ),
0590 PRIVMSGS_TABLE => array(
0591 'id' => 'msg_id',
0592 'field' => 'poster_ip'
0593 ),
0594 BANLIST_TABLE => array(
0595 'id' => 'ban_id',
0596 'field' => 'ban_ip'
0597 )
0598 );
0599
0600 lock_tables(1, array(POSTS_TABLE, PRIVMSGS_TABLE, BANLIST_TABLE));
0601
0602 $batchsize = 2000;
0603 while( list($table, $data_array) = each($names) )
0604 {
0605 $sql = "SELECT MAX(" . $data_array['id'] . ") AS max_id
0606 FROM $table";
0607 $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
0608
0609 $row = $db->sql_fetchrow($result);
0610
0611 $maxid = $row['max_id'];
0612
0613 for($i = 0; $i <= $maxid; $i += $batchsize)
0614 {
0615 $batchstart = $i;
0616 $batchend = $i + $batchsize;
0617
0618 $field_id = $data_array['id'];
0619 $field = $data_array['field'];
0620
0621 print " * Converting IP format '" . $field . "' / '$table' ( $batchstart to $batchend ) :: ";
0622 flush();
0623
0624 $sql = "SELECT $field_id, $field
0625 FROM $table
0626 WHERE $field_id
0627 BETWEEN $batchstart
0628 AND $batchend";
0629 $result = query($sql, "Couldn't obtain ip data from $table (" . $fields . ")");
0630
0631 $per_pct = ceil( $db->sql_numrows($result) / 40 );
0632 $inc = 0;
0633
0634 while( $row = $db->sql_fetchrow($result) )
0635 {
0636 $sql = "UPDATE $table
0637 SET $field = '" . encode_ip($row[$field]) . "'
0638 WHERE $field_id = " . $row[$field_id];
0639 query($sql, "Couldn't convert IP format of $field in $table with $field_id of " . $rowset[$field_id]);
0640
0641 $inc++;
0642 if ( $inc == $per_pct )
0643 {
0644 print ".";
0645 flush();
0646 $inc = 0;
0647 }
0648 }
0649
0650 print " <span class=\"ok\"><b>OK</b></span><br />\n";
0651 }
0652 }
0653
0654 lock_tables(0);
0655 end_step('convert_dates');
0656
0657 case 'convert_dates':
0658 $names = array(
0659 POSTS_TABLE => array('post_time'),
0660 TOPICS_TABLE => array('topic_time'),
0661 PRIVMSGS_TABLE => array('msg_time')
0662 );
0663
0664 lock_tables(1, array(POSTS_TABLE, TOPICS_TABLE, PRIVMSGS_TABLE));
0665
0666 while( list($table, $fields) = each($names) )
0667 {
0668 print " * Converting date format of $fields[$i] in $table :: ";
0669 flush();
0670
0671 for($i = 0; $i < count($fields); $i++)
0672 {
0673 $sql = "UPDATE $table
0674 SET " . $fields[$i] . " = UNIX_TIMESTAMP(" . $fields[$i] . ")";
0675 query($sql, "Couldn't convert date format of $table(" . $fields[$i] . ")");
0676 }
0677
0678 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0679 }
0680
0681 lock_tables(0);
0682 end_step('fix_addslashes');
0683
0684 case 'fix_addslashes':
0685 $slashfields[TOPICS_TABLE] = array('topic_title');
0686 $slashfields[FORUMS_TABLE] = array('forum_desc', 'forum_name');
0687 $slashfields[CATEGORIES_TABLE] = array('cat_title');
0688 $slashfields[WORDS_TABLE] = array('word', 'replacement');
0689 $slashfields[RANKS_TABLE] = array('rank_title');
0690 $slashfields[DISALLOW_TABLE] = array('disallow_username');
0691
0692 //convert smilies?
0693 $slashes = array(
0694 "\\'" => "'",
0695 "\\\"" => "\"",
0696 "\\\\" => "\\");
0697 $slashes = array(
0698 "\\'" => "'",
0699 "\\\"" => "\"",
0700 "\\\\" => "\\");
0701
0702 lock_tables(1, array(TOPICS_TABLE, FORUMS_TABLE, CATEGORIES_TABLE, WORDS_TABLE, RANKS_TABLE, DISALLOW_TABLE, SMILIES_TABLE));
0703
0704 while( list($table, $fields) = each($slashfields) )
0705 {
0706 print " * Removing slashes from $table table :: ";
0707 flush();
0708
0709 while( list($nr, $field) = each($fields) )
0710 {
0711 @reset($slashes);
0712 while( list($search, $replace) = each($slashes) )
0713 {
0714 $sql = "UPDATE $table
0715 SET $field = REPLACE($field, '" . addslashes($search) . "', '" . addslashes($replace) . "')";
0716 query($sql, "Couldn't remove extraneous slashes from the old data.");
0717 }
0718 }
0719
0720 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0721 }
0722
0723 lock_tables(0);
0724 end_step('remove_topics');
0725
0726 case 'remove_topics':
0727 print " * Removing posts with no corresponding topics :: ";
0728 flush();
0729
0730 $sql = "SELECT p.post_id
0731 FROM " . POSTS_TABLE . " p
0732 LEFT JOIN " . TOPICS_TABLE . " t ON p.topic_id = t.topic_id
0733 WHERE t.topic_id IS NULL";
0734 $result = query($sql, "Couldn't obtain list of deleted topics");
0735
0736 $post_total = $db->sql_numrows($result);
0737
0738 if ( $post_total )
0739 {
0740 $post_id_ary = array();
0741 while( $row = $db->sql_fetchrow($result) )
0742 {
0743 $post_id_ary[] = $row['post_id'];
0744 }
0745
0746 $sql = "DELETE FROM " . POSTS_TABLE . "
0747 WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
0748 query($sql, "Couldn't update posts to remove deleted user poster_id values");
0749
0750 $sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
0751 WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
0752 query($sql, "Couldn't update posts to remove deleted user poster_id values");
0753 }
0754
0755 echo "<span class=\"ok\"><b>OK</b></span> ( Removed $post_total posts )<br />\n";
0756 end_step('convert_users');
0757
0758 case 'convert_users':
0759 //
0760 // Completely remove old soft-deleted users
0761 //
0762 $sql = "DELETE FROM " . USERS_TABLE . "
0763 WHERE user_level = -1";
0764 query($sql, "Couldn't delete old soft-deleted users");
0765
0766 $sql = "SELECT COUNT(*) AS total, MAX(user_id) AS maxid
0767 FROM " . USERS_TABLE;
0768 $result = query($sql, "Couldn't get max user_id.");
0769
0770 $row = $db->sql_fetchrow($result);
0771
0772 $totalposts = $row['total'];
0773 $maxid = $row['maxid'];
0774
0775 $sql = "ALTER TABLE " . USERS_TABLE . "
0776 ADD user_sig_bbcode_uid CHAR(10),
0777 MODIFY user_sig text";
0778 query($sql, "Couldn't add user_sig_bbcode_uid field to users table");
0779
0780 $super_mods = array();
0781 $first_admin = -2;
0782
0783 $batchsize = 1000;
0784 for($i = -1; $i <= $maxid; $i += $batchsize)
0785 {
0786 $batchstart = $i;
0787 $batchend = $i + $batchsize;
0788
0789 print " * Converting Users ( $batchstart to $batchend ) :: ";
0790 flush();
0791
0792 $sql = "SELECT *
0793 FROM " . USERS_TABLE . "
0794 WHERE user_id
0795 BETWEEN $batchstart
0796 AND $batchend";
0797 $result = query($sql, "Couldn't get ". USERS_TABLE .".user_id $batchstart to $batchend");
0798
0799 // Array with user fields that we want to check for invalid data (to few characters)
0800 $checklength = array(
0801 'user_occ',
0802 'user_website',
0803 'user_email',
0804 'user_from',
0805 'user_intrest',
0806 'user_aim',
0807 'user_yim',
0808 'user_msnm');
0809
0810 lock_tables(1, array(USERS_TABLE, GROUPS_TABLE, USER_GROUP_TABLE, POSTS_TABLE));
0811
0812 $per_pct = ceil( $db->sql_numrows($result) / 40 );
0813 $inc = 0;
0814
0815 while( $row = $db->sql_fetchrow($result) )
0816 {
0817 $sql = "INSERT INTO " . GROUPS_TABLE . " (group_name, group_description, group_single_user)
0818 VALUES ('" . addslashes($row['username']) . "', 'Personal User', 1)";
0819 query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".GROUPS_TABLE);
0820
0821 $group_id = $db->sql_nextid();
0822
0823 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
0824 VALUES ($group_id, " . $row['user_id'] . ", 0)";
0825 query($sql, "Wasn't able to insert user ".$row['user_id']." into table ".USER_GROUP_TABLE);
0826
0827 if ( is_int($row['user_regdate']) )
0828 {
0829 // We already converted this post to the new style BBcode, skip this post.
0830 continue;
0831 }
0832
0833 //
0834 // Nathan's bbcode2 conversion
0835 //
0836
0837 // undo 1.2.x encoding..
0838 $row['user_sig'] = bbdecode(stripslashes($row['user_sig']));
0839 $row['user_sig'] = undo_make_clickable($row['user_sig']);
0840 $row['user_sig'] = str_replace("<BR>", "\n", $row['user_sig']);
0841
0842 // make a uid
0843 $uid = make_bbcode_uid();
0844
0845 // do 2.x first-pass encoding..
0846 $row['user_sig'] = bbencode_first_pass($row['user_sig'], $uid);
0847 $row['user_sig'] = addslashes($row['user_sig']);
0848
0849 // Check for invalid info like '-' and '?' for a lot of fields
0850 @reset($checklength);
0851 while($field = each($checklength))
0852 {
0853 $row[$field[1]] = strlen($row[$field[1]]) < 3 ? '' : $row[$field[1]];
0854 }
0855
0856 preg_match('/(.*?) (\d{1,2}), (\d{4})/', $row['user_regdate'], $parts);
0857 $row['user_regdate'] = gmmktime(0, 0, 0, $months[$parts[1]], $parts[2], $parts[3]);
0858
0859 $website = $row['user_website'];
0860 if ( substr(strtolower($website), 0, 7) != "http://" )
0861 {
0862 $website = "http://" . $website;
0863 }
0864 if( strtolower($website) == 'http://' )
0865 {
0866 $website = '';
0867 }
0868 $row['user_website'] = addslashes($website);
0869
0870 $row['user_icq'] = (ereg("^[0-9]+$", $row['user_icq'])) ? $row['user_icq'] : '';
0871 @reset($checklength);
0872
0873 while($field = each($checklength))
0874 {
0875 if ( strlen($row[$field[1]]) < 3 )
0876 {
0877 $row[$field[1]] = '';
0878 }
0879 $row[$field[1]] = addslashes($row[$field[1]]);
0880 }
0881
0882 //
0883 // Is user a super moderator?
0884 //
0885 if( $row['user_level'] == 3 )
0886 {
0887 $super_mods[] = $row['user_id'];
0888 }
0889
0890 $row['user_level'] = ( $row['user_level'] == 4 ) ? ADMIN : USER;
0891
0892 //
0893 // Used to define a 'practical' group moderator user_id
0894 // for super mods a little latter.
0895 //
0896 if( $first_admin == -2 && $row['user_level'] == ADMIN )
0897 {
0898 $first_admin = $row['user_id'];
0899 }
0900
0901 //
0902 // Dutch language files have been renamed from 'nederlands' to 'dutch'
0903 //
0904 if( $row['user_lang'] == 'nederlands' )
0905 {
0906 $row['user_lang'] = 'dutch';
0907 }
0908
0909 $sql = "UPDATE " . USERS_TABLE . "
0910 SET
0911 user_sig = '" . $row['user_sig'] . "',
0912 user_sig_bbcode_uid = '$uid',
0913 user_regdate = '" . $row['user_regdate'] . "',
0914 user_website = '" . $row['user_website'] . "',
0915 user_occ = '" . $row['user_occ'] . "',
0916 user_email = '" . $row['user_email'] . "',
0917 user_from = '" . $row['user_from'] . "',
0918 user_intrest = '" . $row['user_intrest'] . "',
0919 user_aim = '" . $row['user_aim'] . "',
0920 user_yim = '" . $row['user_yim'] . "',
0921 user_msnm = '" . $row['user_msnm'] . "',
0922 user_level = '" . $row['user_level'] . "',
0923 user_desmile = NOT(user_desmile),
0924 user_bbcode = 1,
0925 user_theme = 1
0926 WHERE user_id = " . $row['user_id'];
0927 query($sql, "Couldn't update ".USERS_TABLE." table with new BBcode and regdate for user_id ".$row['user_id']);
0928
0929 $inc++;
0930 if ( $inc == $per_pct )
0931 {
0932 print ".";
0933 flush();
0934 $inc = 0;
0935 }
0936 }
0937
0938 // Set any non-standard (like) email addresses to nothing
0939 // could do this above as a preg_ but this one query may
0940 // be faster
0941 $sql = "UPDATE " . USERS_TABLE . "
0942 SET user_email = ''
0943 WHERE user_email NOT REGEXP '^[a-zA-Z0-9_\+\.\-]+@.*[a-zA-Z0-9\-_]+\.[a-zA-Z]{2,}$'";
0944 query($sql, "Couldn't update ".USERS_TABLE." table non-standard user_email entries");
0945
0946 print " <span class=\"ok\"><b>OK</b></span><br />\n";
0947
0948 lock_tables(0);
0949 }
0950
0951 //
0952 // Handle super-mods, create hidden group for them
0953 //
0954 // Iterate trough access table
0955 if( count($super_mods) && $first_admin != -2 )
0956 {
0957 print "\n<br />\n * Creating new group for super moderators :: ";
0958 flush();
0959
0960 $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
0961 VALUES (" . GROUP_HIDDEN . ", 'Super Moderators', 'Converted super moderators', $first_admin, 0)";
0962 $result = query($sql, "Couldn't create group for ".$row['forum_name']);
0963
0964 $group_id = $db->sql_nextid();
0965
0966 if ( $group_id <= 0 )
0967 {
0968 print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n";
0969 continue 2;
0970 }
0971
0972 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0973
0974 print " * Updating auth_access for super moderator group :: ";
0975 flush();
0976
0977 $sql = "SELECT forum_id
0978 FROM " . FORUMS_TABLE;
0979 $result = query($sql, "Couldn't obtain forum_id list");
0980
0981 while( $row = $db->sql_fetchrow($result) )
0982 {
0983 $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod)
0984 VALUES ($group_id, " . $row['forum_id'] . ", 1)";
0985 $result_insert = query($sql, "Unable to set group auth access for super mods.");
0986 }
0987
0988 for($i = 0; $i < count($super_mods); $i++)
0989 {
0990 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
0991 VALUES ($group_id, " . $super_mods[$i] . ", 0)";
0992 query($sql, "Unable to add user_id $user_id to group_id $group_id (super mods)<br>\n");
0993 }
0994
0995 print "<span class=\"ok\"><b>OK</b></span><br />\n";
0996 }
0997
0998 end_step('convert_posts');
0999
1000 case 'convert_posts':
1001 print " * Adding enable_sig field to " . POSTS_TABLE . " :: ";
1002 flush();
1003 $sql = "ALTER TABLE " . POSTS_TABLE . "
1004 ADD enable_sig tinyint(1) DEFAULT '1' NOT NULL";
1005 $result = query($sql, "Couldn't add enable_sig field to " . POSTS_TABLE . ".");
1006 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1007
1008 print " * Adding enable_bbcode field to " . POSTS_TEXT_TABLE . " :: ";
1009 flush();
1010 $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . "
1011 ADD enable_bbcode tinyint(1) DEFAULT '1' NOT NULL";
1012 $result = query($sql, "Couldn't add enable_bbcode field to " . POSTS_TABLE . ".");
1013 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1014
1015 print " * Adding bbcode_uid field to " . POSTS_TEXT_TABLE . " :: ";
1016 flush();
1017 $sql = "ALTER TABLE " . POSTS_TEXT_TABLE . "
1018 ADD bbcode_uid char(10) NOT NULL";
1019 $result = query($sql, "Couldn't add bbcode_uid field to " . POSTS_TABLE . ".");
1020 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1021
1022 print " * Adding post_edit_time field to " . POSTS_TABLE . " :: ";
1023 flush();
1024 $sql = "ALTER TABLE " . POSTS_TABLE . "
1025 ADD post_edit_time int(11)";
1026 $result = query($sql, "Couldn't add post_edit_time field to " . POSTS_TABLE . ".");
1027 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1028
1029 print " * Adding post_edit_count field to " . POSTS_TABLE . " :: ";
1030 flush();
1031 $sql = "ALTER TABLE " . POSTS_TABLE . "
1032 ADD post_edit_count smallint(5) UNSIGNED DEFAULT '0' NOT NULL";
1033 $result = query($sql, "Couldn't add post_edit_count field to " . POSTS_TABLE . ".");
1034 print "<span class=\"ok\"><b>OK</b></span><br />\n<br />\n";
1035
1036 $sql = "SELECT COUNT(*) as total, MAX(post_id) as maxid
1037 FROM " . POSTS_TEXT_TABLE;
1038 $result = query($sql, "Couldn't get max post_id.");
1039
1040 $maxid = $db->sql_fetchrow($result);
1041
1042 $totalposts = $maxid['total'];
1043 $maxid = $maxid['maxid'];
1044
1045 $batchsize = 2000;
1046 for($i = 0; $i <= $maxid; $i += $batchsize)
1047 {
1048 $batchstart = $i + 1;
1049 $batchend = $i + $batchsize;
1050
1051 print " * Converting BBcode ( $batchstart to $batchend ) :: ";
1052 flush();
1053
1054 $sql = "SELECT *
1055 FROM " . POSTS_TEXT_TABLE . "
1056 WHERE post_id
1057 BETWEEN $batchstart
1058 AND $batchend";
1059 $result = query($sql, "Couldn't get ". POSTS_TEXT_TABLE .".post_id $batchstart to $batchend");
1060
1061 lock_tables(1, array(POSTS_TEXT_TABLE, POSTS_TABLE));
1062
1063 $per_pct = ceil( $db->sql_numrows($result) / 40 );
1064 $inc = 0;
1065
1066 while( $row = $db->sql_fetchrow($result) )
1067 {
1068 if ( $row['bbcode_uid'] != '' )
1069 {
1070 // We already converted this post to the new style BBcode, skip this post.
1071 continue;
1072 }
1073
1074 //
1075 // Nathan's bbcode2 conversion
1076 //
1077 // undo 1.2.x encoding..
1078 $row['post_text'] = bbdecode(stripslashes($row['post_text']));
1079 $row['post_text'] = undo_make_clickable($row['post_text']);
1080 $row['post_text'] = str_replace('<BR>', "\n", $row['post_text']);
1081
1082 // make a uid
1083 $uid = make_bbcode_uid();
1084
1085 // do 2.x first-pass encoding..
1086 $row['post_text'] = smiley_replace($row['post_text']);
1087 $row['post_text'] = bbencode_first_pass($row['post_text'], $uid);
1088 $row['post_text'] = addslashes($row['post_text']);
1089
1090 $edited_sql = "";
1091 if ( preg_match('/^(.*?)([\n]+<font size=\-1>\[ This message was .*?)$/s', $row['post_text'], $matches) )
1092 {
1093 $row['post_text'] = $matches[1];
1094 $edit_info = $matches[2];
1095
1096 $edit_times = count(explode(' message ', $edit_info)) - 1; // Taken from example for substr_count in annotated PHP manual
1097
1098 if ( preg_match('/^.* by: (.*?) on (....)-(..)-(..) (..):(..) \]<\/font>/s', $edit_info, $matches) )
1099 {
1100 $edited_user = $matches[1];
1101 $edited_time = gmmktime($matches[5], $matches[6], 0, $matches[3], $matches[4], $matches[2]);
1102
1103 //
1104 // This isn't strictly correct since 2.0 won't include and edit
1105 // statement if the edit wasn't by the user who posted ...
1106 //
1107 $edited_sql = ", post_edit_time = $edited_time, post_edit_count = $edit_times";
1108 }
1109 }
1110
1111 if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $row['post_text'], $matches) )
1112 {
1113 $row['post_text'] = $matches[1];
1114 $enable_sig = 1;
1115 }
1116 else
1117 {
1118 $checksig = preg_replace('/\[addsig\]$/', '', $row['post_text']);
1119 $enable_sig = ( strlen($checksig) == strlen($row['post_text']) ) ? 0 : 1;
1120 }
1121
1122 $sql = "UPDATE " . POSTS_TEXT_TABLE . "
1123 SET post_text = '$checksig', bbcode_uid = '$uid'
1124 WHERE post_id = " . $row['post_id'];
1125 query($sql, "Couldn't update " . POSTS_TEXT_TABLE . " table with new BBcode for post_id :: " . $row['post_id']);
1126
1127 $sql = "UPDATE " . POSTS_TABLE . "
1128 SET enable_sig = $enable_sig" . $edited_sql . "
1129 WHERE post_id = " . $row['post_id'];
1130 query($sql, "Couldn't update " . POSTS_TABLE . " table with signature status for post with post_id :: " . $row['post_id']);
1131
1132 $inc++;
1133 if ( $inc == $per_pct )
1134 {
1135 print '.';
1136 flush();
1137 $inc = 0;
1138 }
1139 }
1140
1141 print " <span class=\"ok\"><b>OK</b></span><br />\n";
1142
1143 lock_tables(0);
1144 }
1145
1146 print "<br />\n * Updating poster_id for deleted users :: ";
1147 flush();
1148
1149 $sql = "SELECT DISTINCT p.post_id
1150 FROM " . POSTS_TABLE . " p
1151 LEFT JOIN " . USERS_TABLE . " u ON p.poster_id = u.user_id
1152 WHERE u.user_id IS NULL";
1153 $result = query($sql, "Couldn't obtain list of deleted users");
1154
1155 $users_removed = $db->sql_numrows($result);
1156
1157 if ( $users_removed )
1158 {
1159 $post_id_ary = array();
1160 while( $row = $db->sql_fetchrow($result) )
1161 {
1162 $post_id_ary[] = $row['post_id'];
1163 }
1164
1165 $sql = "UPDATE " . POSTS_TABLE . "
1166 SET poster_id = " . ANONYMOUS . ", enable_sig = 0
1167 WHERE post_id IN (" . implode(", ", $post_id_ary) . ")";
1168 query($sql, "Couldn't update posts to remove deleted user poster_id values");
1169 }
1170
1171 print "<span class=\"ok\"><b>OK</b></span> ( Removed $users_removed non-existent user references )<br />\n";
1172
1173 end_step('convert_privmsgs');
1174
1175 case 'convert_privmsgs':
1176 $sql = "SELECT COUNT(*) as total, max(msg_id) as maxid
1177 FROM " . PRIVMSGS_TABLE;
1178 $result = query($sql, "Couldn't get max privmsgs_id.");
1179
1180 $maxid = $db->sql_fetchrow($result);
1181
1182 $totalposts = $maxid['total'];
1183 $maxid = $maxid['maxid'];
1184
1185 $sql = "ALTER TABLE " . PRIVMSGS_TABLE . "
1186 ADD privmsgs_subject VARCHAR(255),
1187 ADD privmsgs_attach_sig TINYINT(1) DEFAULT 1";
1188 query($sql, "Couldn't add privmsgs_subject field to " . PRIVMSGS_TABLE . " table");
1189
1190 $batchsize = 2000;
1191 for($i = 0; $i <= $maxid; $i += $batchsize)
1192 {
1193 $batchstart = $i + 1;
1194 $batchend = $i + $batchsize;
1195
1196 print " * Converting Private Message ( $batchstart to $batchend ) :: ";
1197 flush();
1198
1199 $sql = "SELECT *
1200 FROM " . PRIVMSGS_TABLE . "
1201 WHERE msg_id
1202 BETWEEN $batchstart
1203 AND $batchend";
1204 $result = query($sql, "Couldn't get " . POSTS_TEXT_TABLE . " post_id $batchstart to $batchend");
1205
1206 lock_tables(1, array(PRIVMSGS_TABLE, PRIVMSGS_TEXT_TABLE));
1207
1208 $per_pct = ceil( $db->sql_numrows($result) / 40 );
1209 $inc = 0;
1210
1211 while( $row = $db->sql_fetchrow($result) )
1212 {
1213 if ( $row['msg_text'] == NULL )
1214 {
1215 // We already converted this post to the new style BBcode, skip this post.
1216 continue;
1217 }
1218 //
1219 // Nathan's bbcode2 conversion
1220 //
1221 // undo 1.2.x encoding..
1222 $row['msg_text'] = bbdecode(stripslashes($row['msg_text']));
1223 $row['msg_text'] = undo_make_clickable($row['msg_text']);
1224 $row['msg_text'] = str_replace("<BR>", "\n", $row['msg_text']);
1225
1226 // make a uid
1227 $uid = make_bbcode_uid();
1228
1229 // do 2.x first-pass encoding..
1230 $row['msg_text'] = smiley_replace($row['msg_text']);
1231 $row['msg_text'] = bbencode_first_pass($row['msg_text'], $uid);
1232
1233 $checksig = preg_replace('/\[addsig\]$/', '', $row['msg_text']);
1234 $enable_sig = (strlen($checksig) == strlen($row['msg_text'])) ? 0 : 1;
1235
1236 if ( preg_match("/^(.*?)\n-----------------\n.*$/is", $checksig, $matches) )
1237 {
1238 $checksig = $matches[1];
1239 $enable_sig = 1;
1240 }
1241
1242 $row['msg_text'] = $checksig;
1243
1244 $row['msg_status'] = ($row['msg_status'] == 1) ? PRIVMSGS_READ_MAIL : PRIVMSGS_NEW_MAIL;
1245
1246 // Subject contains first 60 characters of msg, remove any BBCode tags
1247 $subject = addslashes(strip_tags(substr($row['msg_text'], 0, 60)));
1248 $subject = preg_replace("/\[.*?\:(([a-z0-9]:)?)$uid.*?\]/si", "", $subject);
1249
1250 $row['msg_text'] = addslashes($row['msg_text']);
1251
1252 $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
1253 VALUES ('" . $row['msg_id'] . "', '$uid', '" . $row['msg_text'] . "')";
1254 query($sql, "Couldn't insert PrivMsg text into " . PRIVMSGS_TEXT_TABLE . " table msg_id " . $row['msg_id']);
1255
1256 $sql = "UPDATE " . PRIVMSGS_TABLE . "
1257 SET msg_text = NULL, msg_status = " . $row['msg_status'] . ", privmsgs_subject = '$subject', privmsgs_attach_sig = $enable_sig
1258 WHERE msg_id = " . $row['msg_id'];
1259 query($sql, "Couldn't update " . PRIVMSGS_TABLE . " table for msg_id " . $row['post_id']);
1260
1261 $inc++;
1262 if ( $inc == $per_pct )
1263 {
1264 print '.';
1265 flush();
1266 $inc = 0;
1267 }
1268 }
1269
1270 print " <span class=\"ok\"><b>OK</b></span><br />\n";
1271 }
1272
1273 lock_tables(0);
1274 end_step('convert_moderators');
1275
1276 case 'convert_moderators';
1277 $sql = "SELECT *
1278 FROM forum_mods";
1279 $result = query($sql, "Couldn't get list with all forum moderators");
1280
1281 while( $row = $db->sql_fetchrow($result) )
1282 {
1283 // Check if this moderator and this forum still exist
1284 $sql = "SELECT user_id
1285 FROM " . USERS_TABLE . ", " . FORUMS_TABLE . "
1286 WHERE user_id = " . $row['user_id'] . "
1287 AND forum_id = " . $row['forum_id'];
1288 $check_data = query($sql, "Couldn't check if user " . $row['user_id'] . " and forum " . $row['forum_id'] . " exist");
1289
1290 if ( !($rowtest = $db->sql_fetchrow($check_data)) )
1291 {
1292 // Either the moderator or the forum have been deleted, this line in forum_mods was redundant, skip it.
1293 continue;
1294 }
1295
1296 $sql = "SELECT g.group_id
1297 FROM " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
1298 WHERE g.group_id = ug.group_id
1299 AND ug.user_id = " . $row['user_id'] . "
1300 AND g.group_single_user = 1";
1301 $insert_group = query($sql, "Couldn't get group number for user " . $row['user_id'] . ".");
1302
1303 $group_id = $db->sql_fetchrow($insert_group);
1304 $group_id = $group_id['group_id'];
1305
1306 print " * Adding moderator for forum " . $row['forum_id'] . " :: ";
1307 flush();
1308
1309 $sql = "INSERT INTO " . AUTH_ACCESS_TABLE . " (group_id, forum_id, auth_mod) VALUES ($group_id, ".$row['forum_id'].", 1)";
1310 query($sql, "Couldn't set moderator (user_id = " . $row['user_id'] . ") for forum " . $row['forum_id'] . ".");
1311
1312 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1313 }
1314
1315 print " * Setting correct user_level for moderators ::";
1316 flush();
1317
1318 $sql = "SELECT DISTINCT u.user_id
1319 FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . AUTH_ACCESS_TABLE . " aa
1320 WHERE aa.auth_mod = 1
1321 AND ug.group_id = aa.group_id
1322 AND u.user_id = ug.user_id
1323 AND u.user_level <> " . ADMIN;
1324 $result = query($sql, "Couldn't obtain list of moderators");
1325
1326 if ( $row = $db->sql_fetchrow($result) )
1327 {
1328 $ug_sql = '';
1329
1330 do
1331 {
1332 $ug_sql .= ( ( $ug_sql != '' ) ? ', ' : '' ) . $row['user_id'];
1333 }
1334 while ( $row = $db->sql_fetchrow($result) );
1335
1336 $sql = "UPDATE " . USERS_TABLE . "
1337 SET user_level = " . MOD . "
1338 WHERE user_id IN ($ug_sql)";
1339 query($sql, "Couldn't set moderator status for users");
1340 }
1341
1342 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1343
1344 end_step('convert_privforums');
1345
1346 case 'convert_privforums':
1347 $sql = "SELECT fa.*, f.forum_name
1348 FROM forum_access fa
1349 LEFT JOIN " . FORUMS_TABLE . " f ON fa.forum_id = f.forum_id
1350 ORDER BY fa.forum_id, fa.user_id";
1351 $forum_access = query($sql, "Couldn't get list with special forum access (forum_access)");
1352
1353 $forum_id = -1;
1354 while( $row = $db->sql_fetchrow($forum_access) )
1355 {
1356 // Iterate trough access table
1357 if ( $row['forum_id'] != $forum_id )
1358 {
1359 // This is a new forum, create new group.
1360 $forum_id = $row['forum_id'];
1361
1362 print " * Creating new group for forum $forum_id :: ";
1363 flush();
1364
1365 $sql = "INSERT INTO " . GROUPS_TABLE . " (group_type, group_name, group_description, group_moderator, group_single_user)
1366 VALUES (" . GROUP_HIDDEN . ", '" . addslashes($row['forum_name']) . " Group', 'Converted Private Forum Group', " . $row['user_id'] . ", 0)";
1367 $result = query($sql, "Couldn't create group for ".$row['forum_name']);
1368
1369 $group_id = $db->sql_nextid();
1370
1371 if ( $group_id <= 0 )
1372 {
1373 print "<font color=\"red\">Group creation failed. Aborting creation of groups...<br></font>\n";
1374 continue 2;
1375 }
1376
1377 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1378
1379 print " * Creating auth_access group for forum $forum_id :: ";
1380 flush();
1381
1382 $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)
1383 VALUES ($group_id, $forum_id, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)";
1384 $result = query($sql, "Unable to set group auth access.");
1385
1386 if ( $db->sql_affectedrows($result) <= 0 )
1387 {
1388 print "<font color=\"red\">Group creation failed. Aborting creation of groups...</font><br>\n";
1389 continue 2;
1390 }
1391
1392 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1393 }
1394
1395 // Add user to the group
1396 $user_id = $row['user_id'];
1397
1398 $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending)
1399 VALUES ($group_id, $user_id, 0)";
1400 query($sql, "Unable to add user_id $user_id to group_id $group_id <br>\n");
1401 }
1402
1403 end_step('update_schema');
1404
1405 case 'update_schema':
1406 $rename = array(
1407 $table_prefix . "users" => array(
1408 "user_interests" => "user_intrest",
1409 "user_allowsmile" => "user_desmile",
1410 "user_allowhtml" => "user_html",
1411 "user_allowbbcode" => "user_bbcode",
1412 "user_style" => "user_theme"
1413 ),
1414 $table_prefix . "privmsgs" => array(
1415 "privmsgs_id" => "msg_id",
1416 "privmsgs_from_userid" => "from_userid",
1417 "privmsgs_to_userid" => "to_userid",
1418 "privmsgs_date" => "msg_time",
1419 "privmsgs_ip" => "poster_ip",
1420 "privmsgs_type" => "msg_status"
1421 ),
1422 $table_prefix . "smilies" => array(
1423 "smilies_id" => "id"
1424 )
1425 );
1426
1427 $schema = get_schema();
1428
1429 $table_def = $schema['table_def'];
1430 $field_def = $schema['field_def'];
1431
1432 // Loop tables in schema
1433 while (list($table, $table_def) = @each($field_def))
1434 {
1435 // Loop fields in table
1436 print " * Updating table '$table' :: ";
1437 flush();
1438
1439 $sql = "SHOW FIELDS
1440 FROM $table";
1441 $result = query($sql, "Can't get definition of current $table table");
1442
1443 while( $row = $db->sql_fetchrow($result) )
1444 {
1445 $current_fields[] = $row['Field'];
1446 }
1447
1448 $alter_sql = "ALTER TABLE $table ";
1449 while (list($field, $definition) = each($table_def))
1450 {
1451 if ( $field == '' )
1452 {
1453 // Skip empty fields if any (shouldn't be needed)
1454 continue;
1455 }
1456
1457 $type = $definition['type'];
1458 $size = $definition['size'];
1459
1460 $default = isset($definition['default']) ? "DEFAULT " . $definition['default'] : '';
1461
1462 $notnull = $definition['notnull'] == 1 ? 'NOT NULL' : '';
1463
1464 $auto_increment = $definition['auto_increment'] == 1 ? 'auto_increment' : '';
1465
1466 $oldfield = isset($rename[$table][$field]) ? $rename[$table][$field] : $field;
1467
1468 if ( !inarray($field, $current_fields) && $oldfield == $field )
1469 {
1470 // If the current is not a key of $current_def and it is not a field that is
1471 // to be renamed then the field doesn't currently exist.
1472 $changes[] = " ADD $field " . $create_def[$table][$field];
1473 }
1474 else
1475 {
1476 $changes[] = " CHANGE $oldfield $field " . $create_def[$table][$field];
1477 }
1478 }
1479
1480 $alter_sql .= join(',', $changes);
1481 unset($changes);
1482 unset($current_fields);
1483
1484 $sql = "SHOW INDEX
1485 FROM $table";
1486 $result = query($sql, "Couldn't get list of indices for table $table");
1487
1488 unset($indices);
1489
1490 while( $row = $db->sql_fetchrow($result) )
1491 {
1492 $indices[] = $row['Key_name'];
1493 }
1494
1495 while ( list($key_name, $key_field) = each($key_def[$table]) )
1496 {
1497 if ( !inarray($key_name, $indices) )
1498 {
1499 $alter_sql .= ($key_name == 'PRIMARY') ? ", ADD PRIMARY KEY ($key_field)" : ", ADD INDEX $key_name ($key_field)";
1500 }
1501 }
1502 query($alter_sql, "Couldn't alter table $table");
1503
1504 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1505 flush();
1506 }
1507
1508 end_step('convert_forums');
1509
1510 case 'convert_forums':
1511 $sql = "SELECT *
1512 FROM " . FORUMS_TABLE;
1513 $result = query($sql, "Couldn't get list with all forums");
1514
1515 while( $row = $db->sql_fetchrow($result) )
1516 {
1517 print " * Converting forum '" . $row['forum_name'] . "' :: ";
1518 flush();
1519
1520 // forum_access: (only concerns posting)
1521 // 1 = Registered users only
1522 // 2 = Anonymous Posting
1523 // 3 = Moderators/Administrators only
1524 switch( $row['forum_access'] )
1525 {
1526 case 1:
1527 // Public forum, no anonymous posting
1528 $auth_view = AUTH_ALL;
1529 $auth_read = AUTH_ALL;
1530 $auth_post = AUTH_REG;
1531 $auth_reply = AUTH_REG;
1532 $auth_edit = AUTH_REG;
1533 $auth_delete = AUTH_REG;
1534 $auth_vote = AUTH_REG;
1535 $auth_pollcreate = AUTH_REG;
1536 $auth_sticky = AUTH_MOD;
1537 $auth_announce = AUTH_MOD;
1538 break;
1539 case 2:
1540 $auth_post = AUTH_ALL;
1541 $auth_reply = AUTH_ALL;
1542 $auth_edit = AUTH_REG;
1543 $auth_delete = AUTH_REG;
1544 $auth_vote = AUTH_ALL;
1545 $auth_pollcreate = AUTH_ALL;
1546 $auth_sticky = AUTH_MOD;
1547 $auth_announce = AUTH_MOD;
1548 break;
1549 default:
1550 $auth_post = AUTH_MOD;
1551 $auth_reply = AUTH_MOD;
1552 $auth_edit = AUTH_MOD;
1553 $auth_delete = AUTH_MOD;
1554 $auth_vote = AUTH_MOD;
1555 $auth_pollcreate = AUTH_MOD;
1556 $auth_sticky = AUTH_MOD;
1557 $auth_announce = AUTH_MOD;
1558 break;
1559 }
1560
1561 // Old auth structure:
1562 // forum_type: (only concerns viewing)
1563 // 0 = Public
1564 // 1 = Private
1565 switch( $row['forum_type'] )
1566 {
1567 case 0:
1568 $auth_view = AUTH_ALL;
1569 $auth_read = AUTH_ALL;
1570 break;
1571 default:
1572 //
1573 // Make it really private ...
1574 //
1575 $auth_view = AUTH_ACL;
1576 $auth_read = AUTH_ACL;
1577 $auth_post = AUTH_ACL;
1578 $auth_reply = AUTH_ACL;
1579 $auth_edit = AUTH_ACL;
1580 $auth_delete = AUTH_ACL;
1581 $auth_vote = AUTH_ACL;
1582 $auth_pollcreate = AUTH_ACL;
1583 $auth_sticky = AUTH_ACL;
1584 $auth_announce = AUTH_MOD;
1585 break;
1586 }
1587
1588 $sql = "UPDATE " . FORUMS_TABLE . " SET
1589 auth_view = $auth_view,
1590 auth_read = $auth_read,
1591 auth_post = $auth_post,
1592 auth_reply = $auth_reply,
1593 auth_edit = $auth_edit,
1594 auth_delete = $auth_delete,
1595 auth_vote = $auth_vote,
1596 auth_pollcreate = $auth_pollcreate,
1597 auth_sticky = $auth_sticky,
1598 auth_announce = $auth_announce
1599 WHERE forum_id = ". $row['forum_id'];
1600 query($sql, "Was unable to update forum permissions!");
1601
1602 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1603 }
1604
1605 end_step('insert_themes');
1606
1607 case 'insert_themes':
1608 print " * Inserting new values into themes table :: ";
1609
1610 @reset($inserts);
1611 while( list($table, $inserts_table) = each($inserts) )
1612 {
1613 if ( $table == THEMES_TABLE )
1614 {
1615 $per_pct = ceil( count($inserts_table) / 40 );
1616 $inc = 0;
1617
1618 while( list($nr, $insert) = each($inserts_table) )
1619 {
1620 query($insert, "Couldn't insert value into " . THEMES_TABLE);
1621
1622 $inc++;
1623 if ( $inc == $per_pct )
1624 {
1625 print ".";
1626 flush();
1627 $inc = 0;
1628 }
1629 }
1630 }
1631 }
1632
1633 print " <span class=\"ok\"><b>OK</b></span><br />\n";
1634 end_step('update_topics');
1635
1636 case 'update_topics':
1637 $sql = "SELECT MAX(topic_id) AS max_topic
1638 FROM " . TOPICS_TABLE;
1639 $result = query($sql, "Couldn't get max topic id");
1640
1641 $row = $db->sql_fetchrow($result);
1642
1643 $maxid = $row['max_topic'];
1644
1645 lock_tables(1, array(TOPICS_TABLE, POSTS_TABLE));
1646
1647 $batchsize = 1000;
1648 for($i = 0; $i <= $maxid; $i += $batchsize)
1649 {
1650 $batchstart = $i + 1;
1651 $batchend = $i + $batchsize;
1652
1653 print " * Setting topic first post_id ( $batchstart to $batchend ) :: ";
1654 flush();
1655
1656 $sql = "SELECT MIN(post_id) AS first_post_id, topic_id
1657 FROM " . POSTS_TABLE . "
1658 WHERE topic_id
1659 BETWEEN $batchstart
1660 AND $batchend
1661 GROUP BY topic_id
1662 ORDER BY topic_id ASC";
1663 $result = query($sql, "Couldn't get post id data");
1664
1665 $per_pct = ceil( $db->sql_numrows($result) / 40 );
1666 $inc = 0;
1667
1668 if ( $row = $db->sql_fetchrow($result) )
1669 {
1670 do
1671 {
1672 $sql = "UPDATE " . TOPICS_TABLE . "
1673 SET topic_first_post_id = " . $row['first_post_id'] . "
1674 WHERE topic_id = " . $row['topic_id'];
1675 query($sql, "Couldn't update topic first post id in topic :: $topic_id");
1676
1677 $inc++;
1678 if ( $inc == $per_pct )
1679 {
1680 print ".";
1681 flush();
1682 $inc = 0;
1683 }
1684 }
1685 while ( $row = $db->sql_fetchrow($result) );
1686 }
1687
1688 print " <span class=\"ok\"><b>OK</b></span><br />\n";
1689 }
1690
1691 lock_tables(0);
1692 end_step('final_configuration');
1693
1694 case 'final_configuration':
1695 //
1696 // Update forum last post information
1697 //
1698 $sql = "SELECT forum_id, forum_name
1699 FROM " . FORUMS_TABLE;
1700 $f_result = query($sql, "Couldn't obtain forum_ids");
1701
1702 while( $forum_row = $db->sql_fetchrow($f_result) )
1703 {
1704 print " * Updating '" . $forum_row['forum_name'] . "' post info :: ";
1705 flush();
1706
1707 $id = $forum_row['forum_id'];
1708
1709 $sql = "SELECT MIN(p.post_id) AS first_post, MAX(p.post_id) AS last_post
1710 FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
1711 WHERE p.forum_id = $id
1712 AND p.topic_id = t.topic_id";
1713 $result = query($sql, "Could not get post ID forum post information :: $id");
1714
1715 if ( $row = $db->sql_fetchrow($result) )
1716 {
1717 $first_post = ( $row['first_post'] ) ? $row['first_post'] : 0;
1718 $last_post = ($row['last_post']) ? $row['last_post'] : 0;
1719 }
1720 else
1721 {
1722 $first_post = 0;
1723 $last_post = 0;
1724 }
1725
1726 $sql = "SELECT COUNT(post_id) AS total
1727 FROM " . POSTS_TABLE . "
1728 WHERE forum_id = $id";
1729 $result = query($sql, "Could not get post count forum post information :: $id");
1730
1731 if ( $row = $db->sql_fetchrow($result) )
1732 {
1733 $total_posts = ($row['total']) ? $row['total'] : 0;
1734 }
1735 else
1736 {
1737 $total_posts = 0;
1738 }
1739
1740 $sql = "SELECT COUNT(topic_id) AS total
1741 FROM " . TOPICS_TABLE . "
1742 WHERE forum_id = $id
1743 AND topic_status <> " . TOPIC_MOVED;
1744 $result = query($sql, "Could not get topic count forum post information :: $id");
1745
1746 if ( $row = $db->sql_fetchrow($result) )
1747 {
1748 $total_topics = ($row['total']) ? $row['total'] : 0;
1749 }
1750 else
1751 {
1752 $total_topics = 0;
1753 }
1754
1755 $sql = "UPDATE " . FORUMS_TABLE . "
1756 SET forum_last_post_id = $last_post, forum_posts = $total_posts, forum_topics = $total_topics
1757 WHERE forum_id = $id";
1758 query($sql, "Could not update forum post information :: $id");
1759
1760 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1761 }
1762
1763 print "<br />\n * Update default user and finalise configuration :: ";
1764 flush();
1765
1766 //
1767 // Update the default admin user with their information.
1768 //
1769 $sql = "SELECT MIN(user_regdate) AS oldest_time
1770 FROM " . USERS_TABLE . "
1771 WHERE user_regdate > 0 AND user_id > 0";
1772 $result = query($sql, "Couldn't obtain oldest post time");
1773
1774 $row = $db->sql_fetchrow($result);
1775
1776 $sql = "INSERT INTO " . $table_prefix . "config (config_name, config_value)
1777 VALUES ('board_startdate', " . $row['oldest_time'] . ")";
1778 query($sql, "Couldn't insert board_startdate");
1779
1780 $sql = "UPDATE " . $table_prefix . "config
1781 SET config_value = '" . $server_name . "'
1782 WHERE config_name = 'server_name'
1783 OR config_name = 'cookie_domain'";
1784 query($sql, "Couldn't insert Board Server domain");
1785
1786 $sql = "UPDATE " . $table_prefix . "config
1787 SET config_value = '" . $server_port . "'
1788 WHERE config_name = 'server_port'";
1789 query($sql, "Couldn't insert Board server port");
1790
1791 $sql = "UPDATE " . $table_prefix . "config
1792 SET config_value = '" . $board_email . "'
1793 WHERE config_name = 'board_email'";
1794 query($sql, "Couldn't insert Board admin email");
1795
1796 $sql = "UPDATE " . $table_prefix . "config
1797 SET config_value = '" . $script_path . "'
1798 WHERE config_name = 'script_path'";
1799 query($sql, "Couldn't insert Board script path");
1800
1801 //
1802 // Change session table to HEAP if MySQL version matches
1803 //
1804 $sql = "SELECT VERSION() AS mysql_version";
1805 $result = query($sql, "Couldn't obtain MySQL Version");
1806
1807 $row = $db->sql_fetchrow($result);
1808
1809 $version = $row['mysql_version'];
1810
1811 if ( preg_match("/^(3\.23)|(4\.)/", $version) )
1812 {
1813 $sql = "ALTER TABLE " . $table_prefix . "sessions
1814 TYPE=HEAP MAX_ROWS=500";
1815 $db->sql_query($sql);
1816 }
1817
1818 echo "<span class=\"ok\"><b>OK</b></span><br />\n";
1819 end_step('drop_fields');
1820
1821 case 'drop_fields':
1822 $fields = array(
1823 BANLIST_TABLE => array("ban_start", "ban_end", "ban_time_type"),
1824 FORUMS_TABLE => array("forum_access", "forum_moderator", "forum_type"),
1825 PRIVMSGS_TABLE => array("msg_text"),
1826 RANKS_TABLE => array("rank_max"),
1827 SMILIES_TABLE => array("emotion"),
1828 TOPICS_TABLE => array("topic_notify")
1829 );
1830
1831 while( list($table, $field_data) = each($fields) )
1832 {
1833 for($i = 0; $i < count($field_data); $i++)
1834 {
1835 print " * Drop field '" . $field_data[$i] . "' in '$table' :: ";
1836 flush();
1837
1838 $sql = "ALTER TABLE $table
1839 DROP COLUMN " . $field_data[$i];
1840 query($sql, "Couldn't drop field :: " . $field_data[$i] . " from table :: $table");
1841
1842 print "<span class=\"ok\"><b>OK</b></span><br />\n";
1843
1844 }
1845 }
1846
1847 end_step('drop_tables');
1848
1849 case 'drop_tables':
1850 $drop_tables = array('access', 'forum_access', 'forum_mods', 'headermetafooter', 'whosonline', $table_prefix . 'old_config');
1851
1852 for($i = 0; $i <