You are here

function _features_restore in Features 6

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

Restore the specified modules to the default state.

2 calls to _features_restore()
features_rebuild in ./features.module
Wrapper around _features_restore().
features_revert in ./features.module
Wrapper around _features_restore().

File

./features.module, line 669
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()) {

  // Since we can't ensure that users will run update.php immediately after
  // updating the features codebase, we must check the schema version explicitly
  // to ensure that we will not blow away any overrides.
  module_load_install('features');
  if (drupal_get_installed_schema_version('features', TRUE) < 6101) {
    return;
  }
  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;
  }
  if (empty($items)) {
    $states = features_get_component_states();
    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,
        ));
      }
    }
  }
}