You are here

function features_detect_overrides in Features 7

Same name and namespace in other branches
  1. 6 features.export.inc \features_detect_overrides()
  2. 7.2 features.export.inc \features_detect_overrides()

Detect differences between DB and code components of a feature.

2 calls to features_detect_overrides()
drush_features_diff in ./features.drush.inc
Show the diff of a feature module.
features_feature_diff in ./features.admin.inc
Page callback to display the differences between what's in code and what is in the db.

File

./features.export.inc, line 315

Code

function features_detect_overrides($module) {
  static $cache;
  if (!isset($cache)) {
    $cache = array();
  }
  if (!isset($cache[$module->name])) {

    // Rebuild feature from .info file description and prepare an export from current DB state.
    $export = features_populate($module->info['features'], $module->info['dependencies'], $module->name);
    $export = features_export_prepare($export, $module->name);
    $overridden = array();

    // Compare feature info
    _features_sanitize($module->info);
    _features_sanitize($export);
    $compare = array(
      'normal' => features_export_info($export),
      'default' => features_export_info($module->info),
    );
    if ($compare['normal'] !== $compare['default']) {
      $overridden['info'] = $compare;
    }

    // Collect differences at a per-component level
    $states = features_get_component_states(array(
      $module->name,
    ), FALSE);
    foreach ($states[$module->name] as $component => $state) {
      if ($state != FEATURES_DEFAULT) {
        $normal = features_get_normal($component, $module->name);
        $default = features_get_default($component, $module->name);
        _features_sanitize($normal);
        _features_sanitize($default);
        $compare = array(
          'normal' => features_var_export($normal),
          'default' => features_var_export($default),
        );
        if (_features_linetrim($compare['normal']) !== _features_linetrim($compare['default'])) {
          $overridden[$component] = $compare;
        }
      }
    }
    $cache[$module->name] = $overridden;
  }
  return $cache[$module->name];
}