Migration notes

***This is an in-progress draft***

Source: Movable Type 2.661
Target: WordPress 2.0.1

Why? The main reason for moving is that I’m using LAMP/PHP professionally these days. Migrating my site to WordPress and running it on LAMP was a good way to build my skills.

WordPress on the topic.

In most respects this was a simple export-then-import. The WordPress docs mention a file called import-mt.php which doesn’t exist in WordPress 2.0.1. There is a file called mt.php, though. I had to edit this file to point it to my MT export.

@@ -75,7 +75,8 @@
function get_entries() {
set_magic_quotes_runtime(0);
- $importdata = file($this->file); // Read the file into an array
+ //$importdata = file($this->file); // Read the file into an array
+ $importdata = file('/path/to/mtexport.txt');
$importdata = implode('', $importdata); // squish it
$importdata = preg_replace("/(rn|n|r)/", "n", $importdata);
$importdata = preg_replace("/n--------n/", "--MT-ENTRY--n", $importdata);

The trickiest bit was preserving the old permalinks. The old site used pretty permalinks for posts with titles, and the post ID for posts without titles (there were many of these). One option was to try to force the imported posts to use the same IDs that were used on Movable Type, and apply an automatic name mapping from the old site to the new site.

Instead, I created a lookup table for my 1,400 or so posts.


create table wp_mtpermalinks (
-- reference to wp_posts.ID
post_id mediumint(11),
-- permalink on old movable type site
permalink varchar(500)
);

I then modified Movable Type’s export code to include the permalink, so that it could be digested by WordPress and stored in lookup table at import time. Here’s the modification I made to CMS.pm.


@@ -2956,6 +2956,7 @@
$tmpl->blog_id($blog_id);
$tmpl->name('Export Template');
$tmpl->text(<<'TEXT');
+PERMALINK: <$MTEntryPermalink$>
AUTHOR: <$MTEntryAuthor$>
TITLE: <$MTEntryTitle$>
STATUS: <$MTEntryStatus$>

I then had to modify the import script, mt.php, to do the insert.


@@ -265,6 +266,8 @@
$post_date = $post_modified;
$post_date_gmt = $post_modified_gmt;
break;
+ case 'PERMALINK':
+ $permalink = $value;
default :
// echo "n$key: $value";
break;
@@ -283,6 +286,11 @@

$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
$post_id = wp_insert_post($postdata);
+ $wpdb->query(
+ "INSERT INTO wp_mtpermalinks
+ (post_id,permalink)
+ VALUES
+ ($post_id,'$permalink')");
// Add categories.
if (0 != count($post_categories)) {
wp_create_categories($post_categories, $post_id);

The last step was to write a script that did a lookup on the old permlink and issued a permanent redirect to the corresponding post on the new site.

Just another WordPress site