Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Extension Dependency Support #2188

Merged
merged 32 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c8cfdad
Add relevant exceptions for enabling/disabling
askvortsov1 May 28, 2020
e50f22b
Add helper method for getting flarum extension dependencies
askvortsov1 May 28, 2020
7937f82
Add extension dependency resolver (Kahn's algorithm), plus unit tests
askvortsov1 May 28, 2020
acc4f65
Enable extensions in proper order
askvortsov1 May 28, 2020
ec3cd0c
Fix no default when getting extension dependencies
askvortsov1 May 28, 2020
0722382
Apply fixes from StyleCI
luceos May 28, 2020
6c686bb
Use require instead of dedicated field to get extension dependencies
askvortsov1 Jul 24, 2020
787515d
Apply fixes from StyleCI
luceos Jul 24, 2020
c374baf
Fix fake extension to not fail tests and be compliant
askvortsov1 Jul 24, 2020
30ee917
Remove unnecessary import
askvortsov1 Sep 6, 2020
fec6ff3
Fix constructor, remove KnownError since we'll need a custom handler
askvortsov1 Sep 6, 2020
54a35b4
Add custom handlers for dependency exceptions
askvortsov1 Sep 6, 2020
2e4ebef
Standardize return format
askvortsov1 Sep 6, 2020
d12fe5b
Add frontend error handler for admin dashboard
askvortsov1 Sep 6, 2020
6e4b867
Fix dependentExtensions saving the wrong thing
askvortsov1 Sep 6, 2020
7b405f0
Update src/Extension/Exception/DependentExtensionsException.php
askvortsov1 Sep 6, 2020
39ca931
Update for new alerts signature
askvortsov1 Sep 24, 2020
7be3c1f
Add more tests for dependency resolution
askvortsov1 Sep 24, 2020
d32bafc
Remove dependency resolution portion
askvortsov1 Sep 26, 2020
8becd7c
Store a set of installed extension composer names instead of an assoc…
askvortsov1 Sep 26, 2020
ebe0107
Improve explanation for installedSet, put its values as true, not null
askvortsov1 Sep 30, 2020
3fa2cdd
Fix comments
askvortsov1 Oct 2, 2020
e1d6378
Get rid of the $installedSet mess, use $extensions to check what is/i…
askvortsov1 Oct 2, 2020
7acf52b
Go back to using $installedSet to store composer package names for in…
askvortsov1 Oct 2, 2020
58477b5
Code cleanup
askvortsov1 Oct 2, 2020
8923b0c
Rename `extensionDependencies` to `extensionDependencyIds` for clarity
askvortsov1 Oct 2, 2020
12e60d9
Apply fixes from StyleCI
luceos Oct 2, 2020
4ba8aba
Improve extension dependency error messages, even though they aren't …
askvortsov1 Oct 2, 2020
294a8bc
Apply fixes from StyleCI
luceos Oct 2, 2020
36f8fa0
Fix leftover `extensionDependencies`
askvortsov1 Oct 2, 2020
fef0d48
Add workaround to modal bug caused by bootstrap JS
askvortsov1 Oct 2, 2020
d65b767
Remove unnecessary changes
askvortsov1 Oct 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply fixes from StyleCI
[ci skip] [skip ci]
  • Loading branch information
luceos authored and StyleCIBot committed Oct 2, 2020
commit 12e60d9b0c94c73bae254d42db958b051cb28367
1 change: 0 additions & 1 deletion src/Extension/Exception/DependentExtensionsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Exception;
use Flarum\Extension\Extension;


/**
* This exception is thrown when someone attempts to disable an extension
* that other enabled extensions depend on.
Expand Down
5 changes: 3 additions & 2 deletions src/Extension/Exception/MissingDependenciesException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public function __construct(Extension $extension, array $missing_dependencies =
*
* @return array
*/
public function getMissingDependencyIds() {
return array_map(function(Extension $extension) {
public function getMissingDependencyIds()
{
return array_map(function (Extension $extension) {
return $extension->getId();
}, $this->missing_dependencies);
}
Expand Down
22 changes: 11 additions & 11 deletions src/Extension/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function __construct(
*/
public function getExtensions()
{
if (is_null($this->extensions) && $this->filesystem->exists($this->paths->vendor . '/composer/installed.json')) {
if (is_null($this->extensions) && $this->filesystem->exists($this->paths->vendor.'/composer/installed.json')) {
$extensions = new Collection();

// Load all packages installed by composer.
$installed = json_decode($this->filesystem->get($this->paths->vendor . '/composer/installed.json'), true);
$installed = json_decode($this->filesystem->get($this->paths->vendor.'/composer/installed.json'), true);

// Composer 2.0 changes the structure of the installed.json manifest
$installed = $installed['packages'] ?? $installed;
Expand All @@ -96,8 +96,8 @@ public function getExtensions()
$installedSet[Arr::get($package, 'name')] = true;

$path = isset($package['install-path'])
? $this->paths->vendor . '/composer/' . $package['install-path']
: $this->paths->vendor . '/' . Arr::get($package, 'name');
? $this->paths->vendor.'/composer/'.$package['install-path']
: $this->paths->vendor.'/'.Arr::get($package, 'name');

// Instantiates an Extension object using the package path and composer.json file.
$extension = new Extension($path, $package);
Expand Down Expand Up @@ -148,12 +148,12 @@ public function enable($name)
$missingDependencies = [];
$enabledIds = $this->getEnabled();
foreach ($extension->getExtensionDependencyIds() as $dependencyId) {
if (!in_array($dependencyId, $enabledIds)) {
if (! in_array($dependencyId, $enabledIds)) {
$missingDependencies[] = $this->getExtension($dependencyId);
}
}

if (!empty($missingDependencies)) {
if (! empty($missingDependencies)) {
throw new Exception\MissingDependenciesException($extension, $missingDependencies);
}

Expand Down Expand Up @@ -195,7 +195,7 @@ public function disable($name)
}
}

if (!empty($dependentExtensions)) {
if (! empty($dependentExtensions)) {
throw new Exception\DependentExtensionsException($extension, $dependentExtensions);
}

Expand Down Expand Up @@ -239,8 +239,8 @@ protected function publishAssets(Extension $extension)
{
if ($extension->hasAssets()) {
$this->filesystem->copyDirectory(
$extension->getPath() . '/assets',
$this->paths->public . '/assets/extensions/' . $extension->getId()
$extension->getPath().'/assets',
$this->paths->public.'/assets/extensions/'.$extension->getId()
);
}
}
Expand All @@ -252,7 +252,7 @@ protected function publishAssets(Extension $extension)
*/
protected function unpublishAssets(Extension $extension)
{
$this->filesystem->deleteDirectory($this->paths->public . '/assets/extensions/' . $extension->getId());
$this->filesystem->deleteDirectory($this->paths->public.'/assets/extensions/'.$extension->getId());
}

/**
Expand All @@ -264,7 +264,7 @@ protected function unpublishAssets(Extension $extension)
*/
public function getAsset(Extension $extension, $path)
{
return $this->paths->public . '/assets/extensions/' . $extension->getId() . $path;
return $this->paths->public.'/assets/extensions/'.$extension->getId().$path;
}

/**
Expand Down