You are here

function features_get_orphans in Features 7.2

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

Generate an array of feature dependencies that have been orphaned.

File

./features.module, line 933
Main *.module file for the 'features' module.

Code

function features_get_orphans($reset = FALSE) {
  static $orphans;
  if (!isset($orphans) || $reset) {
    module_load_include('inc', 'features', 'features.export');
    $orphans = array();

    // Build a list of all dependencies for enabled and disabled features.
    $dependencies = array(
      'enabled' => array(),
      'disabled' => array(),
    );
    $features = features_get_features();
    foreach ($features as $feature) {
      $key = module_exists($feature->name) ? 'enabled' : 'disabled';
      if (!empty($feature->info['dependencies'])) {
        $dependencies[$key] = array_merge($dependencies[$key], _features_export_maximize_dependencies($feature->info['dependencies']));
      }
    }
    $dependencies['enabled'] = array_unique($dependencies['enabled']);
    $dependencies['disabled'] = array_unique($dependencies['disabled']);

    // Find the list of orphaned modules.
    $orphaned = array_diff($dependencies['disabled'], $dependencies['enabled']);
    $orphaned = array_intersect($orphaned, module_list(FALSE, FALSE));
    $orphaned = array_diff($orphaned, drupal_required_modules());
    $orphaned = array_diff($orphaned, array(
      'features',
    ));

    // Build final list of modules that can be disabled.
    $modules = features_get_modules(NULL, TRUE);
    $enabled = module_list();
    _module_build_dependencies($modules);
    foreach ($orphaned as $module) {
      if (!empty($modules[$module]->required_by)) {
        foreach ($modules[$module]->required_by as $module_name => $dependency) {
          $modules[$module]->required_by[$module_name] = $dependency['name'];
        }

        // Determine whether any dependents are actually enabled.
        $dependents = array_intersect($modules[$module]->required_by, $enabled);
        if (empty($dependents)) {
          $info = features_get_modules($module);
          $orphans[$module] = $info;
        }
      }
    }
  }
  return $orphans;
}