boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The MT to b2 script is available!!!

 
Post new topic   Reply to topic    boardom Forum Index -> How to ?
View previous topic :: View next topic  
Author Message
Jennifer



Joined: 11 Aug 2002
Posts: 23
Location: Ronks, PA

PostPosted: Mon Jul 28, 2003 2:33 am    Post subject: The MT to b2 script is available!!! Reply with quote

Much thanks and all credit goes to Voxorb, who was kind enough to write the script.

1. Copy the following code and paste into a text editor.
2. Edit MT database information and b2 database information to reflect your own.
3. Save as whatever.php and upload to your server (any directory).
4. Run Smile

NOTE
This is best done on a fresh install of b2 - as in, a fresh database. Otherwise, remember to back up your database before running the script!

Code:

<a href="<? echo $_SERVER['PHP_SELF']; ?>?mtpart=categories">Categories</a> -
<a href="<? echo $_SERVER['PHP_SELF']; ?>?mtpart=users">Users</a> -
<a href="<? echo $_SERVER['PHP_SELF']; ?>?mtpart=posts">Posts</a> -
<a href="<? echo $_SERVER['PHP_SELF']; ?>?mtpart=comments">Comments</a>
<br /><br />
<?
if (!$_GET['mtpart']) {
  echo "Please select one of the above options to import them into b2. Nothing has been done yet!";
}
$part=strtolower($_GET['mtpart']);


$mt_host='localhost';
$mt_datab='MT DATABASE';
$mt_uname='MT DATABASE USERNAME';
$mt_pword='DATABASE PASSWORD';

$b2_host='localhost';
$b2_datab='b2 DATABASE';
$b2_uname='b2 DATABASE USERNAME';
$b2_pword='DATABASE PASSWORD';


$res=mysql_connect($mt_host,$mt_uname,$mt_pword);
mysql_select_db($mt_datab,$res);
switch ($part) {
  case "posts": $relPos=mysql_query('select * from mt_entry',$res); break;
  case "comments": $relCom=mysql_query('select * from mt_comment',$res); break;
  case "categories": $relCat=mysql_query('select * from mt_category',$res); break;
  case "users": $relAut=mysql_query('select * from mt_author',$res); break;
}
mysql_close($res);

$b2_posts=array(); $b2_posts_temp=array();
$b2_comments=array(); $b2_comments_temp=array();
$b2_categories=array(); $b2_categories_temp=array();
$b2_users=array(); $b2_users_temp=array();

