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\Table;
|
2026-06-02 13:47:36 -05:00
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\Table\Table;
|
2026-06-07 09:38:43 -05:00
|
|
|
use Joomla\Component\MokoJoomBackup\Administrator\Utility\BackupDirectory;
|
2026-06-02 13:47:36 -05:00
|
|
|
use Joomla\Database\DatabaseDriver;
|
|
|
|
|
|
|
|
|
|
class ProfileTable extends Table
|
|
|
|
|
{
|
|
|
|
|
public function __construct(DatabaseDriver $db)
|
|
|
|
|
{
|
2026-06-06 14:52:27 -05:00
|
|
|
parent::__construct('#__mokojoombackup_profiles', 'id', $db);
|
2026-06-02 13:47:36 -05:00
|
|
|
}
|
|
|
|
|
|
2026-06-07 06:54:12 -05:00
|
|
|
public function store($updateNulls = true): bool
|
|
|
|
|
{
|
|
|
|
|
$result = parent::store($updateNulls);
|
|
|
|
|
|
|
|
|
|
if ($result && !empty($this->backup_dir)) {
|
|
|
|
|
$this->protectWebAccessibleDir($this->backup_dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function protectWebAccessibleDir(string $dir): void
|
|
|
|
|
{
|
2026-06-07 09:38:43 -05:00
|
|
|
$resolved = BackupDirectory::resolve($dir);
|
2026-06-07 06:54:12 -05:00
|
|
|
|
2026-06-07 09:38:43 -05:00
|
|
|
if (BackupDirectory::hasPlaceholders($resolved)) {
|
2026-06-07 06:54:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-07 09:38:43 -05:00
|
|
|
if (!BackupDirectory::isWebAccessible($resolved)) {
|
2026-06-07 06:54:12 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-07 09:38:43 -05:00
|
|
|
BackupDirectory::ensureReady($resolved);
|
2026-06-07 06:54:12 -05:00
|
|
|
}
|
|
|
|
|
|
2026-06-02 13:47:36 -05:00
|
|
|
public function check(): bool
|
|
|
|
|
{
|
|
|
|
|
if (empty($this->title)) {
|
|
|
|
|
$this->setError('Profile title is required.');
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($this->backup_type)) {
|
|
|
|
|
$this->backup_type = 'full';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
|
|
|
|
|
|
|
if (empty($this->created) || $this->created === '0000-00-00 00:00:00') {
|
|
|
|
|
$this->created = $now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->modified = $now;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|