diff --git a/phpBB/upgrade_20.php b/phpBB/upgrade_20.php index 4964cf68b1..f0fca0c9f8 100644 --- a/phpBB/upgrade_20.php +++ b/phpBB/upgrade_20.php @@ -19,10 +19,39 @@ * ***************************************************************************/ include('extension.inc'); -include('config.' . $phpEx); +include('config.'.$phpEx); +include('includes/constants.'.$phpEx); +include('includes/db.'.$phpEx); +include('functions/bbcode.'.$phpEx); set_time_limit(20*60); // Increase maximum execution time to 20 minutes. +function common_header() +{ +?> + + + +phpBB - Database upgrade 1.2 to 2.0 Developers edition + + + + + +ERROR! count not drop column $column from table $table. Reason: " . mysql_error(). ""; +// +// Following functions adapted from phpMyAdmin +// +// Return table's CREATE definition +// Returns a string containing the CREATE statement on success +// +function get_table_def($db, $table, $crlf) { + + $schema_create = ""; + $schema_create .= "CREATE TABLE $table ($crlf"; + + $result =$db->sql_query("SHOW FIELDS FROM $table"); + if(!$result) + { + $error = $db->sql_error(); + error_die($db, GENERAL_ERROR, "Failed in get_table_def (show fields) : ".$error["message"]); + } + while ($row = $db->sql_fetchrow($result)) { + $schema_create .= " $row[Field] $row[Type]"; + + if (!empty($row["Default"])){ + $schema_create .= " DEFAULT '$row[Default]'"; + } + if ($row["Null"] != "YES"){ + $schema_create .= " NOT NULL"; + } + if ($row["Extra"] != ""){ + $schema_create .= " $row[Extra]"; + } + + $schema_create .= ",$crlf"; + } + + $schema_create = ereg_replace(",".$crlf."$", "", $schema_create); + $result = $db->sql_query("SHOW KEYS FROM $table"); + if(!$result) + { + $error = $db->sql_error(); + error_die($db, GENERAL_ERROR, "Failed in get_table_content (show keys) : ".$error["message"]); + } + + while ($row = $db->sql_fetchrow($result)){ + $kname=$row['Key_name']; + + if (($kname != "PRIMARY") && ($row['Non_unique'] == 0)){ + $kname="UNIQUE|$kname"; + } + if(!is_array($index[$kname])){ + $index[$kname] = array(); + } + $index[$kname][] = $row['Column_name']; + } + + while(list($x, $columns) = @each($index)){ + $schema_create .= ",$crlf"; + if($x == "PRIMARY"){ + $schema_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")"; + } else if (substr($x,0,6) == "UNIQUE") { + $schema_create .= " UNIQUE ".substr($x,7)." (" . implode($columns, ", ") . ")"; + } else { + $schema_create .= " KEY $x (" . implode($columns, ", ") . ")"; + } + } + + $schema_create .= "$crlf);"; + + return (stripslashes($schema_create)); +} + +// +// Get the content of table as a series of INSERT statements. +// After every row, a custom callback function $handler gets called. +// $handler must accept one parameter ($sql_insert); +// +function get_table_content($db, $table, $handler) { + + $result = $db->sql_query("SELECT * FROM $table"); + if(!$result) + { + $error = $db->sql_error(); + error_die($db, GENERAL_ERROR, "Failed in get_table_content (select * ) : ".$error["message"]); + } + $i = 0; + + while ($row = $db->sql_fetchrow($result)) { + + $schema_insert = "INSERT INTO $table VALUES("; + + for ($j=0; $j<$db->sql_numfields($result);$j++) { + if (!isset($row[$j])) { + $schema_insert .= " NULL,"; + } elseif ($row[$j] != "") { + $schema_insert .= " '".addslashes($row[$j])."',"; + } else { + $schema_insert .= " '',"; + } + } + $schema_insert = ereg_replace(",$", "", $schema_insert); + $schema_insert .= ");"; + $handler(trim($schema_insert)); + $i++; + } + + return (true); } -function change_column($db, $table, $column, $type, $null) -{ - $sql = "alter table $table change $column $column $type $null"; - if (!$r = mysql_query($sql, $db)) - echo "ERROR! count not change column $column from table $table. Reason: " . mysql_error(). ""; +function output_table_content($content){ + echo $content."\n"; + + return; } -function del_backup_table($db, $table) -{ - $sql = "drop table $table"; - if (!$r = mysql_query($sql, $db)) - echo "ERROR! could not delete table $table. Reason: " . mysql_error(). ""; +// +// Nathan's bbcode2 conversion routines +// +function bbdecode($message) { + + // Undo [code] + $code_start_html = "
Code:
";
+		$code_end_html = "

"; + $message = str_replace($code_start_html, "[code]", $message); + $message = str_replace($code_end_html, "[/code]", $message); + + // Undo [quote] + $quote_start_html = "
Quote:
"; + $quote_end_html = "

