diff --git a/src/Commands/PluginActivateCommand.php b/src/Commands/PluginActivateCommand.php index 17b9be8..72a221f 100644 --- a/src/Commands/PluginActivateCommand.php +++ b/src/Commands/PluginActivateCommand.php @@ -24,14 +24,15 @@ public function handle() $pluginFskey = $this->getPluginFskey(); if ($pluginFskey) { - $this->activate($pluginFskey); - } - // Activate all plugins - else { - $this->activateAll(); + $status = $this->activate($pluginFskey); + } else { + // Activate all plugins + $status = $this->activateAll(); } - $this->info('Plugin activate successfully'); + if (! $status) { + return Command::FAILURE; + } return Command::SUCCESS; } @@ -40,31 +41,38 @@ public function activateAll() { $plugin = new Plugin(); - collect($plugin->all())->map(function ($pluginFskey) { - $this->activate($pluginFskey); + $status = true; + + collect($plugin->all())->each(function ($pluginFskey) use (&$status) { + if (! $this->activate($pluginFskey)) { + $status = false; + } }); + + return $status; } public function activate(?string $pluginFskey = null) { $plugin = new Plugin($pluginFskey); - $fskey = $plugin->getStudlyName(); event('plugin:activating', [[ 'fskey' => $fskey, ]]); - if ($result = $plugin->activate()) { - $this->info(sprintf('Plugin %s activate successfully', $pluginFskey)); - } else { - $this->error(sprintf('Plugin %s activate failure', $pluginFskey)); + if ($plugin->activate()) { + $this->info(sprintf('Plugin %s activated successfully', $pluginFskey)); + + event('plugin:activated', [[ + 'fskey' => $fskey, + ]]); + + return true; } - event('plugin:activated', [[ - 'fskey' => $fskey, - ]]); + $this->error(sprintf('Plugin %s activation failed', $pluginFskey)); - return $result; + return false; } } diff --git a/src/Commands/PluginDeactivateCommand.php b/src/Commands/PluginDeactivateCommand.php index 5ad8406..5b77928 100644 --- a/src/Commands/PluginDeactivateCommand.php +++ b/src/Commands/PluginDeactivateCommand.php @@ -24,14 +24,15 @@ public function handle() $pluginFskey = $this->getPluginFskey(); if ($pluginFskey) { - $this->deactivate($pluginFskey); - } - // Deactivate all plugins - else { - $this->deactivateAll(); + $status = $this->deactivate($pluginFskey); + } else { + // Deactivate all plugins + $status = $this->deactivateAll(); } - $this->info('Plugin deactivate successfully'); + if (! $status) { + return Command::FAILURE; + } return Command::SUCCESS; } @@ -40,9 +41,15 @@ public function deactivateAll() { $plugin = new Plugin(); - collect($plugin->all())->map(function ($pluginFskey) { - $this->deactivate($pluginFskey); + $status = true; + + collect($plugin->all())->each(function ($pluginFskey) use (&$status) { + if (! $this->deactivate($pluginFskey)) { + $status = false; + } }); + + return $status; } public function deactivate(?string $pluginFskey = null) @@ -54,16 +61,18 @@ public function deactivate(?string $pluginFskey = null) 'fskey' => $fskey, ]]); - if ($result = $plugin->deactivate()) { - $this->info(sprintf('Plugin %s deactivate successfully', $pluginFskey)); - } else { - $this->error(sprintf('Plugin %s deactivate failure', $pluginFskey)); + if ($plugin->deactivate()) { + $this->info(sprintf('Plugin %s deactivated successfully', $pluginFskey)); + + event('plugin:deactivated', [[ + 'fskey' => $fskey, + ]]); + + return true; } - event('plugin:deactivated', [[ - 'fskey' => $fskey, - ]]); + $this->error(sprintf('Plugin %s deactivated failed', $pluginFskey)); - return $result; + return false; } }