function RulesPlugin::save

Saves the configuration to the database.

The configuration is saved regardless whether this method is invoked on the rules configuration or a contained rule element.

1 method overrides RulesPlugin::save()
RulesEventSet::save in includes/rules.plugins.inc
Do not save since this class is for caching purposes only.

File

includes/rules.core.inc, line 1117

Class

RulesPlugin
Base class for rules plugins.

Code

public function save($name = NULL, $module = 'rules') {
    if (isset($this->parent)) {
        $this->parent
            ->sortChildren();
        return $this->parent
            ->save($name, $module);
    }
    else {
        // Update the dirty flag before saving.
        // However, this operation depends on a fully built Rules-cache, so skip
        // it when entities in code are imported to the database.
        // @see _rules_rebuild_cache()
        if (empty($this->is_rebuild)) {
            rules_config_update_dirty_flag($this, FALSE);
            // In case the config is not dirty, pre-calculate the dependencies for
            // later checking. Note that this also triggers processing settings if
            // necessary.
            // @see rules_modules_enabled()
            if (empty($this->dirty)) {
                $this->dependencies = $this->dependencies();
            }
        }
        $this->plugin = $this->itemName;
        $this->name = isset($name) ? $name : $this->name;
        // Module stores the module via which the rule is configured and is used
        // for generating machine names with the right prefix. However, for
        // default configurations 'module' points to the module providing the
        // default configuration, so the module via which the rules is configured
        // is stored in the "owner" property.
        // @todo For Drupal 8 use "owner" for generating machine names also and
        // module only for the modules providing default configurations.
        $this->module = !isset($this->module) || $module != 'rules' ? $module : $this->module;
        if (!isset($this->owner)) {
            $this->owner = 'rules';
        }
        $this->ensureNameExists();
        $this->data = $this;
        $return = entity_get_controller('rules_config')->save($this);
        unset($this->data);
        // Care about clearing necessary caches.
        if (!empty($this->is_rebuild)) {
            rules_clear_cache();
        }
        else {
            $plugin_info = $this->pluginInfo();
            if (!empty($plugin_info['component'])) {
                // When component variables changes rebuild the complete cache so the
                // changes to the provided action/condition take affect.
                if (empty($this->original) || $this->componentVariables() != $this->original
                    ->componentVariables()) {
                    rules_clear_cache();
                }
                // Clear components cached for evaluation.
                cache_clear_all('comp_', 'cache_rules', TRUE);
            }
            elseif ($this->plugin == 'reaction rule') {
                // Clear event sets cached for evaluation.
                cache_clear_all('event_', 'cache_rules', TRUE);
                // Clear event whitelist for rebuild.
                cache_clear_all('rules_event_whitelist', 'cache_rules', TRUE);
            }
            drupal_static_reset('rules_get_cache');
            drupal_static_reset('rules_config_update_dirty_flag');
        }
        return $return;
    }
}