Naively, I thought this would be very easy. I assumed that there would be many tools already available for this (for sure, we are not the only ones in this situation!) but unfortunately, a search came almost empty (even a Quora question was unsuccessful). The only available resources are some SQL scripts (like this one and this or this other ones, building upon the former). Based on these scripts (and on a pictures of the databases schemas of wordpress and Drupal ) I decided to create a simple Java program that would perform the migration automatically.
Here I’ll comment on the migration steps performed by the program (the actual source code can be found at the end of this post). Of course, this program worked for me but I don’t claim it will work for you as well (in fact, some parts are very specific to my drupal installation so make sure you read the comments). Neither I claim the code is nice, efficient, well-organized,…. In the end I just started writing code, debugging it and improving it until it worked so not really carefully upfront design 🙂 However, I’m confident it will save you many hours of work it you’re in the same situation .
Here we go. Steps for migrating from Drupal 6 to WordPress 3:
- Create your wordpress installation in the same database where you have your Drupal installation (not mandatory but will facilitate things)
- Truncate the data in the following WordPress tables: comments, posts, postmeta, term_relationships, term_taxonomy, terms. Delete the users table (if you want to migrate Drupal users) except for the first one (the site administrator)
- Clone the taxonomies of categories you had in Drupal. Basically, data in term_data is moved to the WordPress table terms and term_hierarchy to term_taxonomy (each row in these two tables represent a parent-child relationship)
- Clone the posts. This involves retrieving data from three drupal tables: node (basic post info), node_revisions (body and teaser) and url_alias (url info) and inserting it into the single posts wordpress table.
- Fix the image/files URLs in the posts. Images in wordpress are usually stored in the uploads folder while Drupal stores them in the sites/default/files folder. So, the body content must be updated using a sentence like this one: body=body.replaceAll(“/sites/default/files/contentImages/”, “/wp-content/uploads/”);
- Fix the post URL itself. Drupal stores the full URL while WordPress only the last part (the one corresponding to a url-friendly version of the post title).
- Relate posts and categories. Take the relationships in the Drupal tables node and term_node and store them in the term_relationships wordpress table.
- Update the category count attribute now that we have inserted the data in term_relationships
- Migrate the comments. Quite straightforward, from the comments Drupal table to the comments wordpress table.
- Update the comment_count attribute in the posts table (if not comments will not be displayed even if they have been properly inserted in the database).
- (not part of the script) Don’t forget to define the redirection rules that will forward all requests to the previous URLs of your drupal posts to the new URLs of your wordpress ones!! You want people to be able to find your posts!
If you think this is useful, I kindly as you to help me spread the word about this post before downloading the file. Be sociable and share this content using the links below.
Link to download the source code.
ICREA Research Professor at Internet Interdisciplinary Institute (UOC). Leader of the SOM Research Lab focusing on the broad area of systems and software engineering. Home page.
Why couldn’t you just freeze the old content and just use WP for the new content ?
The main reason is that you want readers to be able to search and browse the full content of your site from a single place, not telling them that I they haven’t found what they’re looking for they could go to a previous version of the site and see if it’s there. Having two sites would also imply having two url’s and that’s not good for SEO.
More importantly – why did you want to migrate your blog?
That’s a very good question!. There were two main factors:
– I find WordPress much easier to configure and administer than Drupal 6 (Drupal 7 seems to improve this a little bit but still lacks of the same kind of modules and themes support that I needed). Just as an example, you can upgrade wordpress modules from the wordprss dashboard. Instead, for Drupal, you must open a ftp connection, download the new version, launch the update.php,…
– I realized that I was not really using all Drupal capabilities. WordPress is much more than a blogging platform now and covers all my needs with the portal. The only exception was the multi-language support. For that, Drupal is clearly better
too late now, but: Did you have a look at ‘drush’? (drupal.org/project/drush) It allows you to upgrade, install and do all other kinds of admin stuff on Drupal sites from the command line – great tool.
Having said that, I still agree, WP is so much easier to maintain – I’m still going back and forth trying to decide on which of the two platforms to use for an e-commerce site I’m building.
I didn’t know drush. Looks very interesting. As you say now it’s too late (and drush for itself would have not prevented the change) but I’d have liked to know about it during my last two years with Drupal!
There’s always a ‘next site’… 😉
It is in fact for ecommerce and such type of facilities that the WordPress community is just MUCH MORE advanced, and they create better looking stuff. WP-Ecommerce (getshopped.org) is fantastic. As is the new Jigoshop. The equivalents in Drupal were just painful and ugly looking, sorry.
I am also going to migrate from drupal 6 to wordpress. But I am not sure how I am going to transfer all my cck images, yet.
My site is in drupal 7.8, installing module is not a problem now, u can install new module from Module admin page.
I am a newbie and learned everything about drupal from forum and google. I am facing a major problem now, mysql database is increasing automatically. Hosting people said that it is a drupal problem, which they cant solve. Tried my best in forum, but none could help. So I was thinking to find the possibility of converting to WP. My site have basic/book/gallery pages. Is it possible to convert? any script or easy method to convert? Pl send me mail.
Have you tried to deactivate modules that may be storing cache information in the db?
I was thinking about this and the way I would do it is to make a View with just the info I would want to export, then get everything as XML or even a CSV. The trick would be to make it export in some way that WordPress already is set up to import from some other blog, so as to avoid having to write your own importer. I would probably imitate the Blogger format, since I’ve seen it work pretty well. Then I’d never have to mess with the database at all.
I guess this could work in some specific situations but I think it’s quite limited what you would be able to do with this approach. I find the database approach more direct and powerful (but, true, you need to have SQL knolwedge for that)
Thanks for the great script, how would one go about running the migration java program, I can’t seem to figure out how to run it.
Not sure what’s your problem. As long as you have the mysql library to establish the connection and change the configuration parameters to point to your database, the program has no other special requirements
Thanks for the reply, I meant how to physically run the program, what cmd should I use? I’m not familiar with java at all.
If you are not familiar with Java, then it’s better for you to use an editor like Eclipse IDE. It will be easier to setup and run the program. And of course, if you think you’re spent several hours with this, it may be better for you to just hire the http://migratetowp.com services to do the work!
I’d like to perform the migration away from the live Drupal site. My thinking is:
* Export the Drupal MySql database
* Install same version of Drupal on a local machine
* Import Drupal MySql in to local machine instance of Drupal
* Install WordPress to local machine in same database as Drupal
* Use your script to perform migration
Does this method appear to be sound? Is there anything I should be sure to do / not to do with the Drupal export? This step in particular is import as I’ve really got one shot with getting the Drupal export from the current host.
Thank you for your script. What about users with their passwords? Can they be imported into WordPress as well?
Yes, they can but this is not covered in the script. Contact migratetopw.com for this and other advanced migration features
Hi, i’m newbie!
How can i use the JAVA file for elaborate the mysql databse?
You can’t. The Java program does not create the wordpress database, assumes it’s already there (empty) and moves the data to it. You need to first install a fresh wordpress site before running the program
Ok, i know this, but i don’t know how i can run the java program and how this program can manipulate data in my sql. If it was a simple sql query, it will can execute in a sql sapce in phpmyadmin, but this java program? Sorry for my ignorance!
It´s a normal Java program. You need to change the connection parameters so that they “point” to mysql database. If you can’t figure it out, please contact us through migratetowp.com for professional assistance.