* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE */ namespace Joomla\Component\MokoSuiteBackup\Administrator\Table; defined('_JEXEC') or die; use Joomla\CMS\Table\Table; use Joomla\Database\DatabaseDriver; class BackupTable extends Table { public function __construct(DatabaseDriver $db) { parent::__construct('#__mokosuitebackup_records', 'id', $db); } public function check(): bool { if (empty($this->profile_id)) { $this->setError('Profile ID is required.'); return false; } if (empty($this->backupstart) || $this->backupstart === '0000-00-00 00:00:00') { $this->backupstart = date('Y-m-d H:i:s'); } return true; } public function delete($pk = null): bool { $archivePath = $this->absolute_path; // Delete DB record first — if this fails, the file is preserved $result = parent::delete($pk); if ($result && !empty($archivePath) && is_file($archivePath)) { @unlink($archivePath); // Also remove the log file if it exists alongside the archive $logPath = preg_replace('/\.(zip|tar\.gz)$/i', '.log', $archivePath); if (is_file($logPath)) { @unlink($logPath); } } return $result; } }