addArgument('module', InputArgument::REQUIRED, 'O nome do módulo a ser desativado');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$moduleName = $input->getArgument('module');
$modulePath = dirname(__DIR__, 3) . '/modules/' . $moduleName . '/module.json';
if (!file_exists($modulePath)) {
$output->writeln("Módulo '{$moduleName}' não encontrado ou arquivo module.json inexistente.");
return Command::FAILURE;
}
$config = json_decode(file_get_contents($modulePath), true);
if ($config === null) {
$output->writeln("Erro ao ler o arquivo module.json do módulo '{$moduleName}'.");
return Command::FAILURE;
}
$isActive = $config['module_active'] ?? $config['module_ative'] ?? false;
if ($isActive === false) {
$output->writeln("O módulo '{$moduleName}' já está desativado.");
return Command::SUCCESS;
}
// Maintain the key already used in the file if possible
if (isset($config['module_ative'])) {
$config['module_ative'] = false;
} else {
$config['module_active'] = false;
}
if (file_put_contents($modulePath, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))) {
$output->writeln("Módulo '{$moduleName}' desativado com sucesso!");
return Command::SUCCESS;
}
$output->writeln("Falha ao atualizar o arquivo module.json do módulo '{$moduleName}'.");
return Command::FAILURE;
}
}