Although I lost the blogs in the last two months, there are still move
than 500 blogs that records my life and career development. I though of
burying all these old blogs with a CD, but these are my lives and even
the missing two month (60-70 blogs) could still be recovered by
regenerating from the static pages. No big deal.
The real moving process takes some serious programming.
- On movabletype site, run mt-db2sql.cgi to populate the database with my Nov-11-2004 backup records.
- On mambo site, create new categories in blog section. These
categories will cater for the categories from movabletype. Write down
the category id for each category. - On mambo site, study the current database records. If there are
existing blogs, move the ID in mos_content table to a large section
(e.g. add 1000) and adjust the content_id field in
mos_content_frontpage and mos_content_rating tables. - On mambo site, create two folders cpImage and cpFiles.
- cpImages will be the image folder.
- cpFiles will be the uploaded non-displayable files (e.g. documents).
- On mambo site, copy uploaded pictures/files to the two new folders accordingly.
- Revise the move.pl to set the db configuration.
- Copy the Text/Textile.pm from movabletype site to where to run
move.pl script (in the same folder), as the perl module is required by
the move.pl script. - Run move.pl to transfer database records from movabletype to mambo.
- Manually input the missing 70-80 articles from movabletype to mambo
- Adjust the order (maybe a script to do it?)
Below is the source of move.pl
#!/usr/bin/perl
use strict;use DBI;use POSIX;use Date::Parse;use Text::Textile qw(textile);;
my $textile = new Text::Textile;$textile->charset("utf-8");
## Mambo DBmy $database = "portal";my $hostname = "192.168.101.2";my $user = ""; # set user heremy $pass = ""; # set password here
## path to the news images in Mambo.## Note that you should copy the image files manually from MT## to the Mambo directory. This script takes only care of the## database conversion!my $mosimgpath = "cpImages/";
## all local download URLs containing the above are replacedmy $replacepath = "/weblog/files/";
## ...with the string below:my $replacementpath = "images/stories/cpFiles/";
## numberic Mambo user ID of the creator (note:## this script does not do a user mapping from MT to Mambo!)my $creatorid = 64;
## default cateogry IDmy $defaultCatID = 77; # misc old stuff
## What the visitors will see as the author of the postingmy $creatoralias = "";
## (number of entries in destination cat.) +1my $ordering = 8;
##| 1 | Skills and Practices |##| 2 | TLL Oracle |##| 3 | TLL Cluster |##| 4 | Movable Type |##| 6 | My Life |##| 10 | BioCluster Portal Project |##| 11 | Bioinfo Biz | ## Category mapping: Here, MT category 1 is mapped to Mambo## cat. 67. MT cat 2 mapped to 68, too. MT cat 3 is mapped to Mambo## cat 68 etc.my @cats = ($defaultCatID, 73, # 1 Skills $defaultCatID, # 2 TLL oracle 74, # 3 TLL cluster $defaultCatID, # 4 moveable type $defaultCatID, 76, # 6 my life $defaultCatID, $defaultCatID, $defaultCatID, 70, # 10 portal project 78); # 11 biobiz
## movable type site DBmy $mthost = "192.168.100.10";my $mtdb = "chenpeng_logs";my $mtuser = ""; # set user heremy $mtpass = ""; # set password heremy $blog = 1;
## this is the last numeric id in the Mambo "content" database.my $firstid = 1;
## Configuration end
my $id = $firstid;my $dbh = DBI->connect ("DBI:mysql:database=$database;host=$hostname", $user, $pass, {'RaiseError' => 1});my $mth = DBI->connect ("DBI:mysql:database=$mtdb;host=$mthost", $mtuser, $mtpass, {'RaiseError' => 1});my ($title, $title_alias, $introtext, $fulltext, $state, $sectionid, $mask, $catid, $created, $created_by, $created_by_alias, $modified, $modified_by, $checked_out, $checked_out_time, $publish_up, $publish_down, $version, $parentid, $text, $imglist);
my $sbh;
my $sth = $mth->prepare ("SELECT * FROM mt_entry WHERE entry_blog_id=\"$blog\" " . "order by entry_created_on DESC");my ($alt, $align, $src, $imglist, $cath, $cat);
$sth->execute();
my $insertSTH = $dbh->prepare ("INSERT INTO mos_content VALUES (?, ?, ?, ?, ?, " . "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
while (my $ref = $sth->fetchrow_hashref()) { $title = $ref->{'entry_title'}; $title_alias = ""; $introtext = $textile->process($ref->{'entry_text'}); $fulltext = $textile->process($ref->{'entry_text_more'});
$state = 1; $sectionid = 4; #hardcoded, for the section in Mambo $mask = 0; $cath = $mth->prepare ("SELECT * FROM mt_placement WHERE " . "placement_entry_id=$ref->{'entry_id'} " . "AND placement_is_primary=1"); $cath->execute(); if ($cat = $cath->fetchrow_hashref()) { print ">>> MT category ID: " . $cat->{'placement_category_id'} . "\n"; $catid = $cats[$cat->{'placement_category_id'}]; } else { print ">>> MT category ID: use default\n"; $catid = $defaultCatID; } $created = $ref->{'entry_created_on'}; my ($date, $time) = split(" ", $created); $title = "Dev Log $date" if $title =~ /wp\s*::\s*dev\s*log/i; $created_by = $creatorid; $created_by_alias = $creatoralias; $modified = $ref->{'entry_created_on'}; $modified_by = $creatorid; $checked_out = 0; $checked_out_time = 0; $publish_up = $created; $publish_down = "0000-00-00 00:00:00"; $version = 1; $parentid = 0;
$text = $introtext . $fulltext; $imglist = "";
$imglist = ""; $_ = $text; while ( /<img(.*?)>/sg ) { $alt = $1; $align = $1; $src = $1; if (index($alt, "alt")>0) { $alt =~ s!.*alt=\"(.*?)\".*!\1!s; } else { $alt = "image"; } if (index($align, "align")>0) { $align =~ s!.*align=\"(.*?)\".*!\1!s; } else { $align = ""; } $src =~ s!.*src=\"[^\"]*/(.*?)\".*!\1!s;
if ($src) { $imglist .= "$mosimgpath$src|$align|$alt|0\n"; } else { $imglist = "!"; } } $introtext =~ s/<img.*?>/\{mosimage\}/sg; $fulltext =~ s/<img.*?>/\{mosimage\}/sg; $introtext =~ s!$replacepath!$replacementpath!sg; $fulltext =~ s!$replacepath!$replacementpath!sg;
print "*** id $ref->{'entry_id'} -> $id (catid: $catid)\n"; $insertSTH->execute( $id,$title,$title_alias,$introtext,$fulltext, $state,$sectionid,$mask, $catid,$created,$created_by, $created_by_alias,$modified, $modified_by,$checked_out, $checked_out_time,$publish_up, $publish_down,$imglist,"","",$version,$parentid,$ordering, "", "", 1, 0); # default require registered user $id++; $ordering++;
$cath->finish();
}$insertSTH->finish();$sth->finish();$dbh->disconnect();$mth->disconnect();