[edit] Nachdem sich nun scheinbar doch jemand dafür interessiert, muss ich darauf hinweisen, dass dieses Skript von mir nicht getestet wurde und offenbar
.
und hab mal was geschrieben.
Ich würde mich freuen, wenn hier jemand (relativ versiertes) das Script mal testen und ggf. debugen könnte...
Das kann ich mir zeitlich leider überhaupt nicht mehr leisten.
- Ich übernehme keinerlei Garantie oder Haftung (unbedingt Backup von allem machen)
- Am Anfang die Einstellungen anpassen.
- Nachdem das Script durchgelaufen ist, manual über das Admin-Interface alle betroffenen Foren resyncen.
- Votes werden einfach aus den Topics entfernt.
: Vor dem Ausführen bitte testen, ob auf dem Server die Funktion set_time_limit() erlaubt ist und funktioniert. Falls nicht, wird das Script vom PHP-Parser nach einer bestimmen Zeit abgebrochen. Wenn es bis dahin nicht fertig ist, gibt es nur noch Datenmüll in der DB.
: Das Board für alle sperren (es darf während dem Ausführen keinerlei Änderungen an der DB geben!), ansonst gibt es ebenfalls nur noch Datenmüll in der DB.
Code: Alles auswählen
<?php
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
//
// comment this line out to enable script
//
echo "<b>DANGEROUS SCRIPT</b><br><br>Read source to see how to enable it!";die;
$forum_ids = array();
//
// settings
//
$phpbb_root_path = './';
// this script expects both boards to use the normal phpbb-names for the tables
// It is very important to shut down your board during the transfer.
// the old database, you want to import
$from_dbhost = 'localhost';
$from_dbname = 'database';
$from_dbuser = 'xxx';
$from_dbpasswd = 'yyy';
$from_table_prefix = 'old_';
// your current board, where the topics and users should be transfered to
$to_dbhost = 'localhost';
$to_dbname = 'database';
$to_dbuser = 'xxx';
$to_dbpasswd = 'yyy';
$to_table_prefix = 'phpbb_';
// id of the style-sheet, all transfered users will get; check this twice!
$default_style = 1;
// you need one line for every forum you have in your old board
// $forum_ids[forum_id_in_old_board] = forum_id_to_where_topics_from_this_forum_should_be_copied;
$forum_ids[1] = 1;
$forum_ids[2] = 3;
$forum_ids[3] = 5;
//
// do not change below this line
//
// functions
function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '')
{
echo "<b>$msg_title</b><br><br>$msg_text<br><br>Line: $err_line<br>SQL: $sql";
}
function html_start()
{
echo '
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
</head>
<body>
';
}
function html_close()
{
echo '
</body>
';
}
//
// INIT
//
@set_time_limit(0);
define('IN_PHPBB', true);
include($phpbb_root_path . 'extension.inc');
$dbms = 'mysql';// only msql!! at the moment
include($phpbb_root_path . 'db/mysql.'.$phpEx);
// Make the database connections.
$from_db = new sql_db($from_dbhost, $from_dbuser, $from_dbpasswd, $from_dbname, false);
if(!$from_db->db_connect_id)
{
message_die(1, "Could not connect to from_database");
}
$to_db = new sql_db($to_dbhost, $to_dbuser, $to_dbpasswd, $to_dbname, false);
if(!$from_db->db_connect_id)
{
message_die(1, "Could not connect to to_database");
}
html_start();
//
// STEP 1 : COPY USER
//
$user_ids = array();
$user_sql = '';
$group_sql = '';
$user_group_sql = '';
$sql = "SELECT MAX(user_id) AS total FROM " . $to_table_prefix . 'users';
$row = $to_db->sql_fetchrow($to_db->sql_query($sql));
$insert_user_id = $row['total'];
$sql = "SELECT * FROM " . $from_table_prefix . 'users' . " WHERE user_id > 1 ORDER BY user_id ASC";
$result = $from_db->sql_query($sql);
$usercount = $from_db->sql_countrows($result);
for($i = 0; $i < $usercount; $i++)
{
$group_sql .= ( ( empty($group_sql) ) ? '' : ', ' ) . "('', 'Personal User', 1, 0)";
}
$sql = "INSERT INTO " . $to_table_prefix . 'groups' . " (group_name, group_description, group_single_user, group_moderator) VALUES $group_sql";
$to_db->sql_query($sql);
$insert_group_id = $to_db->sql_nextid() - $usercount + 1;
while( $user = $from_db->sql_fetchrow($result) )
{
$insert_user_id++;
$user_sql .= ( empty($user_sql) ) ? '' : ', ';
$user_sql .= "(" . $insert_user_id . ", '" . $user['username'] . "', '" . $user['user_regdate'] . "', '" . $user['user_password'] . "', '" . $user['user_email'] . "', '" . $user['user_icq'] . "', '" . $user['user_website'] . "', '" . $user['user_occ'] . "', '" . $user['user_from'] . "', '" . $user['user_interests'] . "', '" . $user['user_sig'] . "', '" . $user['user_sig_bbcode_uid'] . "', '" . $user['user_avatar'] . "', '" . $user['user_avatar_type'] . "', " . $user['user_viewemail'] . ", '" . $user['user_aim'] . "', '" . $user['user_yim'] . "', '" . $user['user_msnm'] . "', " . $user['user_attachsig'] . ", " . $user['user_allowsmile'] . ", " . $user['user_allowhtml'] . ", " . $user['user_allowbbcode'] . ", " . $user['user_allow_viewonline'] . ", " . $user['user_notify'] . ", " . $user['user_notify_pm'] . ", " . $user['user_popup_pm'] . ", " . $user['user_timezone'] . ", '" . $user['user_dateformat'] . "', '" . $user['user_lang'] . "', " . $default_style . ", " . $user['user_level'] . ", " . $user['user_allow_pm'] . ", 1, '', '" . $user['user_posts'] . "')";
$user_ids[$user['user_id']] = $insert_user_id;
$user_group_sql .= ( ( empty($user_group_sql) ) ? '' : ', ' ) . "($insert_user_id, $insert_group_id, 0)";
$insert_group_id++;
}
$sql = "INSERT INTO " . $to_table_prefix . 'users' . "(user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey, user_posts) VALUES $user_sql";
// Insert the users
if ( !$to_db->sql_query($sql) )
{
message_die(1, "Could not insert users");
}
// Insert the user_group entry
$sql = "INSERT INTO " . $to_table_prefix . 'user_group' . " VALUES (user_id, group_id, user_pending) $user_group_sql";
if ( !$to_db->sql_query($sql) )
{
message_die(1, "Could not insert user_groups");
}
echo "Copied users.<br>";
//
// STEP 2 : COPY TOPICS
//
$topic_sql = '';
$posts_sql = '';
$posts_text_sql = '';
$sql = "INSERT INTO " . $to_table_prefix . 'topics' . " (forum_id, topic_title, topic_poster) VALUES (11, 'board_transfer', -11)";
$to_db->sql_query($sql);
$insert_topic_id = $to_db->sql_nextid();
$sql = "DELETE FROM " . $to_table_prefix . 'topics' . " WHERE forum_id = 11 AND topic_poster = -11 AND topic_title = 'board_transfer'";
$to_db->sql_query($sql);
$sql = "INSERT INTO " . $to_table_prefix . 'posts' . " (topic_id, forum_id, poster_id, post_username) VALUES (11111, 11, -11, 'board_transfer')";
$to_db->sql_query($sql);
$insert_post_id = $to_db->sql_nextid();
$sql = "DELETE FROM " . $to_table_prefix . 'posts' . " WHERE topic_id = 11111 AND forum_id = 11 AND poster_id = -11 AND post_username = 'board_transfer'";
$to_db->sql_query($sql);
foreach($forum_ids as $from_id => $to_id)
{
$sql = "SELECT * FROM " . $from_table_prefix . 'topics' . " WHERE forum_id = $from_id ORDER BY topic_time ASC";
if ( !$result = $from_db->sql_query($sql) )
{
message_die(1, "Could not fetch topics");
}
while( $topic = $from_db->sql_fetchrow($result) )
{
$insert_topic_id++;
$moved_id = ( $topic['topic_moved_id'] == 0 ) ? 0 : $forum_ids[$topic['topic_moved_id'];
$vote_id = 0;//$topic['topic_vote'];
$first_post = $insert_post_id + 1;
$last_post = $insert_post_id + $topic['topic_replies'] + 1;
$topic_sql .= ( empty($topic_sql) ) ? '' : ', ';
$topic_sql .= "($to_id, , '" . $topic['topic_title'] . "', " . $user_ids[$topic['topic_poster']] . ", " . $topic['topic_time'] . ", " . $topic['topic_views'] . ", " . $topic['topic_replies'] . ", " . $topic['topic_status'] . ", $vote_id, " . $topic['topic_type'] . ", $first_post, $last_post, $moved_id)";
//
// STEP 2,5 : COPY POSTS
//
$sql = "SELECT p.*, pt.* FROM " . $from_table_prefix . 'posts' . " p LEFT JOIN " . $from_table_prefix . 'posts_text' . " AS pt USING post_id WHERE p.forum_id = $from_id AND p.topic_id = " . $topic['topic_id'] . " ORDER BY p.post_id ASC";
if ( !$result2 = $from_db->sql_query($sql) )
{
message_die(1, "Could not fetch posts");
}
while( $post = $from_db->sql_fetchrow($result2) )
{
$insert_post_id++;
$posts_sql .= ( empty($posts_sql) ) ? '' : ', ';
$posts_text_sql .= ( empty($posts_text_sql) ) ? '' : ', ';
$post['post_edit_time'] = ( empty($post['post_edit_time']) ) ? 'NULL' : $post['post_edit_time'];
$posts_sql .= "($insert_topic_id, $to_id, " . $user_ids[$post['poster_id']] . ", '" . $post['post_username'] . "', " . $post['post_time'] . ", '" . $post['poster_ip'] . "', " . $post['enable_bbcode'] . ", " . $post['enable_html'] . ", " . $post['enable_smilies'] . ", " . $post['enable_sig'] . ", " . $post['post_edit_time'] . ", " . $post['post_edit_count'] . ")";
$posts_text_sql .= "($insert_post_id, '" . $post['post_subject'] . "', '" . $post['bbcode_uid'] . "', '" . $post['post_text'] . "')";
}
}
}
$sql = "INSERT INTO " . $to_table_prefix . 'topics' . " (forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id) VALUES $topic_sql";
$to_db->sql_query($sql);
echo "Copied topics.<br>";
$sql = "INSERT INTO " . $to_table_prefix . 'posts' . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig, post_edit_time, post_edit_count) VALUES $posts_sql";
$to_db->sql_query($sql);
$sql = "INSERT INTO " . $to_table_prefix . 'posts_text' . " (post_id, post_subject, bbcode_uid, post_text) VALUES $posts_text_sql";
$to_db->sql_query($sql);
echo "Copied posts.<br>";
//
// STEP 3 : CLEAN UP
//
$from_db->sql_close();
$to_db->sql_close();
html_close();
?>