diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 5abc81da..698e4c3c 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -265,26 +265,10 @@ class ConfigurationManager } public function GetApachePort() : string { - $port = getenv('APACHE_PORT'); - if ($port === false) { - $config = $this->GetConfig(); - if (!isset($config['apache_port']) || $config['apache_port'] === '') { - $config['apache_port'] = '443'; - } - return $config['apache_port']; - } else { - if(file_exists(DataConst::GetConfigFile())) { - $config = $this->GetConfig(); - if (!isset($config['apache_port'])) { - $config['apache_port'] = ''; - } - if ($port !== $config['apache_port']) { - $config['apache_port'] = $port; - $this->WriteConfig($config); - } - } - return $port; - } + $envVariableName = 'APACHE_PORT'; + $configName = 'apache_port'; + $defaultValue = '443'; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } /** @@ -297,6 +281,29 @@ class ConfigurationManager file_put_contents(DataConst::GetConfigFile(), json_encode($config)); } + private function GetEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string { + $envVariableOutput = getenv($envVariableName); + if ($envVariableOutput === false) { + $config = $this->GetConfig(); + if (!isset($config[$configName]) || $config[$configName] === '') { + $config[$configName] = $defaultValue; + } + return $config[$configName]; + } else { + if(file_exists(DataConst::GetConfigFile())) { + $config = $this->GetConfig(); + if (!isset($config[$configName])) { + $config[$configName] = ''; + } + if ($envVariableOutput !== $config[$configName]) { + $config[$configName] = $envVariableOutput; + $this->WriteConfig($config); + } + } + return $envVariableOutput; + } + } + public function GetBorgBackupHostLocation() : string { $config = $this->GetConfig(); if(!isset($config['borg_backup_host_location'])) { @@ -316,48 +323,16 @@ class ConfigurationManager } public function GetNextcloudMount() : string { - $mount = getenv('NEXTCLOUD_MOUNT'); - if ($mount === false) { - $config = $this->GetConfig(); - if (!isset($config['nextcloud_mount'])) { - $config['nextcloud_mount'] = ''; - } - return $config['nextcloud_mount']; - } else { - if(file_exists(DataConst::GetConfigFile())) { - $config = $this->GetConfig(); - if (!isset($config['nextcloud_mount'])) { - $config['nextcloud_mount'] = ''; - } - if ($mount !== $config['nextcloud_mount']) { - $config['nextcloud_mount'] = $mount; - $this->WriteConfig($config); - } - } - return $mount; - } + $envVariableName = 'NEXTCLOUD_MOUNT'; + $configName = 'nextcloud_mount'; + $defaultValue = ''; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } public function GetNextcloudDatadirMount() : string { - $mount = getenv('NEXTCLOUD_DATADIR'); - if ($mount === false) { - $config = $this->GetConfig(); - if (!isset($config['nextcloud_datadir']) || $config['nextcloud_datadir'] === '') { - $config['nextcloud_datadir'] = 'nextcloud_aio_nextcloud_data'; - } - return $config['nextcloud_datadir']; - } else { - if(file_exists(DataConst::GetConfigFile())) { - $config = $this->GetConfig(); - if (!isset($config['nextcloud_datadir'])) { - $config['nextcloud_datadir'] = ''; - } - if ($mount !== $config['nextcloud_datadir']) { - $config['nextcloud_datadir'] = $mount; - $this->WriteConfig($config); - } - } - return $mount; - } + $envVariableName = 'NEXTCLOUD_DATADIR'; + $configName = 'nextcloud_datadir'; + $defaultValue = 'nextcloud_aio_nextcloud_data'; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } }