function drush_rules_revert

Reverts a rule on the site.

File

./rules.drush.inc, line 185

Code

function drush_rules_revert() {
    $args = func_get_args();
    $rule_name = !empty($args) && is_array($args) ? array_shift($args) : '';
    if (empty($rule_name)) {
        return drush_set_error('', 'No rule name given.');
    }
    $rule = rules_config_load($rule_name);
    if (empty($rule)) {
        return drush_set_error('', dt('Could not load rule named "!rule-name".', array(
            '!rule-name' => $rule_name,
        )));
    }
    if (($rule->status & ENTITY_OVERRIDDEN) == ENTITY_OVERRIDDEN) {
        if (drush_confirm(dt('Are you sure you want to revert the rule named "!rule-name"? This action cannot be undone.', array(
            '!rule-name' => $rule_name,
        )))) {
            $rule->delete();
            drush_log(dt('The rule "!name" has been reverted to its default state.', array(
                '!name' => $rule_name,
            )), 'success');
        }
        else {
            drush_user_abort();
        }
    }
    else {
        drush_log(dt('The rule "!name" has not been overridden and can\'t be reverted.', array(
            '!name' => $rule_name,
        )), 'warning');
    }
}