Looking for a fast and reliable professional Drupal to WordPress migration service (including migration of users, custom content types, forums and many other advanced features) ?. Check our brand new migratetowp.com site. More than 3 milion items migrated already!!!
As part of the renovation of this modeling languages portal, we dropped Drupal and started using WordPress as CMS. Of course, this forced us to migrate two years of portal posts, comments, categories,… over to WordPress.
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 (and if you want to save even more hours, let us do the migration for you) .
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.
Contact us for more information