Migrate from any Drupal version to 7.x

For a recent project, I had to migrate from Drupal 5 to Drupal 7. Here is how I did it without too much pain. The key steps are :

  • Export data to CSV from the original instance using Views module and a CSV output plugin.
  • Import them in the 7.x instance using Feeds.

The details :

  • On the 5.x side :
    • First, grab a copy from the 5.x site and install it locally.
    • Install views_bonus module.
    • Enable views_bonus_export. It will enable CSV export for views.
    • Create your export views. E.g. A view listing all "blog" nodes, with all needed fields.
    • Hack everything you need. Yes, just do whatever dirty hacks you need. This version of the 5.x site won't ever be used anywhere else, no one will ever blame you for killing kittens here. Need to reformat HTML output of some field ? Hack theme_views_bonus_export_csv() in views_bonus_module. Want to output Organic groups names in plain text instead of a link ? Go for og_handler_field_nodelink() in og_views.inc from go module. Feels so good to make dirty things sometimes.
    • Export each views to CSV files.
  • On the 7.x side :
    • Install feeds module. You may also need additional modules such as feeds_comment_processor, feeds_profile2_processor. Look at the feeds issue queue, there is a LOT of interesting things there which will help you get processors, patches (to keep hides kids e.g.) and tips you might need.
    • Install feeds_tamper. It modifies feeds data before it gets saved, so if hacking in 5.x was not enough, you could modify data before it is actually processed by feeds.
    • You may have to tweak feeds module a little for it to fit your needs.
    • Create feeds importers for each entity types you need to import. Adjust fields mappings.
    • I also had to create a custom import code for some pieces of content that were not handled by feeds, for example flags. PHP's fgetcsv() is your friend.
    • Import CSV files.
    • You're done !

You will probably have to test things around as I did for the process to go smoothly, but once everything is set up, things went very well.

This technique is applicable with any Drupal version, and even any source as long as you can export data to CSV.