Make timezone an attribute

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl 2026-01-19 12:17:25 +01:00
parent 16cfcc28be
commit cc62f83c86
4 changed files with 22 additions and 22 deletions

View file

@ -117,7 +117,7 @@ $app->get('/containers', function (Request $request, Response $response, array $
'borg_restore_password' => $configurationManager->borg_restore_password, 'borg_restore_password' => $configurationManager->borg_restore_password,
'daily_backup_time' => $configurationManager->GetDailyBackupTime(), 'daily_backup_time' => $configurationManager->GetDailyBackupTime(),
'is_daily_backup_running' => $configurationManager->isDailyBackupRunning(), 'is_daily_backup_running' => $configurationManager->isDailyBackupRunning(),
'timezone' => $configurationManager->GetTimezone(), 'timezone' => $configurationManager->timezone,
'skip_domain_validation' => $configurationManager->shouldDomainValidationBeSkipped($skip_domain_validation), 'skip_domain_validation' => $configurationManager->shouldDomainValidationBeSkipped($skip_domain_validation),
'talk_port' => $configurationManager->GetTalkPort(), 'talk_port' => $configurationManager->GetTalkPort(),
'collabora_dictionaries' => $configurationManager->GetCollaboraDictionaries(), 'collabora_dictionaries' => $configurationManager->GetCollaboraDictionaries(),

View file

@ -67,12 +67,12 @@ readonly class ConfigurationController {
} }
if (isset($request->getParsedBody()['delete_timezone'])) { if (isset($request->getParsedBody()['delete_timezone'])) {
$this->configurationManager->DeleteTimezone(); $this->configurationManager->deleteTimezone();
} }
if (isset($request->getParsedBody()['timezone'])) { if (isset($request->getParsedBody()['timezone'])) {
$timezone = $request->getParsedBody()['timezone'] ?? ''; $timezone = $request->getParsedBody()['timezone'] ?? '';
$this->configurationManager->SetTimezone($timezone); $this->configurationManager->timezone = $timezone;
} }
if (isset($request->getParsedBody()['options-form'])) { if (isset($request->getParsedBody()['options-form'])) {

View file

@ -124,6 +124,18 @@ class ConfigurationManager
set { $this->set('borg_restore_password', $value); } set { $this->set('borg_restore_password', $value); }
} }
/**
* @throws InvalidSettingConfigurationException
*/
public string $timezone {
get => $this->get('timezone', '');
set {
// This throws an exception if the validation fails.
$this->validateTimezone($value);
$this->set('timezone', $value);
}
}
public function GetConfig() : array public function GetConfig() : array
{ {
if ($this->config === [] && file_exists(DataConst::GetConfigFile())) if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
@ -784,19 +796,10 @@ class ConfigurationManager
return false; return false;
} }
public function GetTimezone() : string {
$config = $this->GetConfig();
if(!isset($config['timezone'])) {
$config['timezone'] = '';
}
return $config['timezone'];
}
/** /**
* @throws InvalidSettingConfigurationException * @throws InvalidSettingConfigurationException
*/ */
public function SetTimezone(string $timezone) : void { private function validateTimezone(string $timezone) : void {
if ($timezone === "") { if ($timezone === "") {
throw new InvalidSettingConfigurationException("The timezone must not be empty!"); throw new InvalidSettingConfigurationException("The timezone must not be empty!");
} }
@ -804,16 +807,13 @@ class ConfigurationManager
if (!preg_match("#^[a-zA-Z0-9_\-\/\+]+$#", $timezone)) { if (!preg_match("#^[a-zA-Z0-9_\-\/\+]+$#", $timezone)) {
throw new InvalidSettingConfigurationException("The entered timezone does not seem to be a valid timezone!"); throw new InvalidSettingConfigurationException("The entered timezone does not seem to be a valid timezone!");
} }
$config = $this->GetConfig();
$config['timezone'] = $timezone;
$this->WriteConfig($config);
} }
public function DeleteTimezone() : void { /**
$config = $this->GetConfig(); * Provide an extra method since our `timezone` attribute setter prevents setting an empty timezone.
$config['timezone'] = ''; */
$this->WriteConfig($config); public function deleteTimezone() : void {
$this->set('timezone', '');
} }
public function shouldDomainValidationBeSkipped(bool $skipDomainValidation) : bool { public function shouldDomainValidationBeSkipped(bool $skipDomainValidation) : bool {

View file

@ -577,7 +577,7 @@ readonly class DockerActionManager {
'COLLABORA_ENABLED' => $this->configurationManager->isCollaboraEnabled ? 'yes' : '', 'COLLABORA_ENABLED' => $this->configurationManager->isCollaboraEnabled ? 'yes' : '',
'TALK_ENABLED' => $this->configurationManager->isTalkEnabled ? 'yes' : '', 'TALK_ENABLED' => $this->configurationManager->isTalkEnabled ? 'yes' : '',
'UPDATE_NEXTCLOUD_APPS' => ($this->configurationManager->isDailyBackupRunning() && $this->configurationManager->areAutomaticUpdatesEnabled()) ? 'yes' : '', 'UPDATE_NEXTCLOUD_APPS' => ($this->configurationManager->isDailyBackupRunning() && $this->configurationManager->areAutomaticUpdatesEnabled()) ? 'yes' : '',
'TIMEZONE' => $this->configurationManager->GetTimezone() === '' ? 'Etc/UTC' : $this->configurationManager->GetTimezone(), 'TIMEZONE' => $this->configurationManager->timezone === '' ? 'Etc/UTC' : $this->configurationManager->timezone,
'COLLABORA_DICTIONARIES' => $this->configurationManager->GetCollaboraDictionaries() === '' ? 'de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru' : $this->configurationManager->GetCollaboraDictionaries(), 'COLLABORA_DICTIONARIES' => $this->configurationManager->GetCollaboraDictionaries() === '' ? 'de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru' : $this->configurationManager->GetCollaboraDictionaries(),
'IMAGINARY_ENABLED' => $this->configurationManager->isImaginaryEnabled ? 'yes' : '', 'IMAGINARY_ENABLED' => $this->configurationManager->isImaginaryEnabled ? 'yes' : '',
'FULLTEXTSEARCH_ENABLED' => $this->configurationManager->isFulltextsearchEnabled ? 'yes' : '', 'FULLTEXTSEARCH_ENABLED' => $this->configurationManager->isFulltextsearchEnabled ? 'yes' : '',