Migrating From Wordpress To Drupal

Before I began the transition from Wordpress 2.0.3 to Drupal 4.7, I researched as much as I could. I hunted import scripts and I examined the mySQL databases from each. Over the course of the week before I made the move, I tested a combination of ways to get the conversion done, with as little of a disruption as possible. My requirements for the move were simple. I wanted all of my posts, comments and categories moved over, intact. Simple, right?

I found the current wp2drupal module and found that it did not pull category information so I made a couple of modifications and tweaks, and with a little effort I was able to import every post, comment, and category from Wordpress to Drupal.

I am posting the following information as a guideline for those wanting to convert their Wordpress blog into Drupal. While these instructions worked for me, they may not work for everyone, since every configuration is different. I just thought it would be nice to post the instructions so others might not have to search as hard as I did. If you are not familiar with mySQL or php, I do NOT recommend doing this yourself.

The first thing I did, of course, was setup up Drupal 4.7. I followed the basic installation procedures. Once the installation was complete I installed the pathauto module (which will provide the ‘nice’ urls that most Wordpress users are accustomed too). I made sure to configure pathauto so the url’s would reflect the same format as those used by my Wordpress permalinks.

The second thing I did was download the wp2drupal module. For the record, the revision I used was 349.

I opened the module and made the following changes:

Line #189 (approximate):

$wp_table_prefix = variable_get(’wp2drupal_wp_table_prefix’, ”);

was changed to:

$wp_table_prefix = variable_get(’wp2drupal_wp_table_prefix’, ‘wp_’);

Line #250 (approximate):

I added the following line to the module:

db_query(”INSERT INTO term_node VALUES (” . $node_nid . “,” . $wp_post->post_category .”)”);

I placed this line before this line:

$wp_comment_sql = “SELECT comment_author, comment_author_email, comment_author_url, comment_date, comment_content, comment_author_IP, comment_approved FROM ” . $wp_prefix . “comments WHERE comment_post_ID = ” . $wp_post->ID . ” ORDER BY comment_date ASC”;

I am sure I could have made some further changes to the module to make some things easier later in the process, but that’s work for another day. hehe. I saved the changes I made to the module. I did not run the module at this time.

The next thing I did was import a few tables FROM the Wordpress database INTO the Drupal database. The tables I imported were wp_posts, wp_comments, wp_post2cat, and wp_categories. I ran the following query to grab the category number from the post2cat table and plug it into the posts table (where I think it should have been in the first place).

Next, I set up a vocabulary item in Drupal named ‘Category’.

It was then time to run the wp2drupal module. I had a bit of a problem with the importer timing out, because of the sheer volume of posts on my site (5,000) and my php settings. Once I tweaked things, the import worked flawlessly.

At this point of the conversion, I had successfully imported 5,000 posts and 3, 025 comments, but I still didn’t have category names in my posts. I did, however, have those category numbers I wrote into the term_node table. It was time to match those numbers with the names that go with them.

I ran an export of the wp_categories table using phpMyAdmin, of which I copied out all of the lines like the following:

INSERT INTO `wp_categories` VALUES (1, ‘Unclassified’, ‘unclassified’, ”, 0, 10);
INSERT INTO `wp_categories` VALUES (2, ‘Personalized’, ‘personalized’, ”, 0, 268);
INSERT INTO `wp_categories` VALUES (3, ‘FYI’, ‘fyi’, ”, 0, 231);
INSERT INTO `wp_categories` VALUES (4, ‘Programming’, ‘programming’, ”, 0, 42);

I then manually edited these lines to reflect the following:

INSERT INTO `term_data` VALUES (1, 1,’Unclassified’, ”, 0);
INSERT INTO `term_data` VALUES (2, 1, ‘Personalized’, ”, 0);
INSERT INTO `term_data` VALUES (3, 1, ‘FYI’, ”, 0);
INSERT INTO `term_data` VALUES (4, 1, ‘Programming’, ”, 0);

I made sure that each new number and title matched the old number and title. When I was done modifying the lines, I entered the SQL into phpMyAdmin, and each “category” was now imported into Drupal.

At this point I also created another set of insert statements,

INSERT INTO `term_hierarchy` VALUES (1, 0);
INSERT INTO `term_hierarchy` VALUES (2, 0);
INSERT INTO `term_hierarchy` VALUES (3, 0);
INSERT INTO `term_hierarchy` VALUES (4, 0);

for each category number (ie: if there are 17 categories, you would create a list like this from 1 through 17). I entered this SQL as well, as everything was in place.

A quick refresh of my page showed not only that I had successfully imported posts, comments, and categories into Drupal, but that each url matched the ones Wordpress utilized previously.

And that’s it. That was how I migrated from Wordpress 2.0.3 to Drupal 4.7. I think I covered everything, but if something doesn’t make sense, let me know, and I will edit this post accordingly.

Also, I would like to thank Vinny, for helping with the query to grab the category names in the first place.

Sphere: Related Content

Posted on June 18, 2006
864 words · print

4 Comments so far

1

Thom on December 3, 2006 comments:

Hello,

Thanks for the detailed directions–they are quite helpful.

However…it doesn’t seem to work for me with Drupal 4.7.4 and WP2. I’m getting an error when I try to import posts:

warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mydirectory/public_html/drupal/modules/wp2drupal/wp2drupal.module on line 203.

Any idea what might be wrong here? Thanks.

2

Tammara Nelson on December 3, 2006 comments:

Converting 5000 posts indeed would have been a large task to do, :shock: but for my needs it just may work since I don’t have too much content.

Thanks again for providing the helpful information! Although I haven’t yet decided on Drupal, it makes me feel more optimistic about the possibility of conversion to their CMS.

3

Slobokan on December 3, 2006 comments:

I suppose you could enter them all in manually, if that’s what you preferred. I, on the other hand, was not going to manually enter 5,000 posts to do the conversion.

4

Tammara Nelson on December 3, 2006 comments:

Hi Slobokan,
I find your research very interesting. I like WordPress, but I’m considering Drupal in order to have a better interface for a community. In order to preserve the post and page permalinks for obvious seo reasons as you did, is there still not an easier way to do the conversion to Drupal if I should consider?

The secret codes you provided above evidently did the trick for you, but appears to be a lot of work, especially for one who is better at blogging than the technical stuff - me! :oops:

Looking at Drupals demo for creating and posting pages could one not just simply recreate the posts and pages with the permalinks by using the field they provide where the following is noted on their demo? :?: Would that not preserve the url file paths already published online?

“Optionally specify an alternative URL by which this node can be accessed. For example, type “about” when writing an about page. Use a relative path and don’t add a trailing slash or the URL alias won’t work.”

Can’t the WordPress permalinks just simply be copied into the field the Drupal admin area provides? (This is assuming that one does not have hundreds of posts and pages such as myself, since that route would be labor intensive but at least not require code modifications.) But, probably not a solution for someone who has significant posts and pages to convert to Drupal?

Informative article. Thanks.

Leave a reply

Name (required)

Email (required)

Website

Comments

If this is your first time commenting on Slobokan's Site O' Schtuff, your comment will be held for moderation. Once your comment is approved by Slobokan, any future comments will not be held for moderation. Comments may be edited or deleted at the discretion of Slobokan, and may be re-produced at any time for the purpose of discussion, argument, or ridicule. This policy is not open for debate. If you do not agree, do not comment. It's that simple.