/* Grab the entries. */
if ($relPos) {
  while ($line = mysql_fetch_array($relPos, MYSQL_ASSOC)) {
    $post_query[]=trim(str_replace("\n","","INSERT INTO `b2posts` (`ID`,`post_author`,`post_date`,`post_content`,`post_title`,`post_category`,`post_karma`)
VALUES ('".$line['entry_id']."','".$line['entry_author_id']."','".$line['entry_created_on']."','".str_replace("'","",str_replace("\n","<br />",$line['entry_text']." ".$line['entry_text_more']))."','".
$line['entry_title']."','1','0');"));
  }
} else { }
/* Grab the comments. */
if ($relCom) {
  while ($line = mysql_fetch_array($relCom, MYSQL_ASSOC)) {
    $comment_query[]=trim(str_replace("\n","","INSERT INTO `b2comments` (`comment_ID`,`comment_post_ID`,`comment_author`,`comment_author_email`,
`comment_author_url`,`comment_author_IP`,`comment_date`,`comment_content`,`comment_karma`)
VALUES ('".$line['comment_id']."','".$line['comment_entry_id']."','".$line['comment_author']."','".
$line['comment_email']."','".$line['comment_url']."','".$line['comment_ip']."','".
$line['comment_created_on']."','".str_replace("'","",str_replace("\n","<br />",$line['comment_text']))."','0');"));
  }
} else { }
/* Grab the categories. */
if ($relCat) {
  while ($line = mysql_fetch_array($relCat, MYSQL_ASSOC)) {
    $category_query[]=trim(str_replace("\n","","
    INSERT INTO `b2categories` (`cat_ID` , `cat_name`) VALUES ('".$line['category_id']."','".$line['category_label']."');"));
    unset($b2_categories_temp);
  }
} else { }
/* Grab the authors/users. */
if ($relAut) {
  while ($line = mysql_fetch_array($relAut, MYSQL_ASSOC)) {
    $name=explode(" ",$line['author_name'],2);
    $user_query[]=trim(str_replace("\n","","INSERT INTO `b2users` (`ID`,`user_login`,`user_pass`,`user_firstname`,`user_lastname`,`user_nickname`,`user_icq`,
`user_email`,`user_url`,`user_ip`,`user_domain`,`user_browser`,`dateYMDhour`,`user_level`,`user_aim`,`user_msn`,`user_yim`,`user_idmode`)
VALUES ('".$line['author_id']."','".$line['author_name']."','".$line['author_password']."','".$name[0]."','".$name[1]."','".$line['author_name']."','','".$line['author_email']."','".$line['author_url']."','".$line['author_ip']."','','','','1','','','','');"));
  }
} else { }

echo "<pre>";
echo "<b>Posts</b>: ".(count($post_query))." imported.\n";
echo "<b>Comments</b>: ".(count($comment_query))." imported\n";
echo "<b>Categories</b>: ".(count($category_query))." imported\n";
echo "<b>Users</b>: ".(count($user_query))." imported\n";
echo "</pre>";

$res=mysql_connect($b2_host,$b2_uname,$b2_pword);
mysql_select_db($b2_datab,$res);

switch ($part) {
  case "posts":
    $q=mysql_query("drop table `b2posts`");
    $query = "CREATE TABLE `b2posts` ( ID int(10) unsigned NOT NULL auto_increment, post_author int(4) DEFAULT '0' NOT NULL, post_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, post_content text NOT NULL, post_title text NOT NULL, post_category int(4) DEFAULT '0' NOT NULL, post_karma int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (ID), UNIQUE ID (ID) )";
    $q = mysql_query($query);
    foreach($post_query as $num => $data) { $impres=mysql_query($data,$res); }
    break;
  case "comments":
    $q=mysql_query("drop table `b2comments`");
    $query = "CREATE TABLE `b2comments` ( comment_ID int(11) unsigned NOT NULL auto_increment, comment_post_ID int(11) DEFAULT '0' NOT NULL, comment_author tinytext NOT NULL, comment_author_email varchar(100) NOT NULL, comment_author_url varchar(100) NOT NULL, comment_author_IP varchar(100) NOT NULL, comment_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, comment_content text NOT NULL, comment_karma int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (comment_ID) )";
    $q = mysql_query($query);
    foreach($comment_query as $num => $data) { $impres=mysql_query($data,$res); }
    break;
  case "categories":
    $q=mysql_query("drop table `b2categories`");
    $query="CREATE TABLE `b2categories` (cat_ID int(4) NOT NULL auto_increment, cat_name TINYTEXT not null , KEY (cat_ID))";
    $q = mysql_query($query);
    foreach($category_query as $num => $data) { $impres=mysql_query($data,$res); }
    break;
  case "users":
    $q=mysql_query("drop table `b2users`");
    $query = "CREATE TABLE `b2users` ( ID int(10) unsigned NOT NULL auto_increment, user_login varchar(20) NOT NULL, user_pass varchar(20) NOT NULL, user_firstname varchar(50) NOT NULL, user_lastname varchar(50) NOT NULL, user_nickname varchar(50) NOT NULL, user_icq int(10) unsigned DEFAULT '0' NOT NULL, user_email varchar(100) NOT NULL, user_url varchar(100) NOT NULL, user_ip varchar(15) NOT NULL, user_domain varchar(200) NOT NULL, user_browser varchar(200) NOT NULL, dateYMDhour datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, user_level int(2) unsigned DEFAULT '0' NOT NULL, user_aim varchar(50) NOT NULL, user_msn varchar(100) NOT NULL, user_yim varchar(50) NOT NULL, user_idmode varchar(20) NOT NULL, PRIMARY KEY (ID), UNIQUE ID (ID), UNIQUE (user_login) )";
    $q = mysql_query($query);
    foreach($user_query as $num => $data) { $impres=mysql_query($data,$res); }
    break;
}

mysql_close($res);

?>


Last edited by Jennifer on Wed Jul 30, 2003 4:37 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Jennifer



Joined: 11 Aug 2002
Posts: 23
Location: Ronks, PA

PostPosted: Mon Jul 28, 2003 10:14 am    Post subject: Reply with quote

I am desperate, heh, and willing to pay a few dollars (okay, a "few" is an understatement ) if someone can get this successfully working! Not to bash MT, but I hate it, and really want to move my entries (900+; 18 months worth!) to b2... and I've spent HOURS searching for a MT to b2 script with no luck. I even tried looking for a third party script, you know, so that I could use a MT to *third party* and then *third party* to b2, but no luck. Sad

BTW, how that above script works is like this:
1. Change:
$hostname="localhost";
$username = "database username";
$password = "database password";

to reflect the b2 database details.

2. Save as export.php and upload to mt directory.

3. Run. When page appears, view source, then copy the entire source.

4. Paste source into new file, delete the very first eight dashes, save as import.php (or any file name, for that matter), and upload into /import directory for mt.

5. Use the "import/export" utility in mt.

Surely there's a way to "reverse" this code!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Zorri



Joined: 19 Feb 2003
Posts: 8
Location: NY

PostPosted: Mon Jul 28, 2003 4:51 pm    Post subject: Reply with quote

I'd love forever anyone who could do it too. I might throw in a couple of dollars (by mail of course) to anyone who could do it. I did find a way to convert them to GM entries so that you could use the gm-2-b2 file to import them but it means exporting post info from MT and then hand-coding them into GM files. It would take forever. Sad
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Candle



Joined: 23 Dec 2002
Posts: 547

PostPosted: Mon Jul 28, 2003 4:59 pm    Post subject: ......... Reply with quote

You might be better asking about that here .
http://wordpress.org/
_________________
My Game Forum
Back to top
View user's profile Send private message
Jennifer



Joined: 11 Aug 2002
Posts: 23
Location: Ronks, PA

PostPosted: Mon Jul 28, 2003 9:39 pm    Post subject: Reply with quote

Ditto to what Zorri said. I considered the GM thing, but I'm not sure how well that would work with some extensive search & replace usage... and with 900 entries?
I've checked with wordpress.org - the converter isn't released yet. Sad
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Jennifer



Joined: 11 Aug 2002
Posts: 23
Location: Ronks, PA

PostPosted: Wed Jul 30, 2003 4:38 am    Post subject: Reply with quote

Bump! Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> How to ? All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group