You are here

function configuration_get_component_states in Configuration Management 7

Retrieve an array of configuration/components and their current states.

2 calls to configuration_get_component_states()
configuration_get_storage in ./configuration.export.inc
Get a summary storage state for a feature.
_configuration_restore in ./configuration.module
Restore the specified modules to the default state.

File

./configuration.export.inc, line 635

Code

function configuration_get_component_states($configuration = array(), $rebuild_only = TRUE, $reset = FALSE) {
  static $cache;
  if (!isset($cache) || $reset) {
    $cache = array();
  }
  $configuration = !empty($configuration) ? $configuration : array_keys(configuration_get_configuration());

  // Retrieve only rebuildable components if requested.
  configuration_include();
  $components = array_keys(configuration_get_components());
  if ($rebuild_only) {
    foreach ($components as $k => $component) {
      if (!configuration_hook($component, 'configuration_rebuild')) {
        unset($components[$k]);
      }
    }
  }
  foreach ($configuration as $feature) {
    $cache[$feature] = isset($cache[$feature]) ? $cache[$feature] : array();
    if (module_exists($feature)) {
      foreach ($components as $component) {
        if (!isset($cache[$feature][$component])) {
          $normal = configuration_get_signature('normal', $feature, $component, $reset);
          $default = configuration_get_signature('default', $feature, $component, $reset);
          $codecache = configuration_get_signature('cache', $feature, $component, $reset);
          $semaphore = configuration_semaphore('get', $component);

          // DB and code states match, there is nothing more to check.
          if ($normal == $default) {
            $cache[$feature][$component] = CONFIGURATION_DEFAULT;

            // Stale semaphores can be deleted.
            configuration_semaphore('del', $component);

            // Update code cache if it is stale, clear out semaphore if it stale.
            if ($default != $codecache) {
              configuration_set_signature($feature, $component, $default);
            }
          }
          elseif (!configuration_hook($component, 'configuration_rebuild')) {
            $cache[$feature][$component] = CONFIGURATION_OVERRIDDEN;
          }
          else {
            if (empty($semaphore)) {

              // Exception for dependencies. Dependencies are always rebuildable.
              if ($component === 'dependencies') {
                $cache[$feature][$component] = CONFIGURATION_REBUILDABLE;
              }
              else {

                // Code has not changed, but DB does not match. User has DB overrides.
                if ($codecache == $default) {
                  $cache[$feature][$component] = CONFIGURATION_OVERRIDDEN;
                }
                elseif ($codecache == $normal || empty($codecache)) {
                  $cache[$feature][$component] = CONFIGURATION_REBUILDABLE;
                }
                elseif ($codecache != $default) {
                  $cache[$feature][$component] = CONFIGURATION_NEEDS_REVIEW;
                }
              }
            }
            else {

              // Semaphore is still within processing horizon. Do nothing.
              if (REQUEST_TIME - $semaphore < CONFIGURATION_SEMAPHORE_TIMEOUT) {
                $cache[$feature][$component] = CONFIGURATION_REBUILDING;
              }
              else {
                $cache[$feature][$component] = CONFIGURATION_REBUILDABLE;
              }
            }
          }
        }
      }
    }
  }

  // Filter cached components on the way out to ensure that even if we have
  // cached more data than has been requested, the return value only reflects
  // the requested configuration/components.
  $return = $cache;
  $return = array_intersect_key($return, array_flip($configuration));
  foreach ($return as $k => $v) {
    $return[$k] = array_intersect_key($return[$k], array_flip($components));
  }
  return $return;
}