mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-02-16 18:50:20 +00:00
Private GetConfig and WriteConfig by providing generic set() method
This is the minimum required change that keeps the current behaviour to read the configuration file from disk before setting a value, and writes it back immediately after that. A second new method, setMultiple(), allows to set multiple values at once avoiding read/write-cycles in between. Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
parent
e8d1bce4f6
commit
7159bc68d3
3 changed files with 22 additions and 15 deletions
|
|
@ -124,14 +124,14 @@ readonly class DockerController {
|
||||||
|
|
||||||
public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response {
|
public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response {
|
||||||
$this->configurationManager->SetBackupMode('restore');
|
$this->configurationManager->SetBackupMode('restore');
|
||||||
$config = $this->configurationManager->GetConfig();
|
$config = [];
|
||||||
$config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? '';
|
$config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? '';
|
||||||
if (isset($request->getParsedBody()['restore-exclude-previews'])) {
|
if (isset($request->getParsedBody()['restore-exclude-previews'])) {
|
||||||
$config['restore-exclude-previews'] = 1;
|
$config['restore-exclude-previews'] = 1;
|
||||||
} else {
|
} else {
|
||||||
$config['restore-exclude-previews'] = '';
|
$config['restore-exclude-previews'] = '';
|
||||||
}
|
}
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->setMultiple($config);
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$forceStopNextcloud = true;
|
$forceStopNextcloud = true;
|
||||||
|
|
@ -157,9 +157,7 @@ readonly class DockerController {
|
||||||
|
|
||||||
public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response {
|
public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response {
|
||||||
$this->configurationManager->SetBackupMode('test');
|
$this->configurationManager->SetBackupMode('test');
|
||||||
$config = $this->configurationManager->GetConfig();
|
$this->configurationManager->set('instance_restore_attempt', 0);
|
||||||
$config['instance_restore_attempt'] = 0;
|
|
||||||
$this->configurationManager->WriteConfig($config);
|
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id);
|
$this->PerformRecursiveContainerStop($id);
|
||||||
|
|
@ -187,14 +185,14 @@ readonly class DockerController {
|
||||||
$installLatestMajor = "";
|
$installLatestMajor = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->configurationManager->GetConfig();
|
$config = [];
|
||||||
// set AIO_URL
|
// set AIO_URL
|
||||||
$config['AIO_URL'] = $host . ':' . (string)$port . $path;
|
$config['AIO_URL'] = $host . ':' . (string)$port . $path;
|
||||||
// set wasStartButtonClicked
|
// set wasStartButtonClicked
|
||||||
$config['wasStartButtonClicked'] = 1;
|
$config['wasStartButtonClicked'] = 1;
|
||||||
// set install_latest_major
|
// set install_latest_major
|
||||||
$config['install_latest_major'] = $installLatestMajor;
|
$config['install_latest_major'] = $installLatestMajor;
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->setMultiple($config);
|
||||||
|
|
||||||
// Do not pull container images in case 'bypass_container_update' is set via url params
|
// Do not pull container images in case 'bypass_container_update' is set via url params
|
||||||
// Needed for local testing
|
// Needed for local testing
|
||||||
|
|
@ -213,10 +211,8 @@ readonly class DockerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startTopContainer(bool $pullImage) : void {
|
public function startTopContainer(bool $pullImage) : void {
|
||||||
$config = $this->configurationManager->GetConfig();
|
|
||||||
// set AIO_TOKEN
|
// set AIO_TOKEN
|
||||||
$config['AIO_TOKEN'] = bin2hex(random_bytes(24));
|
$this->configurationManager->set('AIO_TOKEN', bin2hex(random_bytes(24)));
|
||||||
$this->configurationManager->WriteConfig($config);
|
|
||||||
|
|
||||||
// Stop domaincheck since apache would not be able to start otherwise
|
// Stop domaincheck since apache would not be able to start otherwise
|
||||||
$this->StopDomaincheckContainer();
|
$this->StopDomaincheckContainer();
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class ConfigurationManager
|
||||||
{
|
{
|
||||||
private array $secrets = [];
|
private array $secrets = [];
|
||||||
|
|
||||||
public function GetConfig() : array
|
private function GetConfig() : array
|
||||||
{
|
{
|
||||||
if(file_exists(DataConst::GetConfigFile()))
|
if(file_exists(DataConst::GetConfigFile()))
|
||||||
{
|
{
|
||||||
|
|
@ -20,6 +20,18 @@ class ConfigurationManager
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set(string $key, mixed $value) : void {
|
||||||
|
$this->setMultiple([$key => $value]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMultiple(array $keyValuePairs) : void {
|
||||||
|
$config = $this->GetConfig();
|
||||||
|
foreach ($keyValuePairs as $key => $value) {
|
||||||
|
$config[$key] = $value;
|
||||||
|
}
|
||||||
|
$this->WriteConfig($config);
|
||||||
|
}
|
||||||
|
|
||||||
public function GetPassword() : string {
|
public function GetPassword() : string {
|
||||||
return $this->GetConfig()['password'];
|
return $this->GetConfig()['password'];
|
||||||
}
|
}
|
||||||
|
|
@ -599,7 +611,7 @@ class ConfigurationManager
|
||||||
/**
|
/**
|
||||||
* @throws InvalidSettingConfigurationException
|
* @throws InvalidSettingConfigurationException
|
||||||
*/
|
*/
|
||||||
public function WriteConfig(array $config) : void {
|
private function WriteConfig(array $config) : void {
|
||||||
if(!is_dir(DataConst::GetDataDirectory())) {
|
if(!is_dir(DataConst::GetDataDirectory())) {
|
||||||
throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not exist! Something was set up falsely!");
|
throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not exist! Something was set up falsely!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,14 +229,13 @@ readonly class DockerActionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
$aioVariables = $container->GetAioVariables()->GetVariables();
|
$aioVariables = $container->GetAioVariables()->GetVariables();
|
||||||
|
$config = [];
|
||||||
foreach ($aioVariables as $variable) {
|
foreach ($aioVariables as $variable) {
|
||||||
$config = $this->configurationManager->GetConfig();
|
|
||||||
$variable = $this->replaceEnvPlaceholders($variable);
|
$variable = $this->replaceEnvPlaceholders($variable);
|
||||||
$variableArray = explode('=', $variable);
|
$variableArray = explode('=', $variable);
|
||||||
$config[$variableArray[0]] = $variableArray[1];
|
$config[$variableArray[0]] = $variableArray[1];
|
||||||
$this->configurationManager->WriteConfig($config);
|
|
||||||
sleep(1);
|
|
||||||
}
|
}
|
||||||
|
$this->configurationManager->setMultiple($config);
|
||||||
|
|
||||||
$envs = $container->GetEnvironmentVariables()->GetVariables();
|
$envs = $container->GetEnvironmentVariables()->GetVariables();
|
||||||
// Special thing for the nextcloud container
|
// Special thing for the nextcloud container
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue