You are here

function drush_features_revert_all in Features 7.2

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

Drush command callback for 'features-revert-all'.

Reverts all enabled features to their definitions in code.

Parameters

...: (Optional) A list of features to exclude from being reverted.

Return value

void|false FALSE on failure, no explicit return value otherwise.

File

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

Code

function drush_features_revert_all() {
  module_load_include('inc', 'features', 'features.export');
  $force = drush_get_option('force');
  $features_to_exclude = func_get_args();
  $features_to_revert = array();
  foreach (features_get_features(NULL, TRUE) as $module) {
    if ($module->status && !in_array($module->name, $features_to_exclude)) {

      // If forced, add the module regardless of its status.
      if ($force) {
        $features_to_revert[] = $module->name;
      }
      else {
        switch (features_get_storage($module->name)) {
          case FEATURES_OVERRIDDEN:
          case FEATURES_NEEDS_REVIEW:
          case FEATURES_REBUILDABLE:
            $features_to_revert[] = $module->name;
            break;
        }
      }
    }
  }
  if ($features_to_revert) {
    $dt_args = array(
      '!modules' => implode(', ', $features_to_revert),
    );
    drush_print(dt('The following modules will be reverted: !modules', $dt_args));

    // Confirm that the user would like to continue. If not, simply abort.
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort('Aborting.');
    }
    drush_invoke('features-revert', $features_to_revert);
  }
  else {
    drush_log(dt('Current state already matches defaults, aborting.'), 'ok');
  }
}