function rules_upgrade_plugin_factory

Creates the right element.

3 calls to rules_upgrade_plugin_factory()
rules_upgrade_convert_element in includes/rules.upgrade.inc
Convert a single element.
rules_upgrade_convert_rule in includes/rules.upgrade.inc
Converts a single reaction rule.
rules_upgrade_convert_rule_set in includes/rules.upgrade.inc
Converts a single rule set, including all of its rules.

File

includes/rules.upgrade.inc, line 297

Code

function rules_upgrade_plugin_factory($element) {
    if ($element['#type'] == 'rule' && !empty($element['#set']) && strpos($element['#set'], 'event_') === 0) {
        return rules_plugin_factory('reaction rule');
    }
    switch ($element['#type']) {
        case 'OR':
            return rules_plugin_factory('or');
        case 'AND':
            return rules_plugin_factory('and');
        default:
            return rules_plugin_factory($element['#type']);
        case 'action':
        case 'condition':
            if (isset($element['#name'])) {
                // Try to come up with the right action/condition name ourself, then
                // invoke a hook.
                $cache = rules_get_cache();
                $items = $cache[$element['#type'] == 'action' ? 'action_info' : 'condition_info'];
                if (isset($items[$element['#name']])) {
                    $element_name = $element['#name'];
                }
                elseif (($name = str_replace('rules_', '', $element['#name'])) && isset($items[$name])) {
                    $element_name = $name;
                }
                elseif (($name = str_replace($element['#type'] . '_', '', $element['#name'])) && isset($items[$name])) {
                    $element_name = $name;
                }
                elseif (($name = str_replace('rules_' . $element['#type'] . '_', '', $element['#name'])) && isset($items[$name])) {
                    $element_name = $name;
                }
                elseif (isset($element['#info']['base']) && isset($items[$element['#info']['base']])) {
                    $element_name = $name;
                }
                // Call the upgrade callback if one has been defined.
                if (function_exists($function = $element['#name'] . '_upgrade_map_name') || isset($element['#info']['base']) && function_exists($function = $element['#info']['base'] . '_upgrade_map_name')) {
                    $element_name = $function($element);
                }
                if (!isset($element_name)) {
                    throw new RulesIntegrityException(t("Cannot find @plugin %name. Maybe a required is missing or the module has not implemented the upgrade functionality.", array(
                        '@plugin' => $element['#type'],
                        '%name' => $element['#name'],
                    )));
                }
                return rules_plugin_factory($element['#type'], $element_name);
            }
            break;
    }
}