Files
dockerfluxodecaixapro/app/Console/Commands/ModuleListCommand.php
T
2026-09-01 10:46:29 -03:00

86 lines
3.4 KiB
PHP
Executable File

<?php
namespace App\Console\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;
use Illuminate\Database\Capsule\Manager as Capsule;
use Kernel\ModuleLoader;
class ModuleListCommand extends Command
{
protected static $defaultName = 'module:list';
protected static $defaultDescription = 'Lista todos os módulos instalados e suas informações';
protected function execute(InputInterface $input, OutputInterface $output): int
{
$modulesPath = dirname(__DIR__, 3) . '/modules';
$loader = new ModuleLoader($modulesPath);
try {
// Get all directories in modules/
$dirs = glob($modulesPath . '/*', GLOB_ONLYDIR);
if (empty($dirs)) {
$output->writeln('<info>Nenhum módulo encontrado em modules/.</info>');
return Command::SUCCESS;
}
$output->writeln('<info>Módulos do Sistema:</info>');
$table = new Table($output);
$table->setHeaders(['Nome', 'Versão', 'Ativo', 'Pronto', 'DB', 'Descrição']);
// Get registered modules from DB using correct column name
$dbModules = [];
if (Capsule::schema()->hasTable('modules')) {
$dbModules = Capsule::table('modules')->pluck('modules_name')->toArray();
}
foreach ($dirs as $dir) {
$name = basename($dir);
$jsonFile = $dir . '/module.json';
$version = 'N/A';
$active = '<comment>Não</comment>';
$ready = '<comment>Não</comment>';
$dbStatus = in_array($name, $dbModules) ? '<info>Sim</info>' : '<comment>Não</comment>';
$description = 'Sem descrição';
if (file_exists($jsonFile)) {
$config = json_decode(file_get_contents($jsonFile), true);
if ($config) {
$version = $config['version'] ?? '1.0.0';
// Check both module_active and module_ative, default to true if missing
$isActive = $config['module_active'] ?? $config['module_ative'] ?? true;
$active = $isActive ? '<info>Sim</info>' : '<comment>Não</comment>';
$isReady = $config['ready'] ?? true;
$ready = $isReady ? '<info>Sim</info>' : '<comment>Não</comment>';
$description = $config['description'] ?? 'Sem descrição';
}
}
$table->addRow([
$name,
$version,
$active,
$ready,
$dbStatus,
substr($description, 0, 40) . (strlen($description) > 40 ? '...' : '')
]);
}
$table->render();
$output->writeln("<info>Total de módulos: " . count($dirs) . "</info>");
return Command::SUCCESS;
} catch (\Exception $e) {
$output->writeln('<error>Erro ao listar módulos: ' . $e->getMessage() . '</error>');
return Command::FAILURE;
}
}
}