Comments

fago’s picture

Yep that would make sense. Perhaps we can make the comment data type savable and do it like with nodes?

mitchell’s picture

Component: Rules Engine » Provided module integration
Status: Active » Postponed
Issue tags: +rules integration

This would be an awesome feature, and a good place to start might be the "Add new content" action, under "Node."

I'm hesitant to send this over to Drupal core: comment.module, so I'll leave it here for now under "provided module integration." Since this issue is without sufficient interest, I'm also going to mark this postponed for now.

amitaibu’s picture

Status: Postponed » Active

Let's keep it active, I might get to it.
btw, It's doesn't need the 'Rules integration' tag - this is needed for other *contrib* modules integration with Rules.

amitaibu’s picture

btw, thanks Mitchell for the issue queue cleanup :)

mitchell’s picture

Np, Amitai. Thank you for the feedback.

mitchell’s picture

Project: Rules » Drupal core
Version: 6.x-1.x-dev » 7.x-dev
Component: Provided module integration » comment.module
Issue tags: -rules integration

Moving to core, removing rules tag.

mitchell’s picture

Project: Drupal core » Rules
Version: 7.x-dev » 6.x-1.x-dev
Component: comment.module » Provided module integration
Issue tags: +comment, +rules 1.0

The core developers don't seem too focused on actions. Moving back to Rules.

criz’s picture

subscribe...

Encarte’s picture

subscribe

Azol’s picture

Subscribe

Witch’s picture

i am very interested in it!

*subscribe*

attiks’s picture

I needed this urgently so a quick stab at it, code added to comment.rules.inc but still needs some love

// second action added, first one is already there
function comment_rules_action_info() {
  return array(
    'rules_action_load_comment' => array(
      'label' => t('Load comment by id'),
      'arguments' => array(
        'cid' => array(
          'type' => 'number',
          'label' => t('Comment id'),
          'required' => TRUE,
        ),
      ),
      'new variables' => array(
        'comment_loaded' => array(
          'type' => 'comment',
          'label' => t('Loaded comment'),
          'label callback' => 'rules_action_load_comment_variable_label',
        ),
      ),
      'module' => 'Comment',
    ),
    'rules_action_add_comment' => array(
      'label' => t('Add comment to a node'),
      'arguments' => array(
        'nid' => array(
          'type' => 'node',
          'label' => t('Node id'),
          'required' => TRUE,
        ),
        'user' => array(
          'type' => 'user',
          'label' => t('Author'),
          'required' => TRUE,
        ),
      ),
      'eval input' => array('subject', 'message'),
      'module' => 'Comment',
    ),
  );
}

function rules_action_add_comment($node, $user, $settings) {
  $comment = array();
  $comment['pid'] = 0;
  $comment['nid'] = $node->nid;
  $comment['uid'] = $user->uid;
  $comment['name'] = $user->name;

  $comment['subject'] = $settings['subject'];
  $comment['comment'] = $settings['comment'];

  comment_save($comment);
}

function rules_action_add_comment_form($settings = array(), &$form, $form_state) {
  $settings += array('subject' => '', 'comment' => '');

  $form['settings']['subject'] = array(
    '#type' => 'textfield',
    '#size' => 30,
    '#title' => t('Subject'),
    '#default_value' => $settings['subject'],
  );
  $form['settings']['comment'] = array(
    '#type' => 'textarea',
    '#size' => 30,
    '#title' => t('Comment'),
    '#default_value' => $settings['comment'],
  );
}
Witch’s picture

i will test it later!

thank you!

attiks’s picture

problems i noticed my self:
- for the node and user you'll see too many options
- input format is blank for the moment, maybe better to turn it into an option

fago’s picture

Status: Active » Needs work

Please roll proper patches again the current dev branch.

attiks’s picture

@fago (or anyone else)
can you help with my questions in #14?

fago’s picture

With what specifically? What do yo mean with too many options?

This is already supported in 7.x, so any 6.x integration should use the same argument names than in 7.x in order to ease upgrading. For saving the comment, it should fix the comment data type to be savable and then leverage rules saving mechanism.

joecanti’s picture

+1

This would be a good feature

Gave the code a quick test but got the following:

