2026-06-02 13:47:36 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package MokoJoomBackup
|
2026-06-06 14:52:27 -05:00
|
|
|
* @subpackage com_mokojoombackup
|
2026-06-02 13:47:36 -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\Component\MokoJoomBackup\Administrator\Controller;
|
2026-06-02 13:47:36 -05:00
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
2026-06-02 15:48:31 -05:00
|
|
|
use Joomla\CMS\Factory;
|
2026-06-02 13:47:36 -05:00
|
|
|
use Joomla\CMS\MVC\Controller\AdminController;
|
2026-06-02 15:48:31 -05:00
|
|
|
use Joomla\CMS\Router\Route;
|
2026-06-06 14:52:27 -05:00
|
|
|
use Joomla\Component\MokoJoomBackup\Administrator\Engine\AkeebaImporter;
|
2026-06-02 13:47:36 -05:00
|
|
|
|
|
|
|
|
class ProfilesController extends AdminController
|
|
|
|
|
{
|
2026-06-06 14:52:27 -05:00
|
|
|
protected $text_prefix = 'COM_MOKOJOOMBACKUP_PROFILES';
|
2026-06-02 13:47:36 -05:00
|
|
|
|
|
|
|
|
public function getModel($name = 'Profile', $prefix = 'Administrator', $config = ['ignore_request' => true])
|
|
|
|
|
{
|
|
|
|
|
return parent::getModel($name, $prefix, $config);
|
|
|
|
|
}
|
2026-06-02 15:48:31 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Import profiles and history from Akeeba Backup Pro, then disable Akeeba.
|
|
|
|
|
*/
|
|
|
|
|
public function importAkeeba(): void
|
|
|
|
|
{
|
|
|
|
|
$this->checkToken();
|
|
|
|
|
|
|
|
|
|
$importHistory = (bool) $this->input->getInt('import_history', 1);
|
|
|
|
|
|
|
|
|
|
$importer = new AkeebaImporter();
|
|
|
|
|
$detection = $importer->detect();
|
|
|
|
|
|
|
|
|
|
if (!$detection['profiles']) {
|
2026-06-06 14:52:27 -05:00
|
|
|
$this->setMessage('COM_MOKOJOOMBACKUP_AKEEBA_NOT_FOUND', 'error');
|
|
|
|
|
$this->setRedirect(Route::_('index.php?option=com_mokojoombackup&view=profiles', false));
|
2026-06-02 15:48:31 -05:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $importer->import($importHistory);
|
|
|
|
|
|
|
|
|
|
if ($result['success']) {
|
|
|
|
|
// Disable Akeeba Backup plugins and component after successful import
|
|
|
|
|
$this->disableAkeeba();
|
|
|
|
|
$this->setMessage($result['message']);
|
|
|
|
|
} else {
|
|
|
|
|
$this->setMessage($result['message'], 'error');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 14:52:27 -05:00
|
|
|
$this->setRedirect(Route::_('index.php?option=com_mokojoombackup&view=profiles', false));
|
2026-06-02 15:48:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Disable all Akeeba Backup extensions (plugins + scheduled tasks).
|
|
|
|
|
* Does NOT uninstall — the admin can do that manually if desired.
|
|
|
|
|
*/
|
|
|
|
|
private function disableAkeeba(): void
|
|
|
|
|
{
|
|
|
|
|
$db = Factory::getDbo();
|
|
|
|
|
|
|
|
|
|
// Disable Akeeba plugins (system, quickicon, console, etc.)
|
|
|
|
|
$akeebaElements = ['akeebabackup', 'akeeba', 'akeebabackuppro'];
|
|
|
|
|
|
|
|
|
|
foreach ($akeebaElements as $element) {
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__extensions'))
|
|
|
|
|
->set($db->quoteName('enabled') . ' = 0')
|
|
|
|
|
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
|
|
|
|
|
->where($db->quoteName('element') . ' LIKE ' . $db->quote('%' . $element . '%'));
|
|
|
|
|
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$db->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable Akeeba scheduled tasks (if using Joomla task scheduler)
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->select($db->quoteName('id'))
|
|
|
|
|
->from($db->quoteName('#__scheduler_tasks'))
|
|
|
|
|
->where($db->quoteName('type') . ' LIKE ' . $db->quote('%akeeba%'));
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$taskIds = $db->loadColumn();
|
|
|
|
|
|
|
|
|
|
if (!empty($taskIds)) {
|
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
|
->update($db->quoteName('#__scheduler_tasks'))
|
|
|
|
|
->set($db->quoteName('state') . ' = 0')
|
|
|
|
|
->where($db->quoteName('id') . ' IN (' . implode(',', array_map('intval', $taskIds)) . ')');
|
|
|
|
|
$db->setQuery($query);
|
|
|
|
|
$db->execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Factory::getApplication()->enqueueMessage(
|
|
|
|
|
'Akeeba Backup plugins and scheduled tasks have been disabled. You can uninstall Akeeba manually via Extensions > Manage.',
|
|
|
|
|
'warning'
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-02 13:47:36 -05:00
|
|
|
}
|