function rules_get_rule_set in Rules 6
Returns the rule set $set_name, which includes the set info and the rules. To improve performance rule sets are cached.
Parameters
$set_name The name of the set which should be returned.:
$reset May be set to true to clear the static $sets cache.:
Return value
Returns the set only containing active rules, ready for evaluation
4 calls to rules_get_rule_set()
- rules_action_invoke_set in rules/
modules/ rules.rules.inc - Base action implementation for invoking all rule sets.
- rules_admin_rule_proxy::get_set in rules_admin/
rules_admin.rule_proxy.inc - Gets the set of this rule, which contains only active rules.
- rules_clear_cache in rules/
rules.module - Clears the rule set cache
- rules_invoke_rule_set in rules/
rules.module - Invokes configured rules for the given rule set
File
- rules/
rules.module, line 149 - Rules engine module
Code
function rules_get_rule_set($set_name, $reset = FALSE) {
//We prevent a lot of queries by storing all sets with active rules with variable_set
static $sets;
if (!isset($sets) || $reset) {
$sets = array();
_rules_get_rule_set_initialize($sets);
}
if (isset($set_name) && !isset($sets[$set_name])) {
if (!$reset && ($cache = cache_get('set_' . $set_name, 'cache_rules'))) {
$sets[$set_name] = $cache->data;
}
else {
// Cache miss, so refresh the cache for all sets
$sets = _rules_get_rule_sets();
foreach ($sets as $name => $set) {
// Make sure the rules are sorted before writing to the cache.
rules_sort_children($set['rules']);
cache_set('set_' . $name, $set, 'cache_rules');
}
// Get all inactive sets and store them to speed up later calls.
$inactive_sets = array_diff(array_keys(rules_get_rule_sets()), array_keys($sets));
// If the inactive sets have changed, update the variable.
if ($inactive_sets != variable_get('rules_inactive_sets', array())) {
variable_set('rules_inactive_sets', $inactive_sets);
}
_rules_get_rule_set_initialize($sets);
}
}
return isset($set_name) && isset($sets[$set_name]) ? $sets[$set_name] : array();
}