Fatal error: Cannot redeclare comment_rules_action_info() - line 214 of comment.rules.inc

Thanks, Joe

attiks’s picture

@Joe

The comment_rules_action_info() function in #12 replaces the one that's already there.

attiks’s picture

StatusFileSize
new4.33 KB

@fago,

See screenshot, I'm seeing users where I expect to only see nodes

zeezhao’s picture

subscribing

fago’s picture

The code looks good so far, I don't think it should show you a user. Try creating a new action, the existing one might have cached old action info.

joecanti’s picture

Thanks attiks - removed the extra instance and worked great. works well for my needs, which is to use it as a vote counter. Am keeping an eye on the Rules integration for voting API which will be amazing, but for now this does a great job of counting votes. When a user presses a flag 'vote now' on a node, a +1 comment is added to that node, then the flag is taken off an a message displayed to the user - 'thanks for voting!'

Now the comment count is displayed as 'votes' and the content is sorted by comment count on a separate page, giving a nice ranking system. Will be interesting to see how it performs under lots of pressure - ie thousands of votes... Any ideas how it would cope? Design runs in panels and views - so the 'voted on' node never gets displayed - the comments never see the light of day... Just the parts of the node needed - ie the picture, title, comment count - votes, and a 'vote now' button.

Perhaps not the intended use, but seems to be more reliable than other work around voting systems I have tried to build...

Thanks again, Joe

zeezhao’s picture

Hi. I tried it out and it works fine. The only thing is I am using it with a casetracker based module that publishes html as part of the comment. Hence some of the html came out in raw text...

So I support the need for "input format" as an option.

Also, I got a "warning: preg_match() expects parameter 2 to be string, array given in ....\includes\bootstrap.inc on line 777" after psoting the comment. Not sure yet what is causing it though i.e. either rules comment or casetracker

Thanks for providing this addition to rules.

attiks’s picture

New version with support for input format, if ok i'll create a patch

function comment_rules_action_info() {
  return array(
    'rules_action_load_comment' => array(
      'label' => t('Load comment by id'),
      'arguments' => array(
        'cid' => array(
          'type' => 'number',
          'label' => t('Comment id'),
          'required' => TRUE,
        ),
      ),
      'new variables' => array(
        'comment_loaded' => array(
          'type' => 'comment',
          'label' => t('Loaded comment'),
          'label callback' => 'rules_action_load_comment_variable_label',
        ),
      ),
      'module' => 'Comment',
    ),
    'rules_action_add_comment' => array(
      'label' => t('Add comment to a node'),
      'arguments' => array(
        'nid' => array(
          'type' => 'node',
          'label' => t('Node id'),
          'required' => TRUE,
        ),
        'user' => array(
          'type' => 'user',
          'label' => t('Author'),
          'required' => TRUE,
        ),
      ),
      'eval input' => array('format', 'subject', 'message'),
      'module' => 'Comment',
    ),
  );
}

function rules_action_add_comment($node, $user, $settings) {
  $comment = array();
  $comment['pid'] = 0;
  $comment['nid'] = $node->nid;
  $comment['uid'] = $user->uid;
  $comment['name'] = $user->name;

  $comment['format'] = $settings['format'];
  $comment['subject'] = $settings['subject'];
  $comment['comment'] = $settings['comment'];

  comment_save($comment);
}

function rules_action_add_comment_form($settings = array(), &$form, $form_state) {
  $settings += array('format' => '', 'subject' => '', 'comment' => '');
  $formats = filter_formats();
  $format_options = array();
  foreach ($formats as $id => $format) {
    $format_options[$id] = $format->name;
  }

  $form['settings']['subject'] = array(
    '#type' => 'textfield',
    '#size' => 30,
    '#title' => t('Subject'),
    '#default_value' => $settings['subject'],
  );
  $form['settings']['comment'] = array(
    '#type' => 'textarea',
    '#size' => 30,
    '#title' => t('Comment'),
    '#default_value' => $settings['comment'],
  );
  $form['settings']['format'] = array(
    '#type' => 'select',
    '#options' => $format_options,
    '#title' => t('Input format'),
    '#default_value' => $settings['format'] ? $settings['format'] : variable_get('filter_default_format', 1),
  );
}
zeezhao’s picture

