Make domain an attribute

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl 2026-01-19 12:06:20 +01:00
parent f737d2f598
commit 5b0b9ef826
3 changed files with 15 additions and 14 deletions

View file

@ -91,7 +91,7 @@ $app->get('/containers', function (Request $request, Response $response, array $
$skip_domain_validation = isset($params['skip_domain_validation']); $skip_domain_validation = isset($params['skip_domain_validation']);
return $view->render($response, 'containers.twig', [ return $view->render($response, 'containers.twig', [
'domain' => $configurationManager->GetDomain(), 'domain' => $configurationManager->domain,
'apache_port' => $configurationManager->GetApachePort(), 'apache_port' => $configurationManager->GetApachePort(),
'borg_backup_host_location' => $configurationManager->GetBorgBackupHostLocation(), 'borg_backup_host_location' => $configurationManager->GetBorgBackupHostLocation(),
'borg_remote_repo' => $configurationManager->GetBorgRemoteRepo(), 'borg_remote_repo' => $configurationManager->GetBorgRemoteRepo(),

View file

@ -257,7 +257,7 @@ readonly class DockerController {
public function StartDomaincheckContainer() : void public function StartDomaincheckContainer() : void
{ {
# Don't start if domain is already set # Don't start if domain is already set
if ($this->configurationManager->GetDomain() !== '' || $this->configurationManager->wasStartButtonClicked) { if ($this->configurationManager->domain !== '' || $this->configurationManager->wasStartButtonClicked) {
return; return;
} }

View file

@ -104,6 +104,11 @@ class ConfigurationManager
set { $this->set('isFulltextsearchEnabled', ($this->isSeccompDisabled() && $value)); } set { $this->set('isFulltextsearchEnabled', ($this->isSeccompDisabled() && $value)); }
} }
public string $domain {
get => $this->get('domain', '');
set { $this->SetDomain($value); }
}
public function GetConfig() : array public function GetConfig() : array
{ {
if ($this->config === [] && file_exists(DataConst::GetConfigFile())) if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
@ -241,6 +246,8 @@ class ConfigurationManager
/** /**
* @throws InvalidSettingConfigurationException * @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 { public function SetDomain(string $domain, bool $skipDomainValidation) : void {
// Validate that at least one dot is contained // Validate that at least one dot is contained
@ -346,25 +353,19 @@ class ConfigurationManager
} }
} }
// Write domain
$config = $this->GetConfig(); $config = $this->GetConfig();
$config['domain'] = $domain;
// Reset the borg restore password when setting the domain // Reset the borg restore password when setting the domain
$config['borg_restore_password'] = ''; $config['borg_restore_password'] = '';
$this->WriteConfig($config); $this->WriteConfig($config);
} $this->setMultiple(function ($confManager) use ($domain) {
// Write domain
public function GetDomain() : string { // Don't set the domain via the attribute, or we create a loop.
$config = $this->GetConfig(); $confManager->set('domain', $domain);
if(!isset($config['domain'])) { });
$config['domain'] = '';
}
return $config['domain'];
} }
public function GetBaseDN() : string { public function GetBaseDN() : string {
$domain = $this->GetDomain(); $domain = $this->domain;
if ($domain === "") { if ($domain === "") {
return ""; return "";
} }