Generally speaking, Drupal does a great job of letting you bulk update content settings across your site. And where core falls short, usually a module called Views Bulk Operations (VBO) jumps in to save the day.
But recently I needed a way to bulk update comment settings. I have a side project where I set commenting to be closed for a content type that I ultimately needed to open commenting on. I searched for a while, even giving VBO a run, but it doesn’t provide the ability to update comment settings.
Unfortunately, there’s no module, so the next best thing was to update rows in the database manually. There are a couple places where rows need to be updated, so here’s the fastest and easiest way to update comment settings in the database.
WARNING: While this is a fairly simple process, if you do not know what you are looking at in the database, this can be a very bad idea!
Log Into Your Database via phpMyAdmin
Start by logging into your database through phpMyAdmin. Because there are so many different places that this might exist at your website’s host, I’ll leave it up to you to find the login area. Here is a snapshot of mine at MediaTemple.
Once you’ve logged in, you should see all your tables down the left-hand side and a whole mess of information (your tables again and some additional info) in the main frame. If you see a list of databases, and not database tables, in the left sidebar, make sure you click on the correct database before moving on.
Find Your Content Type’s Machine Name
Either in your website or in the database table called “node_type”, find the type of content you want to change and make a note of it’s machine name (in the website) or type (in the database). For our purposes, we’ll be looking at the “blog_article” content type.
Run the Update Content Type Comment Settings Query
Make sure you’re back in the root level of the database in phpMyAdmin (not inside a table listing). In the top navigation, you should see a button called “SQL”. You’ll be presented with a large textarea.
In this text area, paste the following code, replacing “blog_article” with your content type’s machine name. You’ll also want to replace the “2” with the status you’d like to set the comment settings to: 0=closed, 1=read only, 2=read/write.
This is the important step because this changes the comment settings in both the “node” table and the “node_revision” tables. Without changing both, it will look like comments are enabled/disabled, but they really won’t be changed.
UPDATE node_revision, node SET node_revision.comment = 2 WHERE node_revision.nid = node.nid AND node.type = "blog_article";
Once you’ve pasted in the above script and filled in your own settings, click “Go” in the lower right corner to run the script.
Thanks to Shai on Drupal.org for leaving this comment with the necessary SQL code.
It’s really quite simple, but after digging around with no luck, I finally stumbled upon this little gem and wanted to make sure it was easier to find for the next person trying to accomplish the same task!