* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE */ namespace Joomla\Plugin\Console\MokoSuiteBackup\Command; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\Component\MokoSuiteBackup\Administrator\Engine\BackupEngine; use Joomla\Console\Command\AbstractCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; class RunCommand extends AbstractCommand { protected static $defaultName = 'mokosuitebackup:run'; protected function configure(): void { $this->setDescription('Run a backup using a specified profile'); $this->addOption('profile', 'p', InputOption::VALUE_REQUIRED, 'Profile ID to use', '1'); $this->addOption('description', 'd', InputOption::VALUE_OPTIONAL, 'Backup description', ''); } protected function doExecute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $profileId = (int) $input->getOption('profile'); $desc = $input->getOption('description') ?: ''; $io->title('MokoSuiteBackup — Run Backup'); $io->text('Profile ID: ' . $profileId); $engineFile = JPATH_ADMINISTRATOR . '/components/com_mokosuitebackup/src/Engine/BackupEngine.php'; if (!file_exists($engineFile)) { $io->error('MokoSuiteBackup component not installed.'); return 1; } if (!class_exists(BackupEngine::class)) { require_once $engineFile; } $engine = new BackupEngine(); $result = $engine->run($profileId, $desc ?: 'CLI backup', 'cli'); if ($result['success']) { $io->success($result['message']); return 0; } $io->error($result['message']); return 1; } }