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

Hinterlasse eine Antwort