function update_resolve_dependencies

Resolves dependencies in a set of module updates, and orders them correctly.

This function receives a list of requested module updates and determines an appropriate order to run them in such that all update dependencies are met. Any updates whose dependencies cannot be met are included in the returned array but have the key 'allowed' set to FALSE; the calling function should take responsibility for ensuring that these updates are ultimately not performed.

In addition, the returned array also includes detailed information about the dependency chain for each update, as provided by the depth-first search algorithm in Drupal\Component\Graph\Graph::searchAndSort().

Parameters

$starting_updates: An array whose keys contain the names of modules with updates to be run and whose values contain the number of the first requested update for that module.

Return value

An array whose keys are the names of all update functions within the provided modules that would need to be run in order to fulfill the request, arranged in the order in which the update functions should be run. (This includes the provided starting update for each module and all subsequent updates that are available.) The values are themselves arrays containing all the keys provided by the Drupal\Component\Graph\Graph::searchAndSort() algorithm, which encode detailed information about the dependency chain for this update function (for example: 'paths', 'reverse_paths', 'weight', and 'component'), as well as the following additional keys:

  • 'allowed': A boolean which is TRUE when the update function's dependencies are met, and FALSE otherwise. Calling functions should inspect this value before running the update.
  • 'missing_dependencies': An array containing the names of any other update functions that are required by this one but that are unavailable to be run. This array will be empty when 'allowed' is TRUE.
  • 'module': The name of the module that this update function belongs to.
  • 'number': The number of this update function within that module.

See also

Drupal\Component\Graph\Graph::searchAndSort()

5 calls to update_resolve_dependencies()
DependencyMissingTest::testMissingUpdate in drupal/core/modules/system/lib/Drupal/system/Tests/Update/DependencyMissingTest.php
DependencyOrderingTest::testUpdateOrderingModuleInterdependency in drupal/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php
Test that dependencies between modules are resolved correctly.
DependencyOrderingTest::testUpdateOrderingSingleModule in drupal/core/modules/system/lib/Drupal/system/Tests/Update/DependencyOrderingTest.php
Test that updates within a single module run in the correct order.
update_batch in drupal/core/includes/update.inc
Starts the database update batch process.
update_script_selection_form in drupal/core/update.php
Form constructor for the list of available database module updates.

File

drupal/core/includes/update.inc, line 1016
Drupal database update API.

Code

function update_resolve_dependencies($starting_updates) {

  // Obtain a dependency graph for the requested update functions.
  $update_functions = update_get_update_function_list($starting_updates);
  $graph = update_build_dependency_graph($update_functions);

  // Perform the depth-first search and sort on the results.
  $graph_object = new Graph($graph);
  $graph = $graph_object
    ->searchAndSort();
  uasort($graph, 'drupal_sort_weight');
  foreach ($graph as $function => &$data) {
    $module = $data['module'];
    $number = $data['number'];

    // If the update function is missing and has not yet been performed, mark
    // it and everything that ultimately depends on it as disallowed.
    if (update_is_missing($module, $number, $update_functions) && !update_already_performed($module, $number)) {
      $data['allowed'] = FALSE;
      foreach (array_keys($data['paths']) as $dependent) {
        $graph[$dependent]['allowed'] = FALSE;
        $graph[$dependent]['missing_dependencies'][] = $function;
      }
    }
    elseif (!isset($data['allowed'])) {
      $data['allowed'] = TRUE;
      $data['missing_dependencies'] = array();
    }

    // Now that we have finished processing this function, remove it from the
    // graph if it was not part of the original list. This ensures that we
    // never try to run any updates that were not specifically requested.
    if (!isset($update_functions[$module][$number])) {
      unset($graph[$function]);
    }
  }
  return $graph;
}