2026-06-04 11:20:35 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package MokoJoomBackup
|
2026-06-06 14:52:27 -05:00
|
|
|
* @subpackage plg_console_mokojoombackup
|
2026-06-04 11:20:35 -05:00
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-06 14:52:27 -05:00
|
|
|
namespace Joomla\Plugin\Console\MokoJoomBackup\Command;
|
2026-06-04 11:20:35 -05:00
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\Factory;
|
2026-06-06 14:52:27 -05:00
|
|
|
use Joomla\Component\MokoJoomBackup\Administrator\Engine\BackupEngine;
|
2026-06-04 11:20:35 -05:00
|
|
|
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
|
|
|
|
|
{
|
2026-06-06 14:52:27 -05:00
|
|
|
protected static $defaultName = 'mokojoombackup:run';
|
2026-06-04 11:20:35 -05:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2026-06-06 14:52:27 -05:00
|
|
|
$engineFile = JPATH_ADMINISTRATOR . '/components/com_mokojoombackup/src/Engine/BackupEngine.php';
|
2026-06-04 11:20:35 -05:00
|
|
|
|
|
|
|
|
if (!file_exists($engineFile)) {
|
|
|
|
|
$io->error('MokoJoomBackup component not installed.');
|
|
|
|
|
|
2026-06-04 20:15:52 -05:00
|
|
|
return 1;
|
2026-06-04 11:20:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2026-06-04 11:20:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$io->error($result['message']);
|
|
|
|
|
|
2026-06-04 20:15:52 -05:00
|
|
|
return 1;
|
2026-06-04 11:20:35 -05:00
|
|
|
}
|
|
|
|
|
}
|