February 27, 2013

Migrating Comments from Drupal 7 to Disqus

Over the past few months we've been busily working away on our brand new, nearly complete Fuse Interactive website, which will use Disqus in place of Drupal's commenting system. Of course, we didn't want to lose any of our existing comments when we made the switch, so we had to export our existing comments from Drupal and import them to our Disqus account. There's gotta be a module, right?

There is, or was, or sort of is... The point being that, although it wasn't exactly rocket science, getting the comments from Drupal and into Disqus wasn't as dead simple as I had hoped.

Because I don't like being made to think or search too hard (and neither should you), here is a no-brain-required guide to exporting Drupal 7 comments to Disqus.

What You'll Need

Step One

If you haven't already, download and enable the Disqus Module for your site.

Step Two

Go to the Disqus Migrate project page and follow the instructions there to clone the modules into your site's modules/contrib folder.

Then enable it (just checking, because I totally didn't overlook this step).

Step Three

Download the Disqus API Bindings for PHP and copy the disqusapi folder into your site's libraries folder.

Step Four

Log into your Disqus account.

Go to http://disqus.com/api/applications and register an application.

When you register the application make sure you add your domain and select "Inherit Permissions from" in the 'Authentication' section.

Upon completing this step you will be given two API keys, Public and Secret (which you can find later at http://disqus.com/api/applications/).

Step Five

Go back to your site and enter the Public and Secret keys in their respective fields within the 'Advanced' tab of the Disqus Module configuration menu.

While you're at it, enter your User API key (available at http://disqus.com/api/keys/) into the field within the 'Behaviour' tab.

Save your configuration.

Step Six

Go to your Comments administration menu and select 'Disqus Export' from the drop down. Click the 'Export all comments to XML file' button (obviously, right?) and you've got your comments all ready to go.

Well, mostly.

Step Seven

When I tried to upload the XML file the first time it mysteriously failed. Like any good problem solver I tried again, and like any good broken file it failed again.

This is because in my excitement I failed to make sure the XML file was valid. So it's probably a good idea to pay a visit to http://validator.w3.org and make sure your XML file is valid. It's also worth making sure your XML file is formatted properly, which means it looks something like this http://help.disqus.com/customer/portal/articles/472150.

If you are using Devel you'll want to turn it off or at the at the very least suppress its output. We ran into a problem with Devel appending a bunch of code to the end of our RSS file which, as you might expect, caused problems when uploading to Disqus.

If you're happy with your XML file you can now go to the Admin section of your Disqus account, open the Tools tab, select 'Generic(WXR)' and upload your file.

Step Eight

Send a thankful tweet to @dwkitchen for porting the Disqus Migrate module from Drupal 6 if you are feeling grateful. Otherwise hi-fives all around, rent a limo, etc.