Thanks for the patch. I tried it briefly, and it does work fine.

However, I still get the error I mentioned in #24:

"warning: preg_match() expects parameter 2 to be string, array given in ....\includes\bootstrap.inc on line 777" 

after posting the comment via a rule. But I can not confirm if the error is being caused by the casetracker module against which the comment is posted.

If no one else is seeing the error, then patch looks fine and will have to find out why casetracker is generating this. Thanks

attiks’s picture

#26: I don't get the error even with casetracker (actually openatrium)

zeezhao’s picture

referring to #27, thanks for your feedback. I am using latest casetracker 6.x-1.x-dev. Does openatrium still sync up with this?

I believe the error is caused by ct module, as after posting the comment via rule, the node always now gives that error message when trying to view it.... As I am not very familiar with its code, I posted this here:

http://drupal.org/node/826082

I think its something to do with how the Project gets posted.

Anyway, thanks for your help.

attiks’s picture

#28: my mistake, the nodes i'm using it on are not casetracker-enabled nodes so i tested it on a case-node, but i don't get the error message

mehoo462’s picture

This works and is very awesome! Thank you.

One thing: tokens seem to work in the Subject of the Comment but not in the body. Is this a simple fix? I would do it if I knew anything about PHP. Any help would be greatly appreciated.

mitchell’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: Provided module integration » Rules Engine
Status: Needs work » Active
Issue tags: -rules 1.0

Happy to see work went into this that could potentially get committed to 6.x, but feature requests are getting bumped now. I'm guessing this will be a lot easier in 7.x anyway. See #17 for some 7.x info.

fago’s picture

Version: 7.x-2.x-dev » 6.x-1.0

7.x already supports creating comments, so working on a 6.x solution is fine now. But the 6.x solution should require the same settings as the 7.x version.

rickvug’s picture

Attached is the code in #25 as a patch. Only change is adding a comments for the functions and moving the form into comment.rules_forms.inc. Further reviews and testing surely needed.

@Fago - I don't see this action in Rules 7.x-2.x-dev. Is this where I should be looking to ensure that settings are the same as the D7 version?

rickvug’s picture

Status: Active » Needs review
StatusFileSize
new3.06 KB

Doh! Forgot to attach the patch.

attiks’s picture

Status: Needs review » Active
rickvug’s picture

@attiks Yes, this is the file I looked at. I'd expect a function called comment_rules_action_info() but I don't see it. I don't think this is due to an API change as node.rules inc implements hook_rules_action_info().

rickvug’s picture

StatusFileSize
new2.95 KB

Here's a slightly updated patch. It fixes the arguments configuration and also makes the comment body field required. The base functionality is working but I've found a few issues:

- Token support is not working.
- Comment subject is not set automatically if you leave the field blank.

attiks’s picture

I think you have to code to have support for automatic title (see http://api.drupal.org/api/function/_comment_form_submit/6) and token support

rickvug’s picture

StatusFileSize
new3.78 KB

Here's an updated patch. This fixes the subject issue (@attiks - we're thinking on the same page). As for token support, 'eval input' is being set as follows:

'eval input' => array('subject', 'comment', 'format'),

This matches the values in the $settings array. Any hints as to why this is not working?

rickvug’s picture

Status: Active » Needs review
StatusFileSize
new3.8 KB

Sorry for so many updates as work progresses. Tokens are actually working. I just needed to configure the rule again for the change to take effect. Attached is the same patch as #40 with format no longer being evaluated (not sure why that was listed first time around).

Back to needs review.

klausi’s picture

@rickvug: you can create a comment in Rules 7.x-2.x-dev with the action "Create a new entity".

rickvug’s picture

@klausi Thanks. I looked at data.rules.inc but found the code difficult to follow to where the settings are defined. Settings such as $settings['entity:select'] and $settings['type'] don't look to line up with comments in D6. If you or someone else could provide more specific guidance on settings that would be helpful.

rickvug’s picture

@fago I don't think that I fully understand Rules data types. In what way does this effect the action? I'm assuming that making the comment data type requires this change in class rules_data_type_comment:

 function save() {
    $comment = &$this->get();
    comment_save($comment);
    return TRUE;
  }

