Import Drupal Comments into Disqus
Among the recent updates to this powered-by-Drupal blog is a switch to having Disqus manage comments. The standard comment module has a few shortcomings which are solved by Disqus. However, Disqus isn't without its own problems and the absent "import comments from Drupal" functionality is one of them.
Reasons for the Switch
My main reason for the change is because Disqus allows users to subscribe to followup comments by email. I was using Drupal's subscriptions module to notify users when a new comment was posted. However, this module processed comments before Akismet and I ended up blasting subscribers with spam.
That's not all, though. are some other advantages of using Disqus over Drupal.
The big problem for me, however, is that Disqus doesn't have an easy way to import comments from Drupal. Since this blog has been up for a while, I would lose a lot of comments if I just let them go. A lot of them provide additional help on tutorial blog posts so there is definitely motivation to keep them.
Getting Drupal's Comments into Disqus
Now Disqus isn't missing import functionality altogether. I'm sure that eventually, the Disqus module for Drupal will include it. WordPress already has a plug-in that can do this and there are options to upload XML comment files exported from JS-Kit and IntenseDebate.
I took the easy route: instead of learning the Disqus API, I learned the IntenseDebate comment export format. I signed up for an IntenseDebate account, created some test comments, and hit export. The format is pretty straightforward, and, since it's XML, self-descriptive.
<output> <blogpost> <url>http%3A%2F%2Fdanielmclaren.com%2Fnode%2F4</url> <title>How to Use Cross-Domain Shared Objects in Flash</title> <guid>http://danielmclaren.com/node/4</guid> <comments> <comment> <isAnon>1</isAnon> <name>so-and-so</name> <email>firstname.lastname@example.org</email> <url>http://example.com</url> <ip/> <comment>I like your site!</comment> <date>2009-10-08 10:25:25</date> <gmt>2009-10-08 10:25:25</gmt> <score>1</score> </comment> </comments> </blogpost>
Using a PHP script, you can generate the XML output for your own comments. Ideally, the comment info would be gathered using the Drupal API but I just plugged right into the database. Now all you have to do is save the XML to a local file, and upload that file in the Disqus import/export page, using IntenseDebate as the format.
The IntenseDebate Export Script
A few notes about the script which translates your Drupal comments to the IntenseDebate format:
- The script assumes you're using clean URLs.
- Registered users aren't handled any differently from anonymous users. I'm the only registered user on my blog so if your website is any different, you might need to make changes.
- The script includes a bunch of entity information in the doctype so you can view the XML properly in Firefox. Comment out the DOCTYPE lines if you don't need it.
Just to be safe, I'd recommend backing up your database. Also, have a good look at the output XML before uploading it to Disqus. You might want to do some tweaking before sending off to their import service.
Let me know if you find this useful or if you run into problems. Good luck!