"; + $message = str_replace($quote_start_html, "[quote]", $message); + $message = str_replace($quote_end_html, "[/quote]", $message); + + // Undo [b] and [i] + $message = preg_replace("#(.*?)#s", "[b]\\1[/b]", $message); + $message = preg_replace("#(.*?)#s", "[i]\\1[/i]", $message); + + // Undo [url] (long form) + $message = preg_replace("#(.*?)#s", "[url=\\1\\2]\\3[/url]", $message); + + // Undo [url] (short form) + $message = preg_replace("#(.*?)#s", "[url]\\3[/url]", $message); + + // Undo [email] + $message = preg_replace("#(.*?)#s", "[email]\\1[/email]", $message); + + // Undo [img] + $message = preg_replace("##s", "[img]\\1[/img]", $message); + + // Undo lists (unordered/ordered) + + //
  • tags: + $message = str_replace("
  • ", "[*]", $message); + + // [list] tags: + $message = str_replace("", "[/list]", $message); + $message = str_replace("", "[/list]", $message); + + return($message); } -function add_column($db, $table, $column, $type, $null) -{ - $sql = "alter table $table add $column $type $null"; - if (!$r = mysql_query($sql, $db)) - echo "ERROR! count not add column $column from table $table. Reason: " . mysql_error(). ""; + +/** + * Nathan Codding - Feb 6, 2001 + * Reverses the effects of make_clickable(), for use in editpost. + * - Does not distinguish between "www.xxxx.yyyy" and "http://aaaa.bbbb" type URLs. + * + */ + +function undo_make_clickable($text) { + + $text = preg_replace("#.*?#i", "\\1", $text); + $text = preg_replace("#.*?#i", "\\1", $text); + + return $text; + } +// +// End function defns +// + + + ?> - - - - phpBB - Database upgrade 1.2 to 2.0 Developers edition - - - - Step 1: Backup the tables to be modified.
    "; + $tables = array("access", "banlist", "catagories", "config", "disallow", "forum_access", "forum_mods", "forums", "headermetafooter", "posts", "priv_msgs", "ranks", "themes", "topics", "users", "words"); - if(!$db = mysql_connect("$dbhost", "$dbuser", "$dbpasswd")) - die("Error, I could not connect to the database at $dbhost. Using username $dbuser.
    Please go back and try again.
    "); - - if(!@mysql_select_db("$dbname", $db)) - die("Database $dbname could not be found"); - - $tables = array("posts" => "Y", - "priv_msgs" => "Y", - "sessions" => "Y", - "topics" => "Y", - "banlist" => "Y", - "config" => "N", - "forums" => "N", - "users" => "N", - "access" => "N", - "smiles" => "N", - "words" => "N", - "forum_mods" => "N"); - - while (list($table_name, $drop_table) = each($tables)) + if(!isset($backupstart)) { - echo "Backing up the $table_name table...
    "; - $backup_name = $table_name . "_backup"; - - $table_create = "CREATE TABLE $backup_name (\n"; - - $r = mysql_query("show fields from $table_name", $db); - - if (0 != mysql_errno($db)) - { - die("Error, could not backup the table $table_name to $backup_name"); - } - else - { - while ($row = mysql_fetch_array($r)) - { - $table_create .= " $row[Field] $row[Type]"; - if (isset($row["Default"]) && (!empty($row["Default"]) || $row["Default"] == "0")) - $table_create .= " DEFAULT '$row[Default]'"; - if ($row["Null"] != "YES") - $table_create .= " NOT NULL"; - if ($row["Extra"] != "") - $table_create .= " $row[Extra]"; - $table_create .= ",\n"; - } - /* The code above leaves extra ',' at the end of the row. use ereg_replace to remove it */ - $table_create = ereg_replace(",\n$", "", $table_create); - - echo "    Extracted the table columns ...
    \n"; - - unset($index); - $r = mysql_query("SHOW KEYS FROM $table_name", $db); - while($row = mysql_fetch_array($r)) - { - $key_name = $row['Key_name']; - if (($key_name != "PRIMARY") && ($row['Non_unique'] == 0)) - $key_name = "UNIQUE|$key_name"; - if (!isset($index[$key_name])) - $index[$key_name] = array(); - $index[$key_name][] = $row['Column_name']; - } - - while(list($x, $columns) = @each($index)) - { - $table_create .= ",\n"; - if ($x == "PRIMARY") - $table_create .= " PRIMARY KEY (" . implode($columns, ", ") . ")"; - elseif (substr($x,0,6) == "UNIQUE") - $table_create .= " UNIQUE " .substr($x,7). " (" . implode($columns, ", ") . ")"; - else - $table_create .= " KEY $x (" . implode($columns, ", ") . ")"; - } - - echo "    Extracted the table indexes ...
    \n"; - - $table_create .= "\n)"; - mysql_query($table_create, $db); - echo "    Created the backup table $backup_name ...
    \n"; - - mysql_query("insert into $backup_name select * from $table_name", $db); - echo "    Copied the data from $table_name to $backup_name...
    \n"; - - if ($drop_table == 'Y') - { - mysql_query("drop table $table_name", $db); - echo "    Dropped table $table_name...
    \n"; - } - } + common_header(); + echo "

    Step 1: Backup critical tables.


    "; + echo "

    Click the Backup button to commence a download of the critical tables in your current database. You will be prompted for a download location for the backup file, please note that the download may be large (and hence take a long time) depending on how many posts/users/forums/etc. you have. When the download has completed (and not before!) click the Next button to continue.


    \n\n"; + echo "
    \n"; + echo "\n"; + echo "\n"; + echo "
    \n\n"; + echo "
    \n"; + echo " \">\n"; + echo "\n"; + echo "
    \n\n"; + common_footer(); + exit; } + header("Content-Type: text/x-delimtext; name=\"phpbb_db_backup.sql\""); + header("Content-disposition: filename=phpbb_db_backup.sql"); + header("Pragma: no-cache"); ?> -Backups completed ok.

    -

    - - +# +# phpBB upgrade script +# Dump of critical tables for $dbname; +# +# DATE : +# + + +# +# TABLE : +# Step 2: Create the tables in the new format.
    "; - if(!$db = mysql_connect("$dbhost", "$dbuser", "$dbpasswd")) - die("Error, I could not connect to the database at $dbhost. Using username $dbuser.
    Please go back and try again.
    "); + common_header(); + echo "

    Step 2: Create new tables.


    "; - if(!@mysql_select_db("$dbname", $db)) - die("Database $dbname could not be found"); + if(file_exists("./db/mysql_schema.sql")){ + $sql_query = fread(fopen("./db/mysql_schema.sql", "r"),filesize("./db/mysql_schema.sql")); + $sql_lines = explode(");\n", preg_replace("/(#.*\n)/", "", $sql_query)); - $tables = array ("posts" => "CREATE TABLE posts ( - post_id int(10) DEFAULT '0' NOT NULL auto_increment, - topic_id int(10) DEFAULT '0' NOT NULL, - forum_id int(10) DEFAULT '0' NOT NULL, - poster_id int(10) NOT NULL, - post_time int(10) NOT NULL, - poster_ip int(10) NOT NULL, - KEY(forum_id), - KEY(topic_id), - KEY(poster_id), - PRIMARY KEY (post_id))", - "post_text" => "CREATE TABLE posts_text ( - post_id int(10) NOT NULL, - post_text text, - PRIMARY KEY(post_id))", - "pmsg" => "CREATE TABLE priv_msgs ( - msg_id int(10) DEFAULT '0' NOT NULL auto_increment, - from_userid int(10) DEFAULT '0' NOT NULL, - to_userid int(10) DEFAULT '0' NOT NULL, - msg_time int(10) NOT NULL, - poster_ip int(10) NOT NULL, - msg_status int(10) DEFAULT '0' NOT NULL, - msg_text text NOT NULL, - PRIMARY KEY (msg_id), - KEY to_userid (to_userid) - )", - "sessions" => "CREATE TABLE sessions ( - sess_id int(10) unsigned DEFAULT '0' NOT NULL, - user_id int(10) DEFAULT '0' NOT NULL, - start_time int(10) unsigned DEFAULT '0' NOT NULL, - remote_ip int(10) NOT NULL, - username varchar(40), - forum int(10), - PRIMARY KEY (sess_id), - KEY start_time (start_time), - KEY remote_ip (remote_ip) - )", - "topics" => "CREATE TABLE topics ( - topic_id int(10) DEFAULT '0' NOT NULL auto_increment, - topic_title varchar(100) NOT NULL, - topic_poster int(10) NOT NULL, - topic_time int(10) NOT NULL, - topic_views int(10) DEFAULT '0' NOT NULL, - forum_id int(10) NOT NULL, - topic_status tinyint(3) DEFAULT '0' NOT NULL, - topic_notify tinyint(3) DEFAULT '0', - topic_last_post_id int(11) DEFAULT '0' NOT NULL, - KEY(forum_id), - PRIMARY KEY (topic_id))", - "banlist" => "CREATE TABLE banlist( - ban_id int(10) NOT NULL AUTO_INCREMENT DEFAULT '0', - ban_userid int(10), - ban_ip int(10), - ban_start int(10), - ban_end int(10), - ban_time_type int(10), - PRIMARY KEY(ban_id))"); + $error = false; + $uploaded = 0; - while(list($name, $table) = each($tables)) - { - echo "Creating table $name   "; - if(!$r = mysql_query($table, $db)) - die("ERROR! Could not create table. Reason: ". mysql_error().""); - echo "[OK]
    "; - flush(); - } + for($i=0;$i 2) + { + echo $sql_lines[$i].")\n\n

    \n\n"; + $sql_lines[$i] = $sql_lines[$i].")"; + $result = $db->sql_query($sql_lines[$i]); + if(!$result){ + die("Error creating new tables"); + } + } + } + } - drop_column($db, "config", "admin_passwd"); - change_column($db, "config", "allow_html", "tinyint(3)", "null"); - change_column($db, "config", "allow_bbcode", "tinyint(3)", "null"); - change_column($db, "config", "allow_sig", "tinyint(3)", "null"); - change_column($db, "config", "allow_namechange", "tinyint(3)", "null"); - change_column($db, "config", "override_themes", "tinyint(3)", "null"); - echo "Altered table config
    "; - - drop_column($db, "forums", "forum_moderator"); - change_column($db, "forums", "forum_access", "tinyint(3)", "null"); - change_column($db, "forums", "forum_type", "tinyint(3)", "null"); - add_column($db, "forums", "forum_order", "int(10)", "default '0' not null"); - add_column($db, "forums", "forum_posts", "int(10)", "default '0' not null"); - add_column($db, "forums", "forum_topics", "int(10)", "default '0' not null"); - add_column($db, "forums", "forum_last_post_id", "int(10)", "default '0' not null"); - - echo "Altered table forums
    "; - - change_column($db, "users", "user_aim", "varchar(255)", "null"); - change_column($db, "users", "user_yim", "varchar(255)", "null"); - change_column($db, "users", "user_msnm", "varchar(255)", "null"); - change_column($db, "users", "user_email", "varchar(255)", "null"); - change_column($db, "users", "user_viewemail", "tinyint(3)", "null"); - change_column($db, "users", "user_attachsig", "tinyint(3)", "null"); - change_column($db, "users", "user_desmile", "tinyint(3)", "null"); - change_column($db, "users", "user_html", "tinyint(3)", "null"); - change_column($db, "users", "user_bbcode", "tinyint(3)", "null"); - add_column($db, "users", "user_notify", "tinyint(3)", "null"); - - echo "Altered table users
    "; - - change_column($db, "access", "access_title", "varchar(30)", "not null"); - - echo "Altered table access
    "; - - change_column($db, "smiles", "code", "varchar(50)", "not null"); - change_column($db, "smiles", "smile_url", "varchar(100)", "not null"); - change_column($db, "smiles", "emotion", "varchar(75)", "not null"); - - echo "Altered table smiles
    "; - - change_column($db, "words", "word", "varchar(100)", "not null"); - change_column($db, "words", "replacement", "varchar(100)", "not null"); - - echo "Altered table words
    "; - - add_column($db, "forum_mods", "mod_notify", "tinyint(3)", "null"); - - echo "Altered table forum_mods
    "; ?> +

    Tables created

    Step 4: Convert the data to the new table format.
    "; + if(!isset($convertstart)) + { - if(!$db = mysql_connect("$dbhost", "$dbuser", "$dbpasswd")) - die("Error, I could not connect to the database at $dbhost. Using username $dbuser.
    Please go back and try again.
    "); + common_header(); + echo "

    Step 3: Move the data to the new tables..


    "; + echo "

    Now all the your old phpBB data will be moved and updated (where necessary) to the newly created phpBB2 tables. If you wish you can automatically delete your old data by checking the delete old data box below. Only do this if you backed up your data earlier! Click the Convert button to commence the operation.

    \n\n"; + echo "
    \n"; + echo "Delete Old Data     "; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
    \n\n"; + common_footer(); + exit; + } - if(!@mysql_select_db("$dbname", $db)) - die("Database $dbname could not be found"); + common_header(); - $r = mysql_query("select * from posts_backup", $db); - - echo "Converting posts and creating posts_text ...
    "; - flush(); - - while ($row = mysql_fetch_array($r)) + // + // Go through tables one by one + // could do this via arrays I guess ... + // + // banlist + // + echo "

    Moving banlist ... "; + $result = $db->sql_query("SELECT * FROM banlist"); + if(!$result) { - $post_time = convert_date($row['post_time']); - $post_ip = convert_ip($row['poster_ip']); - - $post_id = $row['post_id']; - $topic_id = $row['topic_id']; - $forum_id = $row['forum_id']; - $poster_id = $row['poster_id']; - $post_text = $row['post_text']; - $post_text = addslashes('$post_text'); - - $sql = "insert posts (post_id, topic_id, forum_id, poster_id, post_time, poster_ip) - values ($post_id, $topic_id, $forum_id, $poster_id, $post_time, $post_ip)"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting posts " . mysql_error($db) . "
    "; - - $sql = "insert posts_text (post_id, post_text) values ($post_id, '$post_text')"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting posts_text " . mysql_error($db) . "
    "; + die("Failed selecting from banlist"); } - - $r = mysql_query("select * from priv_msgs_backup", $db); - echo mysql_error($db); - - echo "Converting priv_msgs ..
    "; - flush(); - - while ($row = mysql_fetch_array($r)) + if($db->sql_numrows($result)) { - $msg_time = convert_date($row['msg_time']); - $poster_ip = convert_ip('0.0.0.0'); - - $msg_id = $row['msg_id']; - $from_userid = $row['from_userid']; - $to_userid = $row['to_userid']; - $msg_status = $row['msg_status']; - $msg_text = $row['msg_text']; - - $sql = "insert priv_msgs (msg_id, from_userid, to_userid, msg_time, poster_ip, msg_status, msg_text) - values ($msg_id, $from_userid, $to_userid, $msg_time, $poster_ip, $msg_status, '$msg_text')"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting priv_msgs " . mysql_error($db) . "
    "; - + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_banlist + (ban_id, ban_userid, ban_ip, ban_start, ban_end, ban_time_type) + VALUES + ('".$row["ban_id"]."', '".$row["ban_userid"]."', '".convert_ip($row["ban_ip"])."', '".$row["ban_start"]."', '".$row["ban_end"]."', '".$row["ban_time_type"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_banlist"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM banlist WHERE ban_id = '".$row["ban_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from banlist"); + } + } + } } + echo "DONE

    \n"; - $r = mysql_query("select * from sessions_backup", $db); - - echo "Converting sessions ..
    "; - flush(); - - while ($row = mysql_fetch_array($r)) + // + // catagories + // + echo "

    Moving catagories ... "; + $result = $db->sql_query("SELECT * FROM catagories"); + if(!$result) { - $start_time = convert_date($row['start_time']); - $remote_ip = convert_ip($row['remote_ip']); - - $sess_id = $row['sess_id']; - $user_id = $row['user_id']; - - $sql = "insert sessions (sess_id, user_id, start_time, remote_ip) - values ($sess_id, $user_id, $start_time, $remote_ip)"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting sessions " . mysql_error($db) . "
    "; - + die("Failed selecting from catagories"); } - - $r = mysql_query("select * from topics_backup", $db); - - echo "Converting topics ..
    "; - flush(); - - while ($row = mysql_fetch_array($r)) + if($db->sql_numrows($result)) { - $topic_time = convert_date($row['topic_time']); - - $topic_id = $row['topic_id']; - $topic_title = $row['topic_title']; - $topic_poster = $row['topic_poster']; - $topic_views = $row['topic_views']; - $forum_id = $row['forum_id']; - $topic_status = $row['topic_status']; - $topic_notify = $row['topic_notify']; - $forum_id = $row['forum_id']; - - $sql = "insert topics (topic_id, topic_title, topic_poster, topic_time, topic_views, forum_id, topic_status, topic_notify) - values ($topic_id, '$topic_title', $topic_poster, $topic_time, $topic_views, $forum_id, $topic_status, $topic_notify)"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting topics " . mysql_error($db) . "
    "; - + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_categories + (cat_id, cat_title, cat_order) + VALUES + ('".$row["cat_id"]."', '".$row["cat_title"]."', '".$row["cat_order"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_categories"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM catagories WHERE cat_id = '".$row["cat_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from catagories"); + } + } + } } + echo "DONE

    \n"; - $r = mysql_query("select * from banlist_backup", $db); - - echo "Converting banlist ..
    "; - flush(); - - while ($row = mysql_fetch_array($r)) + // + // config + // + echo "

    Moving config ... "; + $result = $db->sql_query("SELECT * FROM config"); + if(!$result) { - $ban_start = convert_date($row['ban_start']); - $ban_end = convert_date($row['ban_end']); - $ban_ip = convert_ip($row['ban_ip']); - - $ban_id = $row['ban_id']; - $ban_userid = $row['ban_userid']; - $ban_time_type = $row['ban_time_type']; - - $sql = "insert banlist (ban_id, ban_userid, ban_ip, ban_start, ban_end, ban_time_type) - values ($ban_id, $ban_userid, $ban_ip, $ban_start, $ban_end, $ban_time_type)"; - mysql_query($sql, $db); - if (mysql_errno($db) != 0) - echo "The following error occured converting banlist " . mysql_error($db) . "
    "; - + die("Failed selecting from config"); } - - echo "Delete the backup tables ..
    "; - flush(); - - $tables = array("posts" , - "priv_msgs", - "sessions" , - "topics" , - "banlist" , - "config" , - "forums" , - "users" , - "access" , - "smiles" , - "words" , - "forum_mods"); - while (list(, $drop_table) = each($tables)) + if($db->sql_numrows($result)) { - $backup_name = $drop_table . '_backup'; - del_backup_table($db, $backup_name); - } + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_config + (config_id, sitename, allow_html, allow_bbcode, allow_sig, allow_namechange, selected, posts_per_page, hot_threshold, topics_per_page, allow_theme_create, override_themes, email_sig, email_from, default_lang) + VALUES + ('".$row["config_id"]."', '".$row["sitename"]."', '".$row["allow_html"]."', '".$row["allow_bbcode"]."', '".$row["allow_sig"]."', '".$row["allow_namechange"]."', '".$row["selected"]."', '".$row["posts_per_page"]."', '".$row["hot_threshold"]."', '".$row["topics_per_page"]."', '".$row["allow_theme_create"]."', '".$row["override_themes"]."', '".$row["email_sig"]."', '".$row["email_from"]."', '".$row["default_lang"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_config"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM config WHERE config_id = '".$row["config_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from config"); + } + } + } + } + echo "DONE

    \n"; + + // + // disallow + // + echo "

    Moving disallow ... "; + $result = $db->sql_query("SELECT * FROM disallow"); + if(!$result) + { + die("Failed selecting from disallow"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_disallow + (disallow_id, disallow_username) + VALUES + ('".$row["disallow_id"]."', '".$row["disallow_username"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_disallow"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM disallow WHERE disallow_id = '".$row["disallow_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from disallow"); + } + } + } + } + echo "DONE

    \n"; + + // + // forum_access + // + echo "

    Moving forum_access ... "; + $result = $db->sql_query("SELECT * FROM forum_access"); + if(!$result) + { + die("Failed selecting from forum_access"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_forum_access + (forum_id, user_id, can_post) + VALUES + ('".$row["forum_id"]."', '".$row["user_id"]."', '".$row["can_post"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_forum_access"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM forum_access WHERE forum_id = '".$row["forum_id"]."' AND user_id = '".$row["user_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from forum_access"); + } + } + } + } + echo "DONE

    \n"; + + // + // forum_mods + // + echo "

    Moving forum_mods ... "; + $result = $db->sql_query("SELECT * FROM forum_mods"); + if(!$result) + { + die("Failed selecting from forum_mods"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_forum_mods + (forum_id, user_id) + VALUES + ('".$row["forum_id"]."', '".$row["user_id"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_forum_mods"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM forum_mods WHERE forum_id = '".$row["forum_id"]."' AND user_id = '".$row["user_id"]."'"; + if(!$delete_result) + { + die("Failed deleting data from forum_mods"); + } + } + } + } + echo "DONE

    \n"; + + // + // forums + // + echo "

    Moving forums ... "; + $result = $db->sql_query("SELECT * FROM forums"); + if(!$result) + { + die("Failed selecting from forums"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "SELECT COUNT(*) AS forum_topics FROM topics WHERE forum_id = '".$row["forum_id"]."'"; + $numtopics_result = $db->sql_query($sql); + if(!$numtopics_result) + { + die("Failed obtaining number of topics for this forum!"); + } + $row["forum_topics"] = $db->sql_fetchfield("forum_topics",-1, $numtopics_result); + + $sql = "SELECT COUNT(*) AS forum_posts, MAX(post_id) AS forum_last_post_id FROM posts WHERE forum_id = '".$row["forum_id"]."'"; + $numposts_result = $db->sql_query($sql); + if(!$numposts_result) + { + die("Failed obtaining number of posts/last_post_id for this forum!"); + } + $row["forum_posts"] = $db->sql_fetchfield("forum_posts",-1, $numposts_result); + $row["forum_last_post_id"] = $db->sql_fetchfield("forum_last_post_id",-1, $numposts_result); + $sql = "INSERT INTO phpbb_forums + (forum_id, forum_name, forum_desc, forum_access, cat_id, forum_order, forum_type, forum_posts, forum_topics, forum_last_post_id) + VALUES + ('".$row["forum_id"]."', '".addslashes($row["forum_name"])."', '".addslashes($row["forum_desc"])."', '".$row["forum_access"]."', '".$row["cat_id"]."', '".$row["forum_order"]."', '".$row["forum_type"]."', '".$row["forum_posts"]."', '".$row["forum_topics"]."', '".$row["forum_last_post_id"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_forums"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM forums WHERE forum_id = '".$row["forum_id"]."' AND cat_id = '".$row["cat_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from forum_mods"); + } + } + } + } + echo "DONE

    \n"; + + // + // headermetafooter + // + echo "

    Moving headermetafooter ... "; + $result = $db->sql_query("SELECT * FROM headermetafooter"); + if(!$result) + { + die("Failed selecting from headermetafooter"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_headermetafooter + (header, meta, footer) + VALUES + ('".$row["header"]."', '".$row["meta"]."', '".$row["footer"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_headermetafooter"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM headermetafooter WHERE header = '".$row["header"]."' AND meta = '".$row["meta"]."' AND footer = '".$row["footer"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from headermetafooter"); + } + } + } + } + echo "DONE

    \n"; + + // + // priv_msgs + // + echo "

    Moving priv_msgs ... "; + $result = $db->sql_query("SELECT * FROM priv_msgs"); + if(!$result) + { + die("Failed selecting from priv_msgs"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_priv_msgs + (msg_id, from_userid, to_userid, msg_time, poster_ip, msg_status, msg_text) + VALUES + ('".$row["msg_id"]."', '".$row["from_userid"]."', '".$row["to_userid"]."', '".convert_date($row["msg_time"])."', '".convert_ip($row["poster_ip"])."', '".$row["msg_status"]."', '".addslashes($row["msg_text"])."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_priv_msgs"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM priv_msgs WHERE msg_id = '".$row["msg_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from priv_msgs"); + } + } + } + } + echo "DONE

    \n"; + + // + // ranks + // + echo "

    Moving ranks ... "; + $result = $db->sql_query("SELECT * FROM ranks"); + if(!$result) + { + die("Failed selecting from ranks"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_ranks + (rank_id, rank_title, rank_min, rank_max, rank_special, rank_image) + VALUES + ('".$row["rank_id"]."', '".addslashes($row["rank_title"])."', '".$row["rank_min"]."', '".$row["rank_max"]."', '".$row["rank_special"]."', '".$row["rank_image"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_ranks"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM ranks WHERE rank_id = '".$row["rank_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from ranks"); + } + } + } + } + echo "DONE

    \n"; + + // + // themes + // + echo "

    Moving ranks ... "; + $result = $db->sql_query("SELECT * FROM themes"); + if(!$result) + { + die("Failed selecting from themes"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_themes + (theme_id, theme_name, bgcolor, textcolor, color1, color2, table_bgcolor, header_image, newtopic_image, reply_image, linkcolor, vlinkcolor, theme_default, fontface, fontsize1, fontsize2, fontsize3, fontsize4, tablewidth, replylocked_image) + VALUES + ('".$row["theme_id"]."', '".addslashes($row["theme_name"])."', '".$row["bgcolor"]."', '".$row["textcolor"]."', '".$row["color1"]."', '".$row["color2"]."', '".$row["table_bgcolor"]."', '".$row["header_image"]."', '".$row["newtopic_image"]."', '".$row["reply_image"]."', '".$row["linkcolor"]."', '".$row["vlinkcolor"]."', '".$row["theme_default"]."', '".$row["fontface"]."', '".$row["fontsize1"]."', '".$row["fontsize2"]."', '".$row["fontsize3"]."', '".$row["fontsize4"]."', '".$row["tablewidth"]."', '".$row["replylocked_image"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_themes"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM themes WHERE theme_id = '".$row["theme_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from themes"); + } + } + } + } + echo "DONE

    \n"; + + // + // topics + // + echo "

    Moving topics ... "; + $result = $db->sql_query("SELECT * FROM topics ORDER BY topic_time DESC"); + if(!$result) + { + die("Failed selecting from topics"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "SELECT COUNT(*) AS topic_replies, MAX(post_id) AS topic_last_post_id FROM posts WHERE topic_id = '".$row["topic_id"]."'"; + $numtopics_result = $db->sql_query($sql); + if(!$numposts_result) + { + die("Failed obtaining number of replies/last_post_id for this topic!"); + } + $row["topic_replies"] = $db->sql_fetchfield("topic_replies",-1, $numtopics_result) - 1; + $row["topic_last_post_id"] = $db->sql_fetchfield("topic_last_post_id",-1, $numtopics_result); + $sql = "INSERT INTO phpbb_topics + (topic_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, forum_id, topic_status, topic_notify, topic_last_post_id) + VALUES + ('".$row["topic_id"]."', '".addslashes($row["topic_title"])."', '".$row["topic_poster"]."', '".convert_date($row["topic_time"])."', '".$row["topic_views"]."', '".$row["topic_replies"]."', '".$row["forum_id"]."', '".$row["topic_status"]."', '".$row["topic_notify"]."', '".$row["topic_last_post_id"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_topics"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM topics WHERE topic_id = '".$row["topic_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from topics"); + } + } + } + } + echo "DONE

    \n"; + + // + // posts/post_text + // + echo "

    Moving posts & post_text ... "; + $result = $db->sql_query("SELECT * FROM posts ORDER BY post_id"); + if(!$result) + { + die("Failed selecting from posts"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + // + // Nathan's bbcode2 conversion + // + // undo 1.2.x encoding.. + $row['post_text'] = bbdecode($row['post_text']); + $row['post_text'] = undo_make_clickable($row['post_text']); + $row['post_text'] = str_replace("
    ", "\n", $row['post_text']); + // make a uid + $uid = make_bbcode_uid(); + // do 2.x first-pass encoding.. + $row['post_text'] = bbencode_first_pass($row['post_text'], $uid); + $row['post_text'] = addslashes($row['post_text']); + + $sql = "INSERT INTO phpbb_posts + (post_id, topic_id, forum_id, poster_id, post_time, poster_ip, bbcode_uid) + VALUES + ('".$row["post_id"]."', '".$row["topic_id"]."', '".$row["forum_id"]."', '".$row["poster_id"]."', '".convert_date($row["post_time"])."', '".convert_ip($row["poster_ip"])."', '".$uid."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_posts"); + } + $sql = "INSERT INTO phpbb_posts_text + (post_id, post_text) + VALUES + ('".$row["post_id"]."', '".addslashes($row["post_text"])."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_posts_text"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM posts WHERE post_id = '".$row["post_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from posts"); + } + } + } + } + echo "DONE

    \n"; + + // + // users + // + echo "

    Moving users ... "; + $result = $db->sql_query("SELECT * FROM users"); + if(!$result) + { + die("Failed selecting from users"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_users + (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_intrest, user_sig, user_viewemail, user_theme, user_aim, user_yim, user_msnm, user_posts, user_attachsig, user_desmile, user_html, user_bbcode, user_rank, user_avatar, user_level, user_lang, user_actkey, user_newpasswd, user_notify) + VALUES + ('".$row["user_id"]."', '".($row["username"])."', '".$row["user_regdate"]."', '".$row["user_password"]."', '".$row["user_email"]."', '".$row["user_icq"]."', '".$row["user_website"]."', '".$row["user_occ"]."', '".addslashes($row["user_from"])."', '".addslashes($row["user_intrest"])."', '".addslashes($row["user_sig"])."', '".$row["user_viewemail"]."', '".$row["user_theme"]."', '".$row["user_aim"]."', '".$row["user_yim"]."', '".$row["user_msnm"]."', '".$row["user_posts"]."', '".$row["user_attachsig"]."', '".$row["user_desmile"]."', '".$row["user_html"]."', '".$row["user_bbcode"]."', '".$row["user_rank"]."', '".$row["user_avatar"]."', '".$row["user_level"]."', '".$row["user_lang"]."', '".$row["user_actkey"]."', '".$row["user_newpasswd"]."', '".$row["user_notify"]."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_users"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM users WHERE user_id = '".$row["user_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from users"); + } + } + } + } + echo "DONE

    \n"; + + // + // words + // + echo "

    Moving words ... "; + $result = $db->sql_query("SELECT * FROM words"); + if(!$result) + { + die("Failed selecting from words"); + } + if($db->sql_numrows($result)) + { + while($row = $db->sql_fetchrow($result)) + { + $sql = "INSERT INTO phpbb_words + (word_id, word, replacement) + VALUES + ('".$row["word_id"]."', '".addslashes($row["word"])."', '".addslashes($row["replacement"])."')"; + $insert_result = $db->sql_query($sql); + if(!$insert_result) + { + die("Failed inserting data into phpbb_words"); + } + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $sql = "DELETE FROM words WHERE word_id = '".$row["word_id"]."'"; + $delete_result = $db->sql_query($sql); + if(!$delete_result) + { + die("Failed deleting data from words"); + } + echo "
    \n"; + } + } + } + echo "DONE
    \n"; + + + if(isset($HTTP_POST_VARS["deleteolddata"])) + { + $old_tables = array("access", "banlist", "catagories", "config", "disallow", "forum_access", "forum_mods", "forums", "headermetafooter", "posts", "priv_msgs", "ranks", "sessions", "smiles", "themes", "topics", "users", "whosonline", "words"); + + echo "

    Removing phpBB 1.x tables ... "; + + for($i=0;$isql_query("DROP TABLE ".$old_tables[$i]); + if(!$result) + { + die("Couldn't drop table : ".$old_tables[$i]); + } + } + + echo "DONE

    "; + } ?> -All Done. +

    All operations completed!

    +

    You should now clear your browsers cookie cache and try accessing your new phpBB2 install.

    -
    - Welcome! This script will upgrade your phpBB v1.2 database to version 2.0.
    - The upgrade will perform the following functions: -
      -
    • Back up all modified database tables. -
    • Create the new tables -
    • Convert the data -
    - - -
    +

    Welcome! This script will upgrade your phpBB v1.2 database to version 2.0. Please note that it assumes a clean database structure is present. If you've introduced any hacks which change the field names or types, or have added additional fields or tables then this script may well fail.

    + +

    The upgrade will perform the following functions: + +

      +
    • Back up all critical tables to a downloadable file. +
    • Create the new tables. +
    • Move the data to the new setup. +
    + +
    + + +