3

As a sequence on this question, I'd like to deduct 2 User Points when a user's first reaction on an Article is deleted (I mentioned my flag 'First reaction' there). I created a Rule 'Reaction removed' with the following settings:

EVENTS: After deleting a comment

CONDITIONS:

  • Comment is flagged Parameter: Flag: First reaction, comment: [comment], User on whose behalf to check: [comment:author]

ACTIONS:

  • Grant points to a user Parameter: User: [comment:author], Points: -2, Points category: Reaction, Operation: Delete, Moderate: Automatically approved
  • Unflag a Node: Parameter: Flag: Commented on a node, Node: [comment:node], User on whose behalf to flag: [comment:author], Skip permission check: false

I thought it looked all right, but it doesn't work, because apparently the comment is always handled as if it's unflagged, even when it's stored in the database as flagged with 'First comment'!

This is the Rules evalution log:

0 ms Reacting on event After deleting a comment.
11.674 ms Evaluating conditions of rule Reaction removed. [edit]
15.543 ms The condition user_has_role evaluated to FALSE [edit]
28.531 ms The condition flag_flagged_comment evaluated to FALSE [edit]  <--- going wrong here
28.547 ms AND evaluated to FALSE.
28.575 ms Finished reacting on event After deleting a comment

What went wrong and how can I solve it?

6
  • My guess is this is an order of events issue. I suspect Flag is getting in ahead of your code and removing its DB entry for the comment. Can you hook in earlier? Oct 24, 2013 at 10:45
  • @Alfred Armstrong: I don't know. What am I supposed to do? How can I do that?
    – Jeroen
    Oct 24, 2013 at 13:26
  • If there's a "before deleting a comment event", try using that instead as a first step. As long as no modules prevent the deletion it should work. Other solutions are likely to be more technical. Oct 24, 2013 at 13:37
  • @Alfred Armstrong: I was actually looking for a "before deleting a comment" event too, but there isn't such option - unless I've overlooked it...
    – Jeroen
    Oct 24, 2013 at 14:12
  • In that case you might have to try changing module weights so Flag runs after Rules. No guarantee it will work but worth a try. drupal.org/project/modules_weight Oct 24, 2013 at 14:20

1 Answer 1

2

The problem arises because the Flag module runs before Rules, so it has already removed the flag before Rules performs its test. One way to deal with this is to install Modules Weight which will allow you to adjust the relative priorities of modules so Flag runs after Rules.

3
  • Do you know a solution without the need to install 'Modules Weight' too?
    – Jeroen
    Feb 20, 2014 at 14:42
  • You can directly edit weights in the database, but Modules Weight is the easiest way. Once you have altered the weights you can uninstall it, if you are concerned about how many modules your site requires. Feb 20, 2014 at 15:24
  • O, that's very handy to know! That's exactly the reason why I asked you this. :) Let me give you an extra vote up.
    – Jeroen
    Feb 20, 2014 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.