And also setting the savable flag:

function comment_rules_data_type_info() {
  return array(
    'comment' => array(
      'label' => t('comment'),
      'class' => 'rules_data_type_comment',
      'savable' => TRUE,
      'identifiable' => TRUE,
      'module' => 'Comment',
    ),
  );
}
klausi’s picture

Status: Needs review » Needs work

I Rules 2 we have the following setting fields:
subject
node
author
comment body including text format

So that looks complete. I suggest to use "Add new comment" as label to be consistent with "Add new content" for nodes.

When I tested the action, I get a notice: "notice: Undefined index: cid in /var/www/klausi/web/drupal-6/modules/comment/comment.module on line 700.". So I think you want to set cid to 0 as well, I guess.

klausi’s picture

@rickvug: don't worry too much about Rules 2 internals, fago just referred to the settings that are configurable in Rules 2. I think your solutions looks good and is nearly ready.

rickvug’s picture

Status: Needs work » Needs review

Attached is an updated patch. The label has been changed as per suggestion.

@klausi - I'm not experiencing the same notice in testing. In any case, I've set $comment['cid'] = NULL and everything works. I get the same behaviour if I set ['cid'] to "0" or don't set it at all. My error reporting is set to E_ALL.

Setting to needs review. Fingers are crossed.

klausi’s picture

Status: Needs review » Needs work

patch is missing.

Make sure that you use Drupal 6-dev from CVS where such PHP notices are enabled and displayed as Drupal messages.

rickvug’s picture

Status: Needs work » Needs review
StatusFileSize
new3.69 KB

@klausi - Here's the patch that I was going to submit previously. I switched to using D6 dev checked out from CVS and could reproduce your error. Setting cid to NULL fixes the issue.

klausi’s picture

Status: Needs review » Needs work
+++ rules/modules/comment.rules.inc	13 Oct 2010 12:53:03 -0000
@@ -129,6 +129,15 @@ function comment_rules_action_info() {
+        'author' => array('type' => 'user', 'label' => t('User, who is set as author')),

use the label from rules 2: "The author of the comment"

+++ rules/modules/comment.rules_forms.inc	13 Oct 2010 12:53:03 -0000
@@ -18,5 +18,36 @@ function rules_action_load_comment_varia
+  $form['settings']['comment'] = array(

let's name this element "comment_body" to be consistent with rules 2

+++ rules/modules/comment.rules_forms.inc	13 Oct 2010 12:53:03 -0000
@@ -18,5 +18,36 @@ function rules_action_load_comment_varia
+  $form['settings']['format'] = array(

and this "comment_body_format"

Powered by Dreditor.

rickvug’s picture

Status: Needs work » Needs review
StatusFileSize
new3.79 KB

Attached is an updated patch that contains the changes requested by klausi in #50.

klausi’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

Great, works for me. Leaving the final commit for fago.

YK85’s picture

subscribe

fago’s picture

Status: Reviewed & tested by the community » Needs work

Patch looks good, however as I've noted in #17 it should make use of the rules saving mechanism for comments to save it.

#17:
>For saving the comment, it should fix the comment data type to be savable and then leverage rules saving mechanism.

Once you've fixed the data type, you can use the node add action as example to follow.

Witch’s picture

Any news about this?

sreher’s picture

thanks for the patch - it makes some very nice features available. And it works great.

I discover an bug. The content and the subject of a comment isn't shown when you reload the page "Editing action Add new comment".
It saves the date in the database, but not loaded it again, so you have to put in new changed data to update it.
Where does the patch load the data from the comment to display it in the rules admin section?

Can anybody help?

baff’s picture

subscribe

mbiddlecombe’s picture

subscribe

Kman2123’s picture

sub

Kman2123’s picture

How do you put this patch in? Any chance that it will be included in the dev release or recommended release?

Azol’s picture

I am currently preparing the new patch to meet the requirements that fago has outlined in #54. Hopefully it will be ready today.

Kman2123’s picture

Oh! That's great news! Thanks!

Azol’s picture

Assigned: Unassigned » Azol
Status: Needs work » Needs review
StatusFileSize
new2.85 KB

Okay, based on patch #51 and fago's recommendations #54.
Worked nicely for me.
I had some troubles with Git (was I the only one?) and Eclipse decided to screw up everything, but hopefully it will work...
Think I am going to assign it to myself since I desperately need this feature for my project...

Status: Needs review » Needs work

The last submitted patch, 376648-add-comment.patch, failed testing.

Azol’s picture

Status: Needs work » Needs review
StatusFileSize
new2.76 KB

Oops, again

Kman2123’s picture

Assigned: Azol » Unassigned
Status: Needs review » Needs work

I am new to patching, where do I insert this or how do I get it?

Thanks for your help!

Kman2123’s picture

Sorry I didn't mean to bump you off it!

Azol’s picture

Status: Needs work » Needs review

http://drupal.org/node/620014 (automated) or
http://drupal.org/node/534548 (manual)

And please, do not change the status of this issue (http://drupal.org/node/156119) unless you absolutely must :)

Azol’s picture

Assigned: Unassigned » Azol

Gah

Azol’s picture

I found no problems with this patch so far, has anyone else tested it?
WTB RTBC :)

fago’s picture

Status: Needs review » Needs work
+    // Note: format is checked by check_markup().
+    $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($settings['comment_body'], $settings['comment_body_format'])))), 29, TRUE);

