Skip to content

Commit

Permalink
fix: dont ignore optional dependencies on disabled extensions.
Browse files Browse the repository at this point in the history
There is a check in the ExtensionManager::resolveExtensionOrder function that ignores optional dependencies on extensions that don't exist in the system. This is sufficient for resolution purposes.

The filter removed in this PR would ignore optional dependencies on non-enabled extensions, so when such an extension was enabled, dependency resolution would run incorrectly.
  • Loading branch information
askvortsov1 committed Mar 25, 2022
1 parent b64003c commit eebc730
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
5 changes: 1 addition & 4 deletions framework/core/src/Extension/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function setVersion($version)
*
* @internal
*/
public function calculateDependencies($extensionSet, $enabledIds)
public function calculateDependencies($extensionSet)
{
$this->extensionDependencyIds = (new Collection(Arr::get($this->composerJson, 'require', [])))
->keys()
Expand All @@ -235,9 +235,6 @@ public function calculateDependencies($extensionSet, $enabledIds)
->map(function ($key) {
return static::nameToId($key);
})
->filter(function ($key) use ($enabledIds) {
return array_key_exists($key, $enabledIds);
})
->toArray();
}

Expand Down
4 changes: 1 addition & 3 deletions framework/core/src/Extension/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public function getExtensions()
// We calculate and store a set of composer package names for all installed Flarum extensions,
// so we know what is and isn't a flarum extension in `calculateDependencies`.
// Using keys of an associative array allows us to do these checks in constant time.
// We do the same for enabled extensions, for optional dependencies.
$installedSet = [];
$enabledIds = array_flip($this->getEnabled());

foreach ($installed as $package) {
if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) {
Expand All @@ -113,7 +111,7 @@ public function getExtensions()
}

foreach ($extensions as $extension) {
$extension->calculateDependencies($installedSet, $enabledIds);
$extension->calculateDependencies($installedSet);
}

$needsReset = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp(): void
$this->missing = new FakeExtension('flarum-missing', ['this-does-not-exist', 'flarum-tags', 'also-not-exists']);
$this->circular1 = new FakeExtension('circular1', ['circular2']);
$this->circular2 = new FakeExtension('circular2', ['circular1']);
$this->optionalDependencyCategories = new FakeExtension('flarum-categories', ['flarum-tags'], ['flarum-tag-backgrounds']);
$this->optionalDependencyCategories = new FakeExtension('flarum-categories', ['flarum-tags'], ['flarum-tag-backgrounds', 'non-existent-optional-dependency']);
}

/** @test */
Expand Down

0 comments on commit eebc730

Please sign in to comment.