mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
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:
committed by
GitHub
parent
245d0d2550
commit
1637b90531
@@ -421,7 +421,7 @@ class ExtensionManager
|
|||||||
* Sort a list of extensions so that they are properly resolved in respect to order.
|
* Sort a list of extensions so that they are properly resolved in respect to order.
|
||||||
* Effectively just topological sorting.
|
* 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
|
* @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
|
* 'missingDependencies' points to an associative array of extensions that could not be resolved due
|
||||||
@@ -443,6 +443,12 @@ class ExtensionManager
|
|||||||
$pendingQueue = [];
|
$pendingQueue = [];
|
||||||
$inDegreeCount = []; // How many extensions are dependent on a given extension?
|
$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) {
|
foreach ($extensionList as $extension) {
|
||||||
$extensionIdMapping[$extension->getId()] = $extension;
|
$extensionIdMapping[$extension->getId()] = $extension;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user