* @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 RemoteTable extends Table { public function __construct(DatabaseDriver $db) { parent::__construct('#__mokosuitebackup_remotes', 'id', $db); } public function check(): bool { if (empty($this->profile_id)) { $this->setError('Profile ID is required.'); return false; } $validTypes = ['sftp', 's3', 'google_drive', 'ftp']; if (empty($this->type) || !\in_array($this->type, $validTypes, true)) { $this->setError('Invalid remote type. Must be one of: ' . implode(', ', $validTypes)); return false; } if (empty($this->title)) { $this->title = ucfirst(str_replace('_', ' ', $this->type)) . ' Remote'; } // Ensure params is valid JSON if (!empty($this->params) && \is_string($this->params)) { $decoded = json_decode($this->params); if (json_last_error() !== JSON_ERROR_NONE) { $this->setError('Remote params must be valid JSON.'); return false; } } $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; } /** * Get the params as a decoded object. * * @return object */ public function getParams(): object { if (empty($this->params)) { return (object) []; } $decoded = json_decode($this->params); return \is_object($decoded) ? $decoded : (object) []; } /** * Set params from an array or object, encoding to JSON. * * @param array|object $params The parameters to encode * * @return void */ public function setParams(array|object $params): void { $this->params = json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } }