mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 06:26:57 +00:00
Merge pull request #348 from nextcloud/enh/noid/refactor-some-logic
refactor some config logic
This commit is contained in:
commit
cd00e5af83
1 changed files with 34 additions and 60 deletions
|
|
@ -265,26 +265,10 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetApachePort() : string {
|
public function GetApachePort() : string {
|
||||||
$port = getenv('APACHE_PORT');
|
$envVariableName = 'APACHE_PORT';
|
||||||
if ($port === false) {
|
$configName = 'apache_port';
|
||||||
$config = $this->GetConfig();
|
$defaultValue = '443';
|
||||||
if (!isset($config['apache_port']) || $config['apache_port'] === '') {
|
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -297,6 +281,28 @@ class ConfigurationManager
|
||||||
file_put_contents(DataConst::GetConfigFile(), json_encode($config));
|
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];
|
||||||
|
}
|
||||||
|
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 {
|
public function GetBorgBackupHostLocation() : string {
|
||||||
$config = $this->GetConfig();
|
$config = $this->GetConfig();
|
||||||
if(!isset($config['borg_backup_host_location'])) {
|
if(!isset($config['borg_backup_host_location'])) {
|
||||||
|
|
@ -316,48 +322,16 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetNextcloudMount() : string {
|
public function GetNextcloudMount() : string {
|
||||||
$mount = getenv('NEXTCLOUD_MOUNT');
|
$envVariableName = 'NEXTCLOUD_MOUNT';
|
||||||
if ($mount === false) {
|
$configName = 'nextcloud_mount';
|
||||||
$config = $this->GetConfig();
|
$defaultValue = '';
|
||||||
if (!isset($config['nextcloud_mount'])) {
|
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetNextcloudDatadirMount() : string {
|
public function GetNextcloudDatadirMount() : string {
|
||||||
$mount = getenv('NEXTCLOUD_DATADIR');
|
$envVariableName = 'NEXTCLOUD_DATADIR';
|
||||||
if ($mount === false) {
|
$configName = 'nextcloud_datadir';
|
||||||
$config = $this->GetConfig();
|
$defaultValue = 'nextcloud_aio_nextcloud_data';
|
||||||
if (!isset($config['nextcloud_datadir']) || $config['nextcloud_datadir'] === '') {
|
return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue);
|
||||||
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue