You are here

function features_get_orphans in Features 6

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

Generate an array of feature dependencies that have been orphaned.

1 call to features_get_orphans()
features_cleanup_form in ./features.admin.inc
Form for disabling orphaned dependencies.

File

./features.module, line 514
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_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]->info['dependents'])) {

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