Files
MokoSuiteBackup/source/packages/plg_console_mokojoombackup/src/Command/RunCommand.php
T

69 lines
1.9 KiB
PHP
Raw Normal View History

<?php
/**
* @package MokoJoomBackup
* @subpackage plg_console_mokojoombackup
* @author Moko Consulting <hello@mokoconsulting.tech>
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*/
namespace Joomla\Plugin\Console\MokoJoomBackup\Command;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Component\MokoJoomBackup\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 = 'mokojoombackup: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('MokoJoomBackup — Run Backup');
$io->text('Profile ID: ' . $profileId);
$engineFile = JPATH_ADMINISTRATOR . '/components/com_mokojoombackup/src/Engine/BackupEngine.php';
if (!file_exists($engineFile)) {
$io->error('MokoJoomBackup component not installed.');
2026-06-04 20:15:52 -05:00
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']);
2026-06-04 20:15:52 -05:00
return 0;
}
$io->error($result['message']);
2026-06-04 20:15:52 -05:00
return 1;
}
}