From 5b0b9ef8263e740fa854be09dc424d53ae1ad9ff Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Mon, 19 Jan 2026 12:06:20 +0100 Subject: [PATCH] Make `domain` an attribute Signed-off-by: Pablo Zmdl --- php/public/index.php | 2 +- php/src/Controller/DockerController.php | 2 +- php/src/Data/ConfigurationManager.php | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/php/public/index.php b/php/public/index.php index 2b1d6af1..f3e8f940 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -91,7 +91,7 @@ $app->get('/containers', function (Request $request, Response $response, array $ $skip_domain_validation = isset($params['skip_domain_validation']); return $view->render($response, 'containers.twig', [ - 'domain' => $configurationManager->GetDomain(), + 'domain' => $configurationManager->domain, 'apache_port' => $configurationManager->GetApachePort(), 'borg_backup_host_location' => $configurationManager->GetBorgBackupHostLocation(), 'borg_remote_repo' => $configurationManager->GetBorgRemoteRepo(), diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index ff73e29a..4e6d52b7 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -257,7 +257,7 @@ readonly class DockerController { public function StartDomaincheckContainer() : void { # Don't start if domain is already set - if ($this->configurationManager->GetDomain() !== '' || $this->configurationManager->wasStartButtonClicked) { + if ($this->configurationManager->domain !== '' || $this->configurationManager->wasStartButtonClicked) { return; } diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 43680ca9..d276ebb7 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -104,6 +104,11 @@ class ConfigurationManager set { $this->set('isFulltextsearchEnabled', ($this->isSeccompDisabled() && $value)); } } + public string $domain { + get => $this->get('domain', ''); + set { $this->SetDomain($value); } + } + public function GetConfig() : array { if ($this->config === [] && file_exists(DataConst::GetConfigFile())) @@ -241,6 +246,8 @@ class ConfigurationManager /** * @throws InvalidSettingConfigurationException + * + * We can't turn this into a private validation method because of the second argument. */ public function SetDomain(string $domain, bool $skipDomainValidation) : void { // Validate that at least one dot is contained @@ -346,25 +353,19 @@ class ConfigurationManager } } - // Write domain $config = $this->GetConfig(); - $config['domain'] = $domain; // Reset the borg restore password when setting the domain $config['borg_restore_password'] = ''; $this->WriteConfig($config); - } - - public function GetDomain() : string { - $config = $this->GetConfig(); - if(!isset($config['domain'])) { - $config['domain'] = ''; - } - - return $config['domain']; + $this->setMultiple(function ($confManager) use ($domain) { + // Write domain + // Don't set the domain via the attribute, or we create a loop. + $confManager->set('domain', $domain); + }); } public function GetBaseDN() : string { - $domain = $this->GetDomain(); + $domain = $this->domain; if ($domain === "") { return ""; }