2024-05-05 09:14:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Modules\Plugins\Commands;
|
|
|
|
|
|
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
|
|
use CodeIgniter\CLI\CLI;
|
2024-05-06 16:00:47 +00:00
|
|
|
use Modules\Plugins\Core\Plugins;
|
2024-05-29 10:24:13 +00:00
|
|
|
use Override;
|
2024-05-05 09:14:30 +00:00
|
|
|
|
|
|
|
class UninstallPlugin extends BaseCommand
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The Command's Group
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $group = 'Plugins';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Command's Name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $name = 'plugins:uninstall';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Command's Description
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2024-06-08 18:30:36 +00:00
|
|
|
protected $description = 'Removes a plugin from the plugins directory.';
|
2024-05-05 09:14:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Command's Usage
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $usage = 'plugins:uninstall [plugins]';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Command's Arguments
|
|
|
|
*
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected $arguments = [
|
|
|
|
'plugins' => 'One or more plugins as vendor/plugin',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param list<string> $pluginKeys
|
|
|
|
*/
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2024-05-05 09:14:30 +00:00
|
|
|
public function run(array $pluginKeys): int
|
|
|
|
{
|
2024-05-05 13:10:59 +00:00
|
|
|
/** @var Plugins $plugins */
|
|
|
|
$plugins = service('plugins');
|
2024-05-05 09:14:30 +00:00
|
|
|
|
|
|
|
/** @var list<string> $errors */
|
|
|
|
$errors = [];
|
|
|
|
foreach ($pluginKeys as $pluginKey) {
|
2024-05-05 13:10:59 +00:00
|
|
|
$plugin = $plugins->getPluginByKey($pluginKey);
|
|
|
|
|
|
|
|
if ($plugin === null) {
|
|
|
|
$errors[] = sprintf('Plugin %s was not found.', $pluginKey);
|
2024-05-05 09:14:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-05 13:10:59 +00:00
|
|
|
if (! $plugins->uninstall($plugin)) {
|
2024-05-05 09:14:30 +00:00
|
|
|
$errors[] = sprintf('Something happened when removing %s', $pluginKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
CLI::error($error . PHP_EOL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors === [] ? 0 : 1;
|
|
|
|
}
|
|
|
|
}
|