This snippit allows you to bulk enable or disable comments for nodes through the database.

SQL to disable comments for all nodes of type "story":
UPDATE node SET comment = 0 WHERE type LIKE "story";

comment = 2 would mass enable read/write
comment = 1 would mass enable just read
You can change "story" to "page" or whatever you'd like.

An alternate solution using Drush

Shows what node types have been created:
drush sql-query "SELECT DISTINCT type FROM node ORDER BY type"

Shows what node types have been created that have comments enabled:
drush sql-query "SELECT DISTINCT type FROM node WHERE comment <> 0 ORDER BY type"

Shows nodes titles that have comments enabled:
drush sql-query "SELECT title, type, comment FROM node WHERE comment <> 0 ORDER BY type"

Drush SQL query to disable comments for all nodes of type "story":
drush sql-query "UPDATE node SET comment = 0 WHERE type LIKE 'story'"

An alternate solution using Views Bulk Operations

A different method would be using VBO. Admin Views provides an out-of-the-box replacement for your main content list using VBO (but you can use VBO without Admin Views also). You can then:

  1. select all the nodes you want
  2. choose the operation: Change value and click [execute]
  3. choose the value to modify (comments allowed), click [next]
  4. set value to 0 or 1 or 2

Comments

bevin’s picture

that is exactly what I need

doublejosh’s picture

Well, yes. But...
-- Would love to provide a UI to choose a large number of nodes, but not all of a type.
-- I prefer not to do this kind of thing in production.

ngstigator’s picture

AaronELBorg’s picture

You wanna do this via the abstraction layer, do ya?

Yeah, I know you do.

That's why I'm here to help you out, friend!!

$subquery = db_select('node');
$subquery->addField('node', 'nid');
$subquery->condition('node.type', 'YOUR_NODE_TYPE', '=');

$num_updated = db_update('node_revision')
->fields(array('comment' => '2',))
->condition ('node_revision.nid', $subquery, 'IN')
->execute();

I couldn't figure out how to do a join in a db_update.

Is it possible?

Shai’s picture

You need to change the setting in the node revisions table as well. Maybe something like the following in addition to the original query:

UPDATE node_revision, node SET node_revision.comment = 2 WHERE
  node_revision.nid = node.nid AND
  node.type = "story";
mchar’s picture

Why don't you update and the node table, so to be:

UPDATE node_revision, node SET node_revision.comment = 2, node.comment = 2 
 WHERE  node_revision.nid = node.nid AND  node.type = "story";

is it wrong to do so, or is there any difference or it will be updated (the node table) on some future node save through the UI ?

MakeOnlineShop’s picture

Thank you ! A lot easier than using boring unclear VBO !

rodtatham’s picture

Here's a complete example for a content type called "toolkit" in D7. This will turn on comments on all content types on your site:-

UPDATE `node` SET `comment` = '2' WHERE `type` = 'toolkit';
UPDATE node_revision SET comment=2 WHERE nid IN (SELECT nid FROM node WHERE node.type='toolkit');

Setting to zero rather than 2 turns them off.

Hope it's helpful.

dr.admin’s picture

Thank you, it is good example and it works.

--
Drupal sites and server support - https://drupal-admin.com

markshust’s picture

here's how to set all comments to read only after they are 3 months old

UPDATE node SET comment = 1 WHERE created <= UNIX_TIMESTAMP(DATE_SUB(now(), INTERVAL 3 MONTH));
UPDATE node_revision SET comment = 1 WHERE timestamp <= UNIX_TIMESTAMP(DATE_SUB(now(), INTERVAL 3 MONTH));
MakeOnlineShop’s picture

No module to batch enable or disable comments

Hello,

Nobody has ever made a module to enable comments or disable comments ?

Thank you.

emmonsaz’s picture

For Drupal 7, try disabling the core comment module.

venusrising’s picture

Bad idea if you happen to have comments on any views it will throw an error.

venusrising