The Good Life... a weblog about life, technology, and the Opera Web browser

Migrating from Movable Type to Drupal

When moving between content management systems, one of the first things you have to think about is whether you can import your data from one system to the next. Importing from Blogger to MovableType was easy. They had straightforward, easy to find and follow instructions. They even document their import file format.

Drupal—what I'm planning on using here soon—is another story. They have documents scattered all over the web. And it's mostly technical jargon that's over my head. So, I'm going to detail the process I used, hopefully in a way that'll help someone in the future.

All the conversion scripts I found required Perl 5.8.2+, which none of the machines I have access to have installed (they all have 5.6.1). The conversion scripts also require the XML::SAX module, so I had to install and configure that. This, of course, is easier said than done.

Installing Perl for Windows

The version of Perl available for Windows is called ActivePerl. ActivePerl comes in two installation packages, an MSI installer and a ZIP file with a batch file installer. They recommend the MSI installer, but that might require the installation of an update version of the Windows Installer (which is linked to from the ActivePerl download page). Detailed installation notes are also available.

Installing XML::SAX

In order to run the script, you need to have the XML::SAX module installed. Using ppm to install it didn't seem to work (according to the error message and documentation I found about the error message), so I used cpan instead. To use cpan, you have to install nmake, then install cpan. Then, finally, install XML::SAX.

(Optional) Install XML::SAX::Expat

The Perl-XML documentation recommends installing a faster XML parser, so I installed XML::SAX::Expat. While in cpan, this should be a simple matter of typing install XML::SAX::Expat.

Export your Movable Type entries

At this point, I started following the Drupal documentation, though not exactly. The first step is to add a new Movable Type template (call it drupal.xml), which you'll then use as input for the convertor script. The Drupal documentation has a sample template. After trying this the first time, I noticed that my entries appeared in Drupal's blog management page backwards (they appeared correctly on my public blog page). I decided that was enough of a pain to do the import again. So, if you want your newest posts at the top, change <MTEntries lastn="1000" sort_order="ascend"> to <MTEntries lastn="1000" sort_order="descend">. This file should then be available for download from your web site.

Making the conversion script

Step 2 according to the Drupal documentation is to create and run the conversion script. This was one of the major stumbling blocks for me due to an error in the Drupal docs. So, save the conversion script to a file named convert.pl. The fourth line from the bottom should be my $filename = $ARGV[0];, otherwise you'll run into a parse error. This change and another change (setting the value for the changed column in the table) should be visible in the Drupal documentation soon.

Running the conversion script

The moment of truth. Now it's time to run the conversion script. Put convert.pl and drupal.xml in the same directory. Assuming Perl is in your path (type path in DOS to check the value of your path variable), navigate (in a DOS window) to the directory where convert.pl and drupal.xml reside and type perl convert.pl drupal.xml > nodes.mysql. Assuming this runs correctly, you'll now have a file full of SQL insert statements which you can then import into Drupal.

Importing into Drupal

After the conversion script runs successfully, upload nodes.mysql to your drupal directory. Now, from a shell session, navigate to your drupal directory and type mysql -h hostname -u username -p database name < nodes.mysql (where you've replaced the emphasized text with the appropriate values). Now all your entries should be imported into Drupal. Almost done!

Fixing Drupal's incrementer

Drupal has an auto-incrementer that normally counts which entry ID to use next. But when using raw SQL insert statements, this doesn't work. So, now we have to update the incrementer manually. If you're using phpMyAdmin, this is as simple as opening the database, checking the number of rows in the nodes table, then updating node_nid in the sequences table to the number of rows in the nodes table plus 1. If you don't have phpMyAdmin, you'll have to run three SQL queries:

  1. select max(nid) from node;
  2. select * from sequences;
  3. update sequences set node_nid = result from first query plus 1;

That's it! Now, you have all your entries imported. Unfortunately, you've left behind your comments and categories. I'm still working on those. I'll let you know what I figure out.