Tag Archives: movabletype

Moving from Movable Type 3.2 to WordPress 2.3

Julie has decided that she wants to blog a little more frequently. One obstacle to this is that her blog is a spam magnet – or it was until I deleted the Movable Type comment CGIs as a last ditch defense. I’ve had very good results with Akismet on WordPress, so inevitably this meant an upgrade from Movable Type to WordPress. It was only a matter of time before this happened, especially now that I am on WordPress myself. Importing is pretty straight forward. It’s making sure that the permalinks don’t break is the problem. In order to do that you need to make sure that WordPress uses the same numerical id’s that Movable Type used. Which means that you have to hack Movable Type to add an ID field to the exported data, and hack WordPress to use that ID when it creates the new blog entries. Then you do a little mod_rewrite action, and the permalinks should keep on ticking. I’ll now proceed with describing the hacks.

I started with the basic WordPress docs to migrate from Movable Type to WordPress.

Go into the Movable Type 3.2 install and edit lib/MT/ImportExport.pm to add an ID field:

--- ImportExport.pm     2008-02-17 17:55:19.000000000 -0800
+++ ImportExport.pm~    2006-01-04 00:21:09.000000000 -0800
@@ -439,7 +439,6 @@
     my $tmpl = MT::Template->new;
     $tmpl->name('Export Template');
     $tmpl->text(<<'TEXT');
-ID: <$MTEntryID$>
 AUTHOR: <$MTEntryAuthor strip_linefeeds="1"$>
 TITLE: <$MTEntryTitle strip_linefeeds="1"$>
 STATUS: <$MTEntryStatus strip_linefeeds="1"$>

I used Joshua Zader’s modified mt.php and modified it some more so that it would work off of a local file since the MT 3.2 export was over 7MB.

--- /tmp/mt.php 2006-03-27 17:15:00.000000000 -0800
+++ mt.php      2008-02-17 20:51:53.000000000 -0800
@@ -1,7 +1,9 @@
-f<?
+<?
 
 // HERE I'M DEFINING A CUSTOM FUNCTION BASED ON THE ORIGINAL WP_INSERT_POST FUNCTION LOCATED IN IN FUNCTIONS-POST.PHP
 
+set_time_limit(0);
+
 function wp_insert_post_with_id($postarr = array()) {
        global $wpdb, $wp_rewrite, $allowedtags, $user_ID;
 
@@ -287,7 +289,7 @@
 
        function get_entries() {
                set_magic_quotes_runtime(0);
-               $importdata = file($this->file); // Read the file into an array
+               $importdata = file('/usr/share/wordpress/wp-content/mt-export.txt'); // Read the file into an array
                $importdata = implode('', $importdata); // squish it
                $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);                
                $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
@@ -371,7 +373,8 @@
        }
 
        function select_authors() {
-               $file = wp_import_handle_upload();
+/*             $file = wp_import_handle_upload(); */
+                $file['file'] = '/usr/share/wordpress/wp-content/mt-export.txt'; 
                if ( isset($file['error']) ) {
                        echo $file['error'];
                        return;

I hope this will save some poor person the time I wasted piecing all this together. Most of the documentation that I googled up was for earlier versions of either Movable Type or WordPress or both. Really, some right thinking, PHP handy person ought to just go in and fix the Movable Type importer and document how to use the Movable Type template in order to make this all work.

Oh, and if you’re going to run multiple WordPress blogs with different url prefixes on a Debian supplied WordPress, then you are going to need this.