Textpattern To WordPress Migration And Importer Updates

After many years on the Textpattern blogging platform, I’ve migrated Place Name Here over to WordPress. Though it only took a day or two to migrate blog posts and comments dating back to 2004 and create a theme to match, it was a move that needed some massaging.

Why Change?

I had been contemplating the change for some time now. I’ve used both systems, as well as others like Movable Type, for personal and client projects and have a good feel for each system’s strengths. I was seeing that where WP was headed is more aligned with where I think I want to take this site. It isn’t that there was anything wrong with Textpattern—in fact in many ways I still prefer it’s simplicity, template system and other core features. But that project seemed to have plateaud and contributions, [updates and roadmaps are sometimes unclear](/article/284/mystateoftextpattern/ “My State of Textpattern Place Name Here”). WordPress has continued to move forward and make easier some of the features I’ve been wanting to add (pingbacks, gravatars, other blogging and infrastructure fluff). But since these weren’t pressing needs, I just kept bumping the move until recently when I had the time to look at it again.

Data Importer Hiccups & Changes

Having a relatively simple markup structure to begin with for the old site’s templates made the theme transition relatively easy. By creating a child theme of Twenty Ten and editing just 9 of the files (along with a bit of experience) got me to what you see now. Given this is only a migration of a 2+ year old markup and CSS that’s been tweaked a few times too many there is certainly cleanup that needs to be done when I get a chance, but a redesign is another challenge for another day.

What I did have to wrestle with was the data migration. The current Textpattern importer plugin seemed a bit out of date and for my needs it needed a bit of customization. The requirements I laid out for a successful migration from Textpattern 4.2.0 to WordPress 3.0.1:

  1. Post author needed to remain my user account in both systems.
  2. Old permalinks needed to work, so /article/[ID]/[textstub] needed to be configured and IDs in the old system needed to be preserved.
  3. Tags needed to be migrated from the old system to the new.
  4. Post Body and Excerpt HTML fields needed to be imported so I didn’t have to configure Textile parsing for all old articles.

Items 1 and 2 required a little massaging before import.

  1. Create the WordPress admin user with the same username as the author in Textpattern.
  2. Delete all test posts, comments and pages from the MySQL database to free up any IDs.

Customization of the textpattern-importer plugin was required to make the rest happen. It wasn’t really a heavy job, but three changes needed to be made.

Swap the use of the Body and Excerpt containing Textile code with the “compiled” Body_html and Excerpt_html fields.

// Get Posts
return $txpdb->get_results('SELECT
  ID,
  Posted,
  AuthorID,
  LastMod,
  Title,
  <em>Body_html,</em>
  <em>Excerpt_html,</em>
  Category1,
  Category2,
  Status,
  Keywords,
  url_title,
  comments_count
  FROM '.$prefix.'textpattern
  ', ARRAY_A);

Include the Keywords field (was this just overlooked? I don’t understand why it wasn’t there already). Also, insert the existing ID for each inserted post (as import_id).

$ret_id = wp_insert_post(array(
  <em>'import_id'      => $OldID,</em>
  'post_date'      => $Posted,
  'post_date_gmt'    => $post_date_gmt,
  'post_author'    => $authorid,
  'post_modified'    => $LastMod,
  'post_modified_gmt' => $post_modified_gmt,
  'post_title'    => $Title,
  'post_content'    => $Body,
  'post_excerpt'    => $Excerpt,
  'post_status'    => $post_status,
  'post_name'      => $url_title,
  <em>'tags_input'    => $Keywords,</em>
  'comment_count'    => $comments_count)
  );

What To Do With The Code Now?

I feel the need to share, but is it worth submitting back to the project?

I’ve uploaded both my customized importer plugin and a diff incase anyone else should want to attempt to use it. Please read my requirements above before you do, but it will probably be a smoother transition than the current plugin. I’d love to discuss contributing the changes back into the project with someone, but wouldn’t lobby for it without some discussion of which of my requirements are universal enough to make it (keywords, yes, HTML posts, dunno). Please use the comments section to let me know your thoughts on contributing this code back to WordPress—or report back if you’ve used the code.

Download pnh-textpattern-importer.zip which contains:

  • textpattern-importer.php: (replace contents of /wp-content/plugins/textpattern-importer/textpattern-importer.php with this file after installing existing plugin)
  • textpattern-importer.php.diff

Comments Temporarily(?) Removed