in X-Geek

bplog to WordPress SQL Script

Okay, calling it a script is a bit of a stretch. Just one SQL statement, really. 🙂

Bplog is a bare-bones blog app. There are only three tables in its database, so migrating it was relatively simple.

I used the following INSERT statement to move values from one to the other. The nested REPLACE statements are ugly, yes. If I was more enterprising, I’d trade them for multiple UPDATE … REPLACE statements at the bottom of a SQL script. I just went with what I could get working the quickest.

INSERT INTO mtdotnet.mt_posts (id, post_date, post_content, post_title, post_excerpt, post_name, post_modified, post_author) SELECT DISTINCT n.id + 2326, n.date, REPLACE(REPLACE(n.entry,’\\\”,’\”),’\\\”‘,’\”‘), REPLACE(REPLACE(n.subject,’\\\”,’\”),’\\\”‘,’\”‘), SUBSTRING(n.entry,0,255), REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(n.subject), ‘ ‘,’_’), ‘.’, ”), ‘,’, ”), ‘+’, ”), ‘!’,”), ‘\\’,”), ‘\”,”), ‘?’,”), ‘:’,”), n.date, ’32’ FROM bpMigrate.news n, mtdotnet.mt_posts r WHERE n.id = r.id;

The replace statements replace characters WordPress considers illegal in the post slugs. Also, bplog escapes quote ( ” ‘ ) characters with preceding slashes in the post body, so I yank those out before inserting the post. You’ll also note that I set the post_author to my WordPress Id so that my imported posts are attributed to my username.

I could clean this SQL up a bit but bplog was essentially obsolete when I began using it in 2002, so I doubt there is a real demand for a full-on migration script. If you’d beg to differ, leave me a comment here and I may decide to help you out.