You are here

function drush_features_revert in Features 6

Same name and namespace in other branches
  1. 7.2 features.drush.inc \drush_features_revert()
  2. 7 features.drush.inc \drush_features_revert()

Revert a feature to it's code definition.

File

./features.drush.inc, line 456
Features module drush integration.

Code

function drush_features_revert() {
  if ($args = func_get_args()) {
    module_load_include('inc', 'features', 'features.export');
    features_include();

    // Determine if revert should be forced.
    $force = drush_get_option('force');
    foreach ($args as $module) {
      if (($feature = feature_load($module, TRUE)) && module_exists($module)) {
        $components = array();

        // Forcefully revert all components of a feature.
        if ($force) {
          foreach (array_keys($feature->info['features']) as $component) {
            if (features_hook($component, 'features_revert')) {
              $components[] = $component;
            }
          }
        }
        else {
          $states = features_get_component_states(array(
            $feature->name,
          ), FALSE);
          foreach ($states[$feature->name] as $component => $state) {
            if (in_array($state, array(
              FEATURES_OVERRIDDEN,
              FEATURES_NEEDS_REVIEW,
              FEATURES_REBUILDABLE,
            )) && features_hook($component, 'features_revert')) {
              $components[] = $component;
            }
          }
        }
        if (empty($components)) {
          drush_log(dt('Current state already matches defaults, aborting.'), 'ok');
        }
        else {
          foreach ($components as $component) {
            if (drush_confirm(dt('Do you really want to revert !component?', array(
              '!component' => $component,
            )))) {
              features_revert(array(
                $module => array(
                  $component,
                ),
              ));
              drush_log(dt('Reverted !component.', array(
                '!component' => $component,
              )), 'ok');
            }
            else {
              drush_log(dt('Skipping !component.', array(
                '!component' => $component,
              )), 'ok');
            }
          }
        }
      }
      else {
        if ($feature) {
          _features_drush_set_error($module, 'FEATURES_FEATURE_NOT_ENABLED');
        }
        else {
          _features_drush_set_error($module);
        }
      }
    }
  }
  else {
    drush_features_list();
    return;
  }
}