You are here

function _features_restore in Features 7

Same name and namespace in other branches
  1. 6 features.module \_features_restore()
  2. 7.2 features.module \_features_restore()

Restore the specified modules to the default state.

4 calls to _features_restore()
features_modules_disabled in ./features.module
Implements hook_modules_disabled().
features_modules_enabled in ./features.module
Implements hook_modules_enabled().
features_rebuild in ./features.module
Wrapper around _features_restore().
features_revert in ./features.module
Wrapper around _features_restore().

File

./features.module, line 831
Module file for the features module, which enables the capture and management of features in Drupal. A feature is a collection of Drupal entities which taken together statisfy a certain use-case.

Code

function _features_restore($op, $items = array()) {
  module_load_include('inc', 'features', 'features.export');
  features_include();
  switch ($op) {
    case 'revert':
      $restore_states = array(
        FEATURES_OVERRIDDEN,
        FEATURES_REBUILDABLE,
        FEATURES_NEEDS_REVIEW,
      );
      $restore_hook = 'features_revert';
      $log_action = 'Revert';
      break;
    case 'rebuild':
      $restore_states = array(
        FEATURES_REBUILDABLE,
      );
      $restore_hook = 'features_rebuild';
      $log_action = 'Rebuild';
      break;
    case 'disable':
      $restore_hook = 'features_disable_feature';
      $log_action = 'Disable';
      break;
    case 'enable':
      $restore_hook = 'features_enable_feature';
      $log_action = 'Enable';
      break;
  }
  if (empty($items)) {

    // Drush may execute a whole chain of commands that may trigger feature
    // rebuilding multiple times during a single request. Make sure we do not
    // rebuild the same cached list of modules over and over again by setting
    // $reset to TRUE.
    // Note: this may happen whenever more than one feature will be enabled
    // in chain, for example also using features_install_modules().
    $states = features_get_component_states(array(), $op == 'rebuild', defined('DRUSH_BASE_PATH'));
    foreach ($states as $module_name => $components) {
      foreach ($components as $component => $state) {
        if (in_array($state, $restore_states)) {
          $items[$module_name][] = $component;
        }
      }
    }
  }
  foreach ($items as $module_name => $components) {
    foreach ($components as $component) {
      if (features_hook($component, $restore_hook)) {

        // Set a semaphore to prevent other instances of the same script from running concurrently.
        watchdog('features', '@actioning @module_name / @component.', array(
          '@action' => $log_action,
          '@component' => $component,
          '@module_name' => $module_name,
        ));
        features_semaphore('set', $component);
        features_invoke($component, $restore_hook, $module_name);

        // If the script completes, remove the semaphore and set the code signature.
        features_semaphore('del', $component);
        features_set_signature($module_name, $component);
        watchdog('features', '@action completed for @module_name / @component.', array(
          '@action' => $log_action,
          '@component' => $component,
          '@module_name' => $module_name,
        ));
      }
    }
  }
}