Skip to content

Commit

Permalink
refactor: plugin activate and deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
jevantang committed Mar 26, 2024
1 parent 15ffaeb commit b5d593d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
42 changes: 25 additions & 17 deletions src/Commands/PluginActivateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
}
41 changes: 25 additions & 16 deletions src/Commands/PluginDeactivateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
}

0 comments on commit b5d593d

Please sign in to comment.