lastzero's software engineering blog

Observing absurdities helps lead to a state of Zen

April 30, 2008

Switched from Drupal 5 to WordPress 2.5

Filed under: Databases & XML, WordPress — Tags: — 13:37

After having trouble with the Drupal upgrade I decided to give WordPress a try. The funny thing is to copy the existing posts to the new tables. If you got the same problem, you can use this view:

CREATE VIEW wp_import AS SELECT a.nid AS ID, 1 AS post_author, FROM_UNIXTIME(a.created) AS post_date, FROM_UNIXTIME(a.created) AS post_date_gmt, b.body AS post_content, b.title AS post_title, 0 AS post_category, b.teaser AS post_except, ‘publish’ AS post_status, ‘open’ AS comment_status, ‘open’ AS ping_status, ” AS post_password, ‘post’ + a.nid AS post_name, ” AS to_ping, ” AS pinged, FROM_UNIXTIME(a.changed) AS post_modified, FROM_UNIXTIME(a.changed) AS post_modified_gmt, ” AS post_content_filtered, 0 AS post_parent, a.nid AS guid, 0 AS menu_order, ‘post’ AS post_type, ” AS post_mime_type, 0 AS comment_count FROM node a JOIN node_revisions b ON a.nid = b.nid WHERE a.type = ‘blog’ AND a.nid > 1 AND a.status = 1;

Then you can easily import all your stuff (without the images, sorry):

INSERT wordpress.wp_posts SELECT * FROM wp_import;

Wanna convert your custom markup to HTML? No problem, just run this query (works for cached content only, so you might want to click on each of your older posts once as a quick fix):

UPDATE wordpress.wp_posts w, (SELECT a.nid, b.data AS filtered FROM node_revisions a, cache_filter b WHERE CONCAT_WS(‘:’, a.format, MD5(a.body)) = b.cid) AS c SET post_content = c.filtered WHERE c.filtered IS NOT NULL AND w.ID = c.nid;

There might be a way to import a Drupal blog via RSS as well – let’s see if somebody answers to my posting on the WordPress support forum.

Update (6.5.2008)

I found another blog post that explains how to migrate from Drupal 5 to WordPress 2.0. The provided SQL script also converts categories and comments, which mine does not. However, it does not care about input filters, so Wikicode will not be converted to HTML. The perfect solution would be a combination of our scripts ;)

1 Comment »

  1. Hey mate. Cheers for this. I’d already seen the post over at darcynorman.net and was a bit put off by the fact it uses WP 2 and not 2.5 but I suppose I could install an old WP from the archive then do an upgrade.

    Hmmm.

    Also. I tried the RSS import. It worked quite well. You have to save your feed as an XML. The only issue is comments and categories.

    Comment by mkjones — October 23, 2008 @ 16:17

RSS feed for comments on this post. TrackBack URL

Leave a comment

In today’s environment, the most common methodology is code and fix. Applying more discipline than chaos will almost certainly help. Martin Fowler

Powered by PHP, Memcached, MySQL and WordPress