Import Wordpress Blog into Drupal with Users from Comments

I need to import an entire Wordpress blog to a new Drupal install. I want the posts, pages, authors, taxonomy, comments, and the users who made comments. The last one being the hang up, we didn't want to lose any users from the community during this migration.

In the end I used Wordpress Import module, the User Import module, a little manual parsing and some simple SQL and now have 300 new users linked to their original comments. But I took the long road to this solution, read on and I will relate my journey.

The Wordpress Import module works great. But, even though the exported WXR file contains email and other data for each comment the Wordpress Import module does not allow you to import and map these Wordpress users who made comments, only the authors of Wordpress posts.

So here I took a detour trying for a complete solution.

I decided to use Table Wizard module and Migrate module. Again two great modules that work great together. To start you need the Wordpress data prepped in database tables. But as I prepped the data, I didn't find a good tool to parse/export the WordPress eXtended RSS (WXR) file. So as I was starting to parse the WXR file on the command line, by hand and w/ PHP I realized this was NOT the simplest solution.

The simplest solution would be to use the great Wordpress Import module then create new users accounts and map these new users to their previous comments. Then with the addition of the User Import module all I needed to do was prep the user data before hand and map those users to comments with SQL.

Following are quick notes on my final process.



Get Wordpress data prepped

• Export WXR file from Wordpress.com:

- login at wordpress.com

- My DashBoard >> My Blogs >> Tools >> Export

- Select author

- Download Export File

- for use with the Wordpress Import module


Prep the comment user data from Wordpress WXR file:

• Grep from command line for comment user email address, plus extras:

- We didn't bother with anything but the email in the end because of the messy "names" and multiple names per email address that can be entered on the wordpress blog. You can get names as well as linked URLs per user if you wanted.

> grep '<wp:comment_author>\|<wp:comment_author_email>\|<wp:comment_author_url>' WORDPRESS-WXR-FILE.xml

• Search and clean up any commas ',' in author names via a text editor

- Only if you want more than email addresses

• Grep for lines with @ so as to have only email addresses, and sort by unique

> grep '@' GREPED-WORDPRESS-WXR-FILE.txt | sort -u

- if you wanted more than email address don't grep for @

• Search and replace via a text editor for tags so you have CSV of each record

- yes the tags right there in front of you :)

• Count your lines for kicks

> grep '@' GREPED-WORDPRESS-WXR-FILE.txt | sort -u | wc -l

• I used a Spreadsheet to quickly create a second column of user names from the user portion of the email address.

- Giving me an export of a "name,email" CSV file for use with the User Import module.


Use the Modules:

Wordpress Import module: http://drupal.org/project/wordpress_import

"This module imports a WordPress blog into Drupal from a WordPress eXtended RSS (WXR) file."

- Usage stats: http://drupal.org/project/usage/wordpress_import

- Dependancies:

- Ctools module: http://drupal.org/project/ctools

- Devel module: http://drupal.org/project/devel

User Import module: http://drupal.org/project/user_import

- "Import users into Drupal or update existing users with data from a CSV file (comma separated file)."

- Usage stats: http://drupal.org/project/usage/user_import


Read:

- wordpress_import/README.txt

- user_import/README.txt

Install all 4 modules:

- @ /sites/all/modules

Enable all 4 modules:

- Importing >> Word Press Import

- Chaos Tool Suite >> Chaos tools

- Development >> Devel

- Other >> User Import

Use modules to import data:

- Administer > Content management > Wordpress import

admin/content/wordpress_import/options

- Administer > User management > User imports

admin/user/user_import

Disable all 4 modules:


Map users to the comments:

I got here by reviewing database after making new user comments and new anonymous comments.

• Link new users to their proper comments w/ SQL:

> UPDATE comments, users SET comments.uid = users.uid, comments.name = users.name WHERE comments.mail = users.mail

• Clean other comments of Anonymous names

> UPDATE comments SET comments.name = "" WHERE comments.uid = 0

• Clean email and Homepage from all comments

> UPDATE comments SET comments.mail = "", comments.homepage = "" WHERE 1


===============================

Notes:

• I used the 6.x-2.1 version

• 6.x-2.1 is not dependent upon Menu

• Wordpress module does not allow you to import and map the Wordpress Users who made comments, only the Authors of Wordpress posts.

• Had to turn-up/add "upload_max_filesize = 4M" to my php.ini for larger uploads

• Possible problem w/ php 5.3.x? I did: http://drupal.org/node/716502

• These post talks about using table wizard and migrate tools:

- http://blog.merge.nl/2010/03/25/migrating-wordpress-site-with-users-drupal-6/

- http://www.lullabot.com/articles/drupal-data-imports-migrate-and-table-wizard

- Table Wizard module: http://drupal.org/project/tw

- Migrate module: http://drupal.org/project/migrate

- need a tool for exporting XML to mySQL or CSV/TAB delimited file for this use

• my Wordpress import:

- 289 posts/pages, 1159 comments, 1 authors, 27 categories, 13 tags

- blog->blog, page->blog

- map to single user

- cleaned up my taxonomy

- with secondary tags had to change the URL alias in path ./admin/build/path/patterns

- rebuild all paths

- via URL alias made the default path for the wordpress-tags have same path as other taxonomy, ie not: wordpress-tags

• my User import:

- 250 users, after cleaning up

• new Drupal site: I will post when live

Comments

I love the internet, one search and the answer is there, thank you crownedup (whoever you are)!!! I just got into Drupal and was so impressed that I had to quit my stale WP site, but alas, I didn't really want to quit, I really wanted to translate. I tried Word press import, but it didn't go the distance with all the interactions I had gained with comment users. Hopefully you have the answer. Will post results.

Did you also consider the Wordpress Import module? Is there a reason you chose not to use it for your migration? As far as I can see it includes the option of importing comments, categories and tags, and trackbacks.

I did use the Wordpress Import module, thats what this whole post is about.
I used the Wordpress Import module and the User Import module with a little direct SQL query action.

The only hangup I had using the wonderful Wordpress Import module was that I didn't want the Wordpress style "trackbacks", I wanted new Drupal Users linked to their previous comments. So after the Wordpress Import I used the User Import module to import new users that I parsed from the Wordpress WXR export file. Then with SQL I linked these new users to the proper comment and then cleaned the tables so that comments were either by these new users or "Anonymous".

The question I had, and didn't answer, and dropped because I had to get to the finish line, was:
Once you import the "not verified" comments in the trackback style, can you get these comments mapped to new Drupal user accounts so as to "verify" them?

Add new comment