Add determinsm to extension order resolution (#3076)

By sorting alphabetically by extension ID before applying topological sort, we ensure that a given set of extensions will always be booted in the same order. This will make it easier to replicate issues caused by complex extension dependencies.
This commit is contained in:
Alexander Skvortsov 2021-09-20 11:40:00 -04:00 committed by GitHub
parent 0090f97f9a
commit acaa23d2a5

View File

@ -421,7 +421,7 @@ class ExtensionManager
* Sort a list of extensions so that they are properly resolved in respect to order.
* Effectively just topological sorting.
*
* @param Extension[] $extensionList: an array of \Flarum\Extension\Extension objects
* @param Extension[] $extensionList
*
* @return array with 2 keys: 'valid' points to an ordered array of \Flarum\Extension\Extension
* 'missingDependencies' points to an associative array of extensions that could not be resolved due
@ -443,6 +443,12 @@ class ExtensionManager
$pendingQueue = [];
$inDegreeCount = []; // How many extensions are dependent on a given extension?
// Sort alphabetically by ID. This guarantees that any set of extensions will always be sorted the same way.
// This makes boot order deterministic, and independent of enabled order.
$extensionList = Arr::sort($extensionList, function ($ext) {
return $ext->getId();
});
foreach ($extensionList as $extension) {
$extensionIdMapping[$extension->getId()] = $extension;
}