1

There are many situations in which a rule could trigger another rule. For example, If I have a rule that reacts to a Node being created, I can trigger that rule with another rule that created a node. The same should hold true for flagging nodes, but I have seen cases in which it does not. I have written 'single flag enforcement' rules that are triggered by a node being flagged, which un-flag all nodes flagged by that user, then re-flag only the triggering node. This rule should trigger itself over and over infinitely, but it does not. How does Drupal's Rules handle these situation? Is there a way to force rules to allow or disallow this form of cascading rule triggering (and potentially cause/prevent an infinite loop?)

1 Answer 1

1

It will not trigger recursively, Rules has inbuilt mechanism to prevent this. if you check the function rules_element_invoke_component you can see this.

function rules_element_invoke_component($arguments, RulesPlugin $element) {
  ....
  // Handle recursion prevention.
  if ($state->isBlocked($component)) {
     return rules_log('Not evaluating @plugin %label to prevent recursion.',  $replacements, RulesLog::INFO, $component);
  }
  $state->block($component);
  ....
}
6
  • Is that to say that a rule will not trigger itself, but it can trigger a different rule if the actions match triggers?
    – Hoytman
    Jun 12, 2014 at 17:49
  • Yes, if you check the rules.state.inc file you can see static protected $blocked = array(); where they are storing the rule id.
    – msmani
    Jun 12, 2014 at 19:06
  • It looks like a rule can be called multiple times on a single page load, but not as a 'child process' of the same rule.
    – Hoytman
    Jun 13, 2014 at 12:26
  • I don't think so, can you explain a scenario.
    – msmani
    Jun 13, 2014 at 13:05
  • 1
    Yeah, as you said a rule cannot be called as a child process. But as per VBO, assume that we have a rule that triggers when a user is updated and we are performing bulk user update. Even though this is a bulk operation for us internally it is only loop. And after each updation if a rule is not triggering any other rule then it will unblock $state->unblock($component);, so it will trigger for the next update also.
    – msmani
    Jun 13, 2014 at 13:31

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.