function rules_import_workflow_ng_rule in Rules 6
Transform a workflow-ng rule into a rule
2 calls to rules_import_workflow_ng_rule()
- rules_admin_import_workflow_ng in rules_admin/
rules_admin.export.inc - Tries to import workflow-ng rules.
- rules_update_6001 in rules/
rules.install - Upgrade from workflow-ng
File
- rules/
rules.install, line 181 - Rules - Installation file.
Code
function rules_import_workflow_ng_rule(&$name, $cfg) {
drupal_load('module', 'rules');
$rule = array(
'#type' => 'rule',
);
$name = _rules_import_replace_module_name($name);
foreach (array(
'#altered',
'#active',
'#weight',
) as $key) {
if (isset($cfg[$key])) {
$rule[$key] = $cfg[$key];
}
}
$rule['#categories'] = array(
'imported',
);
$rule['#label'] = _rules_import_replace_module_name($cfg['#label']);
$rule['#set'] = _rules_import_get_set($cfg);
if (isset($cfg['#fixed']) && $cfg['#fixed']) {
$rule['#status'] = 'fixed';
}
else {
if ($cfg['#module'] == 'workflow-ng') {
$rule['#status'] = 'custom';
$name = _rules_admin_rule_get_new_unique_name();
}
else {
$rule['#status'] = 'default';
}
}
$rule += array(
'#actions' => array(),
'#conditions' => array(),
);
// Separate actions and conditions.
foreach (element_children($cfg) as $key) {
if (isset($cfg[$key]['#type']) && $cfg[$key]['#type'] == 'action') {
$rule['#actions'][$key] = $cfg[$key];
}
else {
$rule['#conditions'][$key] = $cfg[$key];
}
}
// Transform elements to be compatible with workflow-ng
$success = rules_helper_do_recursive('_rules_import_transform_element', $rule['#actions']);
if ($success) {
$success = rules_helper_do_recursive('_rules_import_transform_element', $rule['#conditions']);
}
if ($success) {
rules_sort_elements($rule['#actions']);
rules_sort_elements($rule['#conditions']);
}
return $success ? $rule : FALSE;
}