diff -u b/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php --- b/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -373,15 +373,11 @@ // Work out what modules to install and uninstall. $uninstall = array_diff(array_keys($current_extensions['module']), array_keys($new_extensions['module'])); $install = array_diff(array_keys($new_extensions['module']), array_keys($current_extensions['module'])); - // Sort the module list by their weights. So that dependencies are - // uninstalled last. Modules of the same weight are sorted in reverse - // alphabetical order. - array_multisort(array_values($module_list), SORT_ASC, array_keys($module_list), SORT_DESC, $module_list); + + $module_list = $this->sortModulesForUninstall($module_list); $uninstall = array_intersect(array_keys($module_list), $uninstall); - // Sort the module list by their weights (reverse). So that dependencies - // are installed first. Modules of the same weight are sorted in - // alphabetical order. - array_multisort(array_values($module_list), SORT_DESC, array_keys($module_list), SORT_ASC, $module_list); + + $module_list = $this->sortModulesForInstall($module_list); $install = array_intersect(array_keys($module_list), $install); // Work out what themes to enable and to disable. @@ -401,6 +397,70 @@ } /** + * Sorts the module list in a consistent order for installation. + * + * Sort the module list by their weights (reverse). So that dependencies + * are uninstalled last. Modules of the same weight are sorted in reverse + * alphabetical order. The use of array_multisort() is to ensure a + * consistent order when module weights are equal. For example an array like + * + * array( + * 'actions' => 0, + * 'ban' => 0, + * 'options' => -2, + * 'text' => -1, + * ); + * + * will result in the following sort order: + * 0 options + * 1 text + * 2 0 ban + * 2 1 actions + * + * @param array $module_list + * The list of modules keyed by name with a value of weight. + * + * @return array + * The list of modules sorted by weight then name. + */ + protected function sortModulesForUninstall($module_list) { + array_multisort(array_values($module_list), SORT_ASC, array_keys($module_list), SORT_DESC, $module_list); + return $module_list; + } + + /** + * Sorts the module list in a consistent order for installation. + * + * Sort the module list by their weights (reverse). So that dependencies + * are installed first. Modules of the same weight are sorted in + * alphabetical order. The use of array_multisort() is to ensure a + * consistent order when module weights are equal. For example an array like + * + * array( + * 'actions' => 0, + * 'ban' => 0, + * 'options' => -2, + * 'text' => -1, + * ); + * + * will result in the following sort order: + * 0 0 actions + * 0 1 ban + * 1 text + * 2 options + * + * @param array $module_list + * The list of modules keyed by name with a value of weight. + * + * @return array + * The list of modules sorted by weight then name. + */ + protected function sortModulesForInstall($module_list) { + array_multisort(array_values($module_list), SORT_DESC, array_keys($module_list), SORT_ASC, $module_list); + return $module_list; + } + + /** * Gets a list changes for extensions. * * @param string $type