This would check access permissions on run-time what is wrong. If one configures a rule, one usually wants to perform regardless of the permissions of the currently logged in user. Thus if, any permission checks should be done when the action is configured + notify the site-builder of that behaviour. Thus, site-builders should be aware that creating this with a PHP input filter and custom tokens might be a "small" security hole. So maybe add a small note the config form.

BTW: I see no config form for the action?

chey’s picture

Is this still being worked on? Any updates? I'm not sure what fago is trying to say in comment #73.

Azol’s picture

Had no time to look into it yet. It's a week of work for me what an experienced drupaler will achieve in three minutes...

baff’s picture

is #67 the solution so far?

gkelly’s picture

sub. This would be a really useful feature when completed.

eg208’s picture

subscribe

eg208’s picture

Status: Needs work » Needs review

#67: 376648-add-comment.patch queued for re-testing.

klausi’s picture

stop subscribing, start following http://drupal.org/node/1306444

fago’s picture

Status: Needs review » Needs work

see #73

Azol’s picture

StatusFileSize
new2.96 KB

New patch:

1) added settings form
2) removed comment subject truncation at the moment until I can find a better (more secure?) solution

Known bug: if commented node contains CCK user reference fields, they become NULL for some reason. Would be great if someone could help troubleshooting this issue.

attiks’s picture

Status: Needs work » Needs review
Azol’s picture

Status: Needs review » Needs work

Setting this back to Needs work due to the bug I described. Any help with troubleshooting is welcome!

mitchell’s picture

Component: Rules Engine » Rules Core

Updated component.

nicodv’s picture

Is there a patch that does this in d7?

Thanks

IWasBornToWin’s picture

at #86, you dont need a patch for d7, you can do it under "add new entity" and then choose, "comment"

kopeboy’s picture

Title: Action: make comment » Can't comment on node if comment body is plain text field
Version: 6.x-1.x-dev » 7.x-2.x-dev
Category: Feature request » Bug report
Issue summary: View changes

Actually you can't if the comment body field is set to plain text.

This is a bug instead.
There are no data selectors for it.

You decide if it's better to fix the bug (Create a new entity of type comment) or do the (new feature) action "Add comment".

This might be relevant: #1770440: Text comparison on comment-body:value not working if Comment set to Plain text processing

tr’s picture

Status: Needs work » Closed (won't fix)
Issue tags: -comment

This issue is a D6 issue, or at least it was until the last comment #88. I'm not sure why it was moved to D7 - the D7 issue described in #88 is being handled by #1811812: Creating a Comment directly after saving a node. and #1770440: Text comparison on comment-body:value not working if Comment set to Plain text processing

Marking this current issue as won't fix because it was about D6 and D6 has not been supported for almost three years now.

tr’s picture

Version: 7.x-2.x-dev » 6.x-1.x-dev