addArgument('handle', InputArgument::OPTIONAL, 'Module handle to upgrade (omit to upgrade all)') ->addOption('all', 'a', InputOption::VALUE_NONE, 'Upgrade all modules that need upgrading') ->setHelp('This command upgrades an installed module. Use --all to upgrade all modules that need upgrading.') ; } protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $handle = $input->getArgument('handle'); $all = $input->getOption('all'); $io->title('Upgrade Module'); try { if ($all || !$handle) { return $this->upgradeAll($io); } return $this->upgradeOne($io, $handle); } catch (\Throwable $e) { $io->error('Failed to upgrade module: ' . $e->getMessage()); $this->logger->error('Module upgrade failed', [ 'handle' => $handle, 'error' => $e->getMessage(), ]); return Command::FAILURE; } } private function upgradeOne(SymfonyStyle $io, string $handle): int { // Find the module $module = $this->moduleManager->fetch($handle); if (!$module) { $io->error("Module '{$handle}' not found or not installed."); return Command::FAILURE; } if (!$module->needsUpgrade()) { $io->success("Module '{$handle}' is already up to date."); return Command::SUCCESS; } $io->text("Upgrading module '{$handle}'..."); $this->moduleManager->upgrade($handle); $this->logger->info('Module upgraded via console', [ 'handle' => $handle, 'command' => $this->getName(), ]); $io->success("Module '{$handle}' upgraded successfully!"); return Command::SUCCESS; } private function upgradeAll(SymfonyStyle $io): int { $modules = $this->moduleManager->list(); $pending = []; foreach ($modules as $module) { if ($module->needsUpgrade()) { $pending[] = $module->handle(); } } if (count($pending) === 0) { $io->success('All modules are up to date.'); return Command::SUCCESS; } $io->text(sprintf('Found %d module(s) to upgrade: %s', count($pending), implode(', ', $pending))); $failed = []; foreach ($pending as $handle) { try { $io->text("Upgrading module '{$handle}'..."); $this->moduleManager->upgrade($handle); $this->logger->info('Module upgraded via console', [ 'handle' => $handle, 'command' => $this->getName(), ]); $io->text("✓ '{$handle}' upgraded."); } catch (\Throwable $e) { $failed[] = $handle; $io->text("✗ '{$handle}' failed: {$e->getMessage()}"); $this->logger->error('Module upgrade failed', [ 'handle' => $handle, 'error' => $e->getMessage(), ]); } } if (count($failed) > 0) { $io->error(sprintf('Failed to upgrade %d module(s): %s', count($failed), implode(', ', $failed))); return Command::FAILURE; } $io->success(sprintf('Successfully upgraded %d module(s).', count($pending))); return Command::SUCCESS; } }