mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-05 22:05:47 -05:00
extension enable check
This commit is contained in:
@@ -60,9 +60,13 @@ final class ExtensionCompatibility
|
||||
/** @param Collection<string, ExtensionManifest> $enabled */
|
||||
public function assertCompatible(ExtensionManifest $manifest, Collection $enabled): void
|
||||
{
|
||||
$errors = $this->resolve((clone $enabled)->put($manifest->id, $manifest))['errors'];
|
||||
// A claim both sides make is reported from the side of the extension being checked.
|
||||
$reason = $errors[$manifest->id] ?? reset($errors);
|
||||
$before = $this->resolve($enabled)['errors'];
|
||||
$after = $this->resolve((clone $enabled)->put($manifest->id, $manifest))['errors'];
|
||||
// An extension that was already failing does not hold this one back: only a failure
|
||||
// of its own, or one it causes in another extension, does. A claim both sides make
|
||||
// is reported from the side of the extension being checked.
|
||||
$caused = array_diff_key($after, $before);
|
||||
$reason = $after[$manifest->id] ?? reset($caused);
|
||||
throw_if($reason !== false, InvalidExtensionException::class, $reason);
|
||||
$this->assertDistinctAutoloader($manifest, $enabled);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,19 @@ test('rejects upgrades and disabling that would break an enabled dependent', fun
|
||||
$compatibility->assertCanDisable('child', $enabled);
|
||||
});
|
||||
|
||||
test('an extension that is already failing does not stop another from being enabled', function (): void {
|
||||
$enabled = collect([
|
||||
'future' => manifest('future', ['panel' => '^3.0']),
|
||||
'orphan' => manifest('orphan', ['extensions' => ['gone' => '*']]),
|
||||
]);
|
||||
$compatibility = resolve(ExtensionCompatibility::class);
|
||||
|
||||
$compatibility->assertCompatible(manifest('healthy'), $enabled);
|
||||
|
||||
expect(fn () => $compatibility->assertCompatible(manifest('dependent', ['extensions' => ['future' => '*']]), $enabled))
|
||||
->toThrow(InvalidExtensionException::class, 'Extension "dependent" requires unavailable extension "future".');
|
||||
});
|
||||
|
||||
/** @param list<string> $components */
|
||||
function presentation(string $id, array $components): ExtensionManifest
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user