Migration finished

As I wrote in the last post i was thinking about migrating back to wordpress. The steps are almost done. I don’t use categories anymore and the few links i had were added manually after the db-migration. What’s still left to do is to look for a nice theme and install some nifty plugins.

Thoughts about migrating (back) from Drupal to WordPress

Here’s something I found on this webpage related to a Drupal2Wordpress database migration:

prerequisites:

  • A fresh and clean installation of WordPress
  • Drupal database name: drupal (no table-suffix)
  • WordPress database name: wordpress (table-suffix ‚wp_‘)

Fire up the mysql cli:

USE wordpress;
DELETE FROM wp_posts ;
DELETE FROM wp_comments;
INSERT INTO wp_posts( ID, post_author, post_date, post_content, post_title, post_excerpt, post_name, post_modified )
SELECT a.nid, 1, FROM_UNIXTIME(a.created), b.body, a.title, b.teaser, concat('OLD',a.nid), FROM_UNIXTIME(a.changed)
FROM drupal.node as a, drupal.node_revisions as b
WHERE a.nid = b.nid AND (a.type='blog' OR a.type='page' OR a.type='story' OR a.type='forum');
INSERT INTO wp_comments ( comment_post_ID, comment_date, comment_content, comment_parent )
SELECT nid, FROM_UNIXTIME(timestamp), concat(subject,' ', comment), thread FROM drupal.comments ;

For the last part I wrote a perl-script, because the statement needs to iterate over all posts and calculate the related amount of comments. For getting this to work the user who runs the script needs to be able to login without a password to mysql. This can e.g. be achieved by a .my.cnf file in the home directory of the user.

#!/usr/bin/perl

@postids = echo "select ID from wp_posts" | mysql wordpress;

foreach (@postids) {
if ($_ == "ID") { next }
print $_;
system "echo 'UPDATE wp_posts SET comment_count = (SELECT count(*) from wp_comments where comment_post_ID = $_) where ID = $_;' | mysql wordpress";
system "echo 'SELECT comment_count from wp_posts where ID = $_;' | mysql wordpress";
}

I wrote this in a very short amount of time and I know it’s very dirty, but it works 🙂

Things that are still missing:

  • User migration
  • Post and Comment Formating
  • Categories

schmalenegger.com migrated to Drupal

Within the last days i migrated this website from WordPress to Drupal6. The wp2drupal module helped a lot at moving the content to the new drupal db.
I think, that most of the things work now, but let’s see… 😉