function rules_action_invoke_set in Rules 6
Base action implementation for invoking all rule sets.
We could just call rules_invoke_rule_set(), but then the changed variables would be saved immediately. Instead we create a new evaluation state, mapping to existing variables, so the outer state takes care of saving changes for those variables.
Related topics
1 string reference to 'rules_action_invoke_set'
- rules_rules_action_info in rules/
modules/ rules.rules.inc - Implementation of hook_rules_action_info().
File
- rules/
modules/ rules.rules.inc, line 269 - rules integration for the rules module
Code
function rules_action_invoke_set() {
$args = func_get_args();
$state = array_pop($args);
$element = array_pop($args);
$settings = array_pop($args);
$set_name = $element['#info']['set'];
$set = rules_get_rule_set($set_name);
if (!$set) {
rules_log(t("The configured rule set %set doesn't exist any more.", array(
'%set' => $set_name,
)), TRUE);
return;
}
// We create a new evaluation state, that maps the variables to the outer
// state whenever possible. If necessary, we initialize new variables. So
// we have to care for saving the changes of the new variables only.
$new_state = array(
'set_info' => $set['info'],
'variables' => array(),
);
$mapped_vars = array();
$map = rules_get_mapped_argument_names($element);
$set['info'] += array(
'arguments' => array(),
);
foreach (array_keys($set['info']['arguments']) as $i => $name) {
if (isset($map[$name]) && isset($state['variables'][$map[$name]])) {
$new_state['variables'][$name] =& $state['variables'][$map[$name]];
$mapped_vars[] = $name;
}
else {
$variable = new rules_variable();
$variable
->construct($new_state, $name, $args[$i]);
}
}
// Evaluate, but don't save mapped variables.
rules_evaluate_rule_set($set_name, $set, $new_state, $mapped_vars);
}