Skip to content

Commit

Permalink
chore: plugin install order
Browse files Browse the repository at this point in the history
  • Loading branch information
jevantang committed Oct 22, 2022
1 parent 7071837 commit fcfcfa7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
48 changes: 12 additions & 36 deletions src/Commands/PluginInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,26 @@ public function handle()
try {
$path = $this->argument('path');
if (! str_contains($path, config('plugins.paths.plugins'))) {
$exitCode = $this->call('plugin:unzip', [
$this->call('plugin:unzip', [
'path' => $path,
]);

if ($exitCode != 0) {
return $exitCode;
}

$unikey = Cache::pull('install:plugin_unikey');
} else {
$unikey = basename($path);
$unikey = dirname($path);
}

if (! $unikey) {
info('Failed to unzip, couldn\'t get the plugin unikey');

return -1;
return 0;
}

$plugin = new Plugin($unikey);
if (! $plugin->isValidPlugin()) {
$this->error('plugin is invalid, unikey: '.$unikey);
$this->error('plugin is invalid');

return -1;
return 0;
}

$plugin->manualAddNamespace();
Expand All @@ -60,14 +56,6 @@ public function handle()
'unikey' => $unikey,
]]);

$exitCode = $this->call('plugin:publish', [
'name' => $unikey,
]);

if ($exitCode != 0) {
return $exitCode;
}

$composerJson = Json::make($plugin->getComposerJsonPath())->get();
$require = Arr::get($composerJson, 'require', []);
$requireDev = Arr::get($composerJson, 'require-dev', []);
Expand All @@ -83,45 +71,33 @@ public function handle()
}
}

$exitCode = $this->call('plugin:deactivate', [
$this->call('plugin:deactivate', [
'name' => $unikey,
]);

if ($exitCode != 0) {
return $exitCode;
}

$exitCode = $this->call('plugin:migrate', [
$this->call('plugin:migrate', [
'name' => $unikey,
'--force' => true,
]);

if ($exitCode != 0) {
return $exitCode;
}

if ($this->option('seed')) {
$exitCode = $this->call('plugin:seed', [
$this->call('plugin:seed', [
'name' => $unikey,
'--force' => true,
]);

if ($exitCode != 0) {
return $exitCode;
}
}

$plugin->install();

$this->call('plugin:publish', [
'name' => $unikey,
]);

event('plugin:installed', [[
'unikey' => $unikey,
]]);

$this->info("Installed: {$unikey}");
} catch (\Throwable $e) {
$this->error("Install fail: {$e->getMessage()}");

return -1;
}

return 0;
Expand Down
7 changes: 6 additions & 1 deletion src/Commands/PluginUninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public function handle()

// Triggers top-level computation of composer.json hash values and installation of extension packages
if (count($require) || count($requireDev)) {
Process::run('composer update', $this->output);
$process = Process::run('composer update', $this->output);
if (! $process->isSuccessful()) {
$this->error('Failed to uninstall packages, calc composer.json hash value fail');

return -1;
}
}

$plugin->uninstall();
Expand Down

0 comments on commit fcfcfa7

Please sign in to comment.