I'm a bit surprised that there isn't an action to change the comment state (disabled/read/read-write) on a node. I will get around it with custom php, but this should probably be included as it's a common task.

Comments

mitchell’s picture

Marked #464424: Add action: *publish* comment as a duplicate of this issue.

fivehimself’s picture

Hi RoboPhred,

could you tell me if you managed to get around it by using custom PHP? I'm looking for the same thing here....

RoboPhred’s picture

I was, but once again my dns server has decided that my url does not exist. Since the site was a subdomain of a multi-site install, I can not access it to copy over the code.

I will try to remember to post it here later once the dns is done with its existential crisis.

Have a look at the api docs for the comment module:
http://api.drupal.org/api/drupal/modules--comment--comment.module/6

detot’s picture

also interested in how to solve this

RoboPhred’s picture

I created a rule set with two arguments: node (node) and enabled (boolean).

<?php
if(!module_exists('comment'))
  return;
if($enabled)
  $status = COMMENT_NODE_READ_WRITE;
else
  $status = COMMENT_NODE_READ_ONLY;
$node->comment = $status;

return array("node" => $node);
?>

This just toggles between read/write and read-only (locked). If you want to disable comments (so no existing comments are visible), check comment.module for the constant to use.

brad.bulger’s picture

changing the status of a particular comment is a distinct action from changing the comment status of a node, is it not? are these related as far as the relevant code changes? otherwise #464424: Add action: *publish* comment doesn't really seem like a duplicate issue.

wgrunberg’s picture

@RoboPhred
I am trying to construct a rules action which sets a node's commenting to read only. I have tried your code without success in a rules PHP action but I get the following error:
Parse error: syntax error, unexpected $end, expecting '(' in /drupal6/sites/all/modules/rules/rules/modules/php.rules.inc(107) : eval()'d code on line 1
I get the same error with a simplified version too:

$status = COMMENT_NODE_READ_ONLY;
$node->comment = $status;
return array("node" => $node);

I would appreciate any suggestions.

wgrunberg’s picture

I committed a newbie error in rules' custom PHP action and included the PHP tags. Once I removed them, the code worked very nicely. The PHP tags are apparently reserved for some form of pre-processing before execution.

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: Provided module integration » Rules Engine
Status: Active » Fixed

This should be fixed in 7.x. Please reopen if this is a mistake.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sslider999’s picture

Status: Closed (fixed) » Active

Hello,

If i`m not mistaken, there is no rule in version 7 for changing the node comment settings.

Can this feature be added?

Thanks,

fago’s picture

Oh, there is an entity property "Comments allowed, node:comment" - at least with recent version of the entity api. With that + the regular data_set action you can do it. I'd be open for adding a separate action though.

mitchell’s picture

Title: Node: Set comment status » Action: Set comment status
mitchell’s picture

Component: Rules Engine » Rules Core
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.