"; $answer = trim(fgets(STDIN)); if ($answer != 'yes') { die("Aborting ...\n"); } print "- connecting to the source database\n"; if (!($olddb = mysql_connect($olddb_host,$olddb_user,$olddb_pass,TRUE))) { die("Failed to connect to the source database.\n"); } if (!mysql_select_db("PATIX", $olddb)) { die("Failed to select the source database.\n"); } print "- connecting to the destination database\n"; $newdb = phorum_db_interact(DB_RETURN_CONN); #phorum_db_interact(DB_RETURN_RES, "set character set 'latin5'"); mysql_query("set character set 'latin5'", $olddb); // ---------------------------------------------------------------------- // Convert users // ---------------------------------------------------------------------- print "- deleting all existing users ...\n"; phorum_db_interact( DB_RETURN_RES, "DELETE FROM ${PHORUM["user_table"]} WHERE user_id != 1" ); $res = mysql_query(" SELECT count(*) FROM uye ", $olddb); if (!$res) die ("User count query failed!\n"); $row = mysql_fetch_row($res); $usercount = $row[0]; print "- converting $usercount users ...\n"; $res = mysql_query(" SELECT * FROM uye LEFT JOIN uye_info ON uye.id = uye_info.id ", $olddb); if (!$res) die ("User query failed!\n"); $count = 0; $unknown_mail_count = 0; while ($user = mysql_fetch_assoc($res)) { $count ++; print " > user $count of $usercount\r"; // There are users with spaces in the first position in the db. // Those are trucated by Phorum, resulting in duplicate users. // So here we replace these spaces with "X". It probably aren't // active users. $nick = preg_replace('/^\s+/', 'X', $user['nick']); if (empty($user['eposta'])) { $unknown_mail_count ++; $fake = "no_mail_{$unknown_mail_count}@example.com"; print "\n * User {$user['id']}: empty mail address, assigned $fake\n"; $user['eposta'] = $fake; } $puser = array( 'user_id' => $user['id'], 'username' => $nick, 'password' => $user['sifre'], 'email' => $user['eposta'], 'active' => $user['yetki'] < 4 ? PHORUM_USER_INACTIVE : PHORUM_USER_ACTIVE, 'date_added' => $user['regon'], 'date_last_active' => empty($user['actzaman']) ? $user['actzaman'] : $user['regon'], 'signature' => empty($user['imza']) || // ignore these signatures fully. $user['imza'] == 'sdlfjfjdfsj sdpofjsdofdsfj' ? '' : $user['imza'], 'admin' => $user['yetki'] >= 10 ? 1 : 0 ); // Create the user in the Phorum system. phorum_api_user_save($puser, PHORUM_FLAG_RAW_PASSWORD); } print "\n"; // ---------------------------------------------------------------------- // Convert categories (folders) and forums. // ---------------------------------------------------------------------- print "- deleting all existing folders and forums ...\n"; phorum_db_interact( DB_RETURN_RES, "DELETE FROM {$PHORUM["forums_table"]}" ); print "- creating folders and forums ...\n"; $res = mysql_query(" SELECT id,ad FROM forumkat WHERE ustad = '' ORDER BY sira ", $olddb); if (!$res) die ("User query failed!\n"); $folder_order = 1; while ($folder = mysql_fetch_assoc($res)) { print " > folder {$folder['id']}: {$folder['ad']}\n"; // Create the category folder. $pfolder = $PHORUM["default_forum_options"]; $pfolder['forum_id'] = $folder['id']; $pfolder['name'] = $folder['ad']; $pfolder['description'] = ''; $pfolder['folder_flag'] = 1; $pfolder['active'] = 1; $pfolder['vroot'] = 0; $pfolder['parent_id'] = 0; $pfolder['inherit_id'] = 0; $pfolder['display_order'] = $folder_order ++; phorum_db_add_forum($pfolder); // Retrieve all forums in this category folder. $res2 = mysql_query(" SELECT id,ad,tanim FROM forumkat WHERE ustad = '".addslashes($folder['ad'])."' ORDER BY sira ", $olddb); if (!$res2) die ("Forums for folder query failed!\n"); $forum_order = 1; while ($forum = mysql_fetch_assoc($res2)) { print " + forum {$forum['id']}: {$forum['ad']}\n"; $pforum = $PHORUM["default_forum_options"]; $pforum['forum_id'] = $forum['id']; $pforum['name'] = $forum['ad']; $pforum['description'] = $forum['tanim']; $pforum['folder_flag'] = 0; $pforum['active'] = 1; $pforum['vroot'] = 0; $pforum['parent_id'] = $folder['id']; $pforum['inherit_id'] = 0; $pforum['display_order'] = $forum_order ++; phorum_db_add_forum($pforum); } } print "- rebuilding forum paths info ...\n"; $forums = phorum_admin_build_path_array(); unset($forums[0]); foreach($forums as $fid => $forumpath) { $update_forum = array('forum_id'=>$fid, 'forum_path'=>$forumpath); phorum_db_update_forum($update_forum); } // ---------------------------------------------------------------------- // Convert messages. // ---------------------------------------------------------------------- print "- deleting all existing messages ...\n"; phorum_db_interact( DB_RETURN_RES, "DELETE FROM {$PHORUM["message_table"]}" ); print "- converting messages ...\n"; $res = mysql_query(" SELECT count(*) FROM forumkonu WHERE archieved = 0 ", $olddb); if (!$res) die ("Thread count query failed!\n"); $row = mysql_fetch_row($res); $threadcount = $row[0]; // TODO: LIMIT 500 only for dev time. $res = mysql_query(" SELECT id, stiki, fid, kitli, arsiv, ad, viewcount FROM forumkonu WHERE archieved = 0 LIMIT 500 ", $olddb); if (!$res) die ("Threads query failed!\n"); $count = 0; while ($thread = mysql_fetch_assoc($res)) { $count ++; print " > thread $count of $threadcount\r"; $res2 = mysql_query(" SELECT * FROM forummsg{$thread['arsiv']} WHERE konuid = {$thread['id']} ORDER BY id "); if (!$res2) die ("Messages for thread query failed!\n"); $basemsg = array( "forum_id" => $thread['fid'], "author" => "will be filled from script", "subject" => $thread['ad'], "email" => "", "ip" => "unknown", "closed" => 0, "moderator_post" => 0, "status" => PHORUM_STATUS_APPROVED, "sort" => PHORUM_SORT_DEFAULT, "msgid" => "" ); $thread_id = NULL; while ($message = mysql_fetch_assoc($res2)) { $dbmsg = $basemsg; // The first message is considered the parent message. if ($thread_id === NULL) { $thread_id = $message['id']; $dbmsg['parent_id'] = 0; // All others are straight follow-up messages. } else { $dbmsg['parent_id'] = $thread_id; } $dbmsg['thread'] = $thread_id; $dbmsg['message_id'] = $message['id']; $dbmsg['user_id'] = $message['pid']; $dbmsg['body'] = $message['mesaj']; $dbmsg['datestamp'] = $message['zaman']; phorum_db_post_message($dbmsg, TRUE); } } print "\nDone!\n\n"; ?>