|
15 | 15 | use Flarum\Extension\Event\Enabled; |
16 | 16 | use Flarum\Extension\Event\Enabling; |
17 | 17 | use Flarum\Extension\Event\Uninstalled; |
| 18 | +use Flarum\Extension\Exception\CircularDependenciesException; |
18 | 19 | use Flarum\Foundation\Paths; |
19 | 20 | use Flarum\Settings\SettingsRepositoryInterface; |
20 | 21 | use Illuminate\Contracts\Container\Container; |
@@ -157,6 +158,13 @@ public function getExtensions() |
157 | 158 | return $this->extensions; |
158 | 159 | } |
159 | 160 |
|
| 161 | + public function getExtensionsById(array $ids): Collection |
| 162 | + { |
| 163 | + return $this->getExtensions()->filter(function (Extension $extension) use ($ids) { |
| 164 | + return in_array($extension->getId(), $ids); |
| 165 | + }); |
| 166 | + } |
| 167 | + |
160 | 168 | /** |
161 | 169 | * Loads an Extension with all information. |
162 | 170 | * |
@@ -397,10 +405,19 @@ public function getEnabled() |
397 | 405 | * Persist the currently enabled extensions. |
398 | 406 | * |
399 | 407 | * @param array $enabledExtensions |
| 408 | + * @throws CircularDependenciesException |
400 | 409 | */ |
401 | 410 | protected function setEnabledExtensions(array $enabledExtensions) |
402 | 411 | { |
403 | | - $sortedEnabled = static::resolveExtensionOrder($enabledExtensions)['valid']; |
| 412 | + $resolved = static::resolveExtensionOrder($enabledExtensions); |
| 413 | + |
| 414 | + if (! empty($resolved['circularDependencies'])) { |
| 415 | + throw new Exception\CircularDependenciesException( |
| 416 | + $this->getExtensionsById($resolved['circularDependencies'])->values()->all() |
| 417 | + ); |
| 418 | + } |
| 419 | + |
| 420 | + $sortedEnabled = $resolved['valid']; |
404 | 421 |
|
405 | 422 | $sortedEnabledIds = array_map(function (Extension $extension) { |
406 | 423 | return $extension->getId(); |
|
0 commit comments