2026-03-19 19:04:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Console\Commands\Module;
|
|
|
|
|
|
2026-04-01 17:14:20 +02:00
|
|
|
final class DeactivateCommand extends AbstractModuleCommand
|
2026-03-19 19:04:28 +01:00
|
|
|
{
|
|
|
|
|
public function name(): string
|
|
|
|
|
{
|
|
|
|
|
return 'module:deactivate';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function description(): string
|
|
|
|
|
{
|
2026-03-19 19:16:36 +01:00
|
|
|
return 'Run a module\'s deactivation handler';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function usage(): string
|
|
|
|
|
{
|
|
|
|
|
return <<<'USAGE'
|
|
|
|
|
Usage: php bin/console module:deactivate <module-id> [options]
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
--confirm Execute the deactivation handler
|
|
|
|
|
--dry-run Validate the handler without executing
|
|
|
|
|
|
|
|
|
|
The module does not need to be in the enabled list.
|
|
|
|
|
USAGE;
|
2026-03-19 19:04:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute(array $args, array $options): int
|
|
|
|
|
{
|
|
|
|
|
$moduleId = $args[0] ?? '';
|
|
|
|
|
if ($moduleId === '') {
|
2026-03-19 19:16:36 +01:00
|
|
|
fwrite(STDERR, $this->usage() . "\n");
|
2026-03-19 19:04:28 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 17:14:20 +02:00
|
|
|
$result = $this->moduleRunner()->deactivate(
|
|
|
|
|
$moduleId,
|
|
|
|
|
(bool) ($options['confirm'] ?? false),
|
|
|
|
|
(bool) ($options['dry-run'] ?? false)
|
|
|
|
|
);
|
2026-03-19 19:04:28 +01:00
|
|
|
|
2026-04-01 17:14:20 +02:00
|
|
|
$stream = $result['exit_code'] === 0 ? STDOUT : STDERR;
|
|
|
|
|
fwrite($stream, $result['message'] . PHP_EOL);
|
2026-03-19 19:04:28 +01:00
|
|
|
|
2026-04-01 17:14:20 +02:00
|
|
|
return (int) $result['exit_code'];
|
2026-03-19 19:04:28 +01:00
|
|
|
}
|
|
|
|
|
}
|