mirror of
https://github.com/flarum/core.git
synced 2025-07-31 21:50:50 +02:00
fix: circular dependencies disable all involved extensions (#3785)
This commit is contained in:
@@ -605,6 +605,7 @@ core:
|
|||||||
|
|
||||||
# These translations are displayed as error messages.
|
# These translations are displayed as error messages.
|
||||||
error:
|
error:
|
||||||
|
circular_dependencies_message: "Circular dependencies detected: {extensions}. Aborting. Please disable one of the extensions and try again."
|
||||||
dependent_extensions_message: "Cannot disable {extension} until the following dependent extensions are disabled: {extensions}"
|
dependent_extensions_message: "Cannot disable {extension} until the following dependent extensions are disabled: {extensions}"
|
||||||
extension_initialiation_failed_message: "{extension} failed to initialize, check the browser console for further information."
|
extension_initialiation_failed_message: "{extension} failed to initialize, check the browser console for further information."
|
||||||
generic_message: "Oops! Something went wrong. Please reload the page and try again."
|
generic_message: "Oops! Something went wrong. Please reload the page and try again."
|
||||||
|
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Extension\Exception;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Flarum\Extension\ExtensionManager;
|
||||||
|
|
||||||
|
class CircularDependenciesException extends Exception
|
||||||
|
{
|
||||||
|
public $circular_dependencies;
|
||||||
|
|
||||||
|
public function __construct(array $circularDependencies)
|
||||||
|
{
|
||||||
|
$this->circular_dependencies = $circularDependencies;
|
||||||
|
|
||||||
|
parent::__construct('Circular dependencies detected: '.implode(', ', ExtensionManager::pluckTitles($circularDependencies)).' - aborting. Please fix this by disabling the extensions that are causing the circular dependencies.');
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* For detailed copyright and license information, please view the
|
||||||
|
* LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Flarum\Extension\Exception;
|
||||||
|
|
||||||
|
use Flarum\Extension\ExtensionManager;
|
||||||
|
use Flarum\Foundation\ErrorHandling\HandledError;
|
||||||
|
|
||||||
|
class CircularDependenciesExceptionHandler
|
||||||
|
{
|
||||||
|
public function handle(CircularDependenciesException $e): HandledError
|
||||||
|
{
|
||||||
|
return (new HandledError(
|
||||||
|
$e,
|
||||||
|
'circular_dependencies',
|
||||||
|
409
|
||||||
|
))->withDetails($this->errorDetails($e));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function errorDetails(CircularDependenciesException $e): array
|
||||||
|
{
|
||||||
|
return [[
|
||||||
|
'extensions' => ExtensionManager::pluckTitles($e->circular_dependencies),
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
}
|
@@ -15,6 +15,7 @@ use Flarum\Extension\Event\Disabling;
|
|||||||
use Flarum\Extension\Event\Enabled;
|
use Flarum\Extension\Event\Enabled;
|
||||||
use Flarum\Extension\Event\Enabling;
|
use Flarum\Extension\Event\Enabling;
|
||||||
use Flarum\Extension\Event\Uninstalled;
|
use Flarum\Extension\Event\Uninstalled;
|
||||||
|
use Flarum\Extension\Exception\CircularDependenciesException;
|
||||||
use Flarum\Foundation\Paths;
|
use Flarum\Foundation\Paths;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
@@ -157,6 +158,13 @@ class ExtensionManager
|
|||||||
return $this->extensions;
|
return $this->extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getExtensionsById(array $ids): Collection
|
||||||
|
{
|
||||||
|
return $this->getExtensions()->filter(function (Extension $extension) use ($ids) {
|
||||||
|
return in_array($extension->getId(), $ids);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an Extension with all information.
|
* Loads an Extension with all information.
|
||||||
*
|
*
|
||||||
@@ -397,10 +405,19 @@ class ExtensionManager
|
|||||||
* Persist the currently enabled extensions.
|
* Persist the currently enabled extensions.
|
||||||
*
|
*
|
||||||
* @param array $enabledExtensions
|
* @param array $enabledExtensions
|
||||||
|
* @throws CircularDependenciesException
|
||||||
*/
|
*/
|
||||||
protected function setEnabledExtensions(array $enabledExtensions)
|
protected function setEnabledExtensions(array $enabledExtensions)
|
||||||
{
|
{
|
||||||
$sortedEnabled = static::resolveExtensionOrder($enabledExtensions)['valid'];
|
$resolved = static::resolveExtensionOrder($enabledExtensions);
|
||||||
|
|
||||||
|
if (! empty($resolved['circularDependencies'])) {
|
||||||
|
throw new Exception\CircularDependenciesException(
|
||||||
|
$this->getExtensionsById($resolved['circularDependencies'])->values()->all()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sortedEnabled = $resolved['valid'];
|
||||||
|
|
||||||
$sortedEnabledIds = array_map(function (Extension $extension) {
|
$sortedEnabledIds = array_map(function (Extension $extension) {
|
||||||
return $extension->getId();
|
return $extension->getId();
|
||||||
|
@@ -58,6 +58,7 @@ class ErrorServiceProvider extends AbstractServiceProvider
|
|||||||
return [
|
return [
|
||||||
IlluminateValidationException::class => Handling\ExceptionHandler\IlluminateValidationExceptionHandler::class,
|
IlluminateValidationException::class => Handling\ExceptionHandler\IlluminateValidationExceptionHandler::class,
|
||||||
ValidationException::class => Handling\ExceptionHandler\ValidationExceptionHandler::class,
|
ValidationException::class => Handling\ExceptionHandler\ValidationExceptionHandler::class,
|
||||||
|
ExtensionException\CircularDependenciesException::class => ExtensionException\CircularDependenciesExceptionHandler::class,
|
||||||
ExtensionException\DependentExtensionsException::class => ExtensionException\DependentExtensionsExceptionHandler::class,
|
ExtensionException\DependentExtensionsException::class => ExtensionException\DependentExtensionsExceptionHandler::class,
|
||||||
ExtensionException\MissingDependenciesException::class => ExtensionException\MissingDependenciesExceptionHandler::class,
|
ExtensionException\MissingDependenciesException::class => ExtensionException\MissingDependenciesExceptionHandler::class,
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user