mirror of
https://github.com/nextcloud/all-in-one.git
synced 2026-02-04 04:56:52 +00:00
Trigger config saving manually and add more setter methods
This requires some additional code lines but allows the calling code to group calls to setter methods and only save them at once. Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
parent
e8d1bce4f6
commit
fa50f5c141
4 changed files with 127 additions and 105 deletions
|
|
@ -162,6 +162,8 @@ readonly class ConfigurationController {
|
||||||
$this->configurationManager->DeleteBorgBackupLocationItems();
|
$this->configurationManager->DeleteBorgBackupLocationItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
return $response->withStatus(201)->withHeader('Location', '.');
|
return $response->withStatus(201)->withHeader('Location', '.');
|
||||||
} catch (InvalidSettingConfigurationException $ex) {
|
} catch (InvalidSettingConfigurationException $ex) {
|
||||||
$response->getBody()->write($ex->getMessage());
|
$response->getBody()->write($ex->getMessage());
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ readonly class DockerController {
|
||||||
|
|
||||||
public function startBackup(bool $forceStopNextcloud = false) : void {
|
public function startBackup(bool $forceStopNextcloud = false) : void {
|
||||||
$this->configurationManager->SetBackupMode('backup');
|
$this->configurationManager->SetBackupMode('backup');
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
|
$this->PerformRecursiveContainerStop($id, $forceStopNextcloud);
|
||||||
|
|
@ -110,6 +111,7 @@ readonly class DockerController {
|
||||||
|
|
||||||
public function checkBackup() : void {
|
public function checkBackup() : void {
|
||||||
$this->configurationManager->SetBackupMode('check');
|
$this->configurationManager->SetBackupMode('check');
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
@ -117,6 +119,7 @@ readonly class DockerController {
|
||||||
|
|
||||||
private function listBackup() : void {
|
private function listBackup() : void {
|
||||||
$this->configurationManager->SetBackupMode('list');
|
$this->configurationManager->SetBackupMode('list');
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
@ -124,14 +127,13 @@ 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();
|
$this->configurationManager->setSelectedRestoreTime($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;
|
$this->configurationManager->setRestoreExcludePreviews(1);
|
||||||
} else {
|
} else {
|
||||||
$config['restore-exclude-previews'] = '';
|
$this->configurationManager->setRestoreExcludePreviews('');
|
||||||
}
|
}
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->save();
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$forceStopNextcloud = true;
|
$forceStopNextcloud = true;
|
||||||
|
|
@ -145,21 +147,22 @@ readonly class DockerController {
|
||||||
|
|
||||||
public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response {
|
public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response {
|
||||||
$this->configurationManager->SetBackupMode('check-repair');
|
$this->configurationManager->SetBackupMode('check-repair');
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
||||||
// Restore to backup check which is needed to make the UI logic work correctly
|
// Restore to backup check which is needed to make the UI logic work correctly
|
||||||
$this->configurationManager->SetBackupMode('check');
|
$this->configurationManager->SetBackupMode('check');
|
||||||
|
$this->configurationManager->save();
|
||||||
|
|
||||||
return $response->withStatus(201)->withHeader('Location', '.');
|
return $response->withStatus(201)->withHeader('Location', '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
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->setNoInstanceRestoreAttempt();
|
||||||
$config['instance_restore_attempt'] = 0;
|
$this->configurationManager->save();
|
||||||
$this->configurationManager->WriteConfig($config);
|
|
||||||
|
|
||||||
$id = self::TOP_CONTAINER;
|
$id = self::TOP_CONTAINER;
|
||||||
$this->PerformRecursiveContainerStop($id);
|
$this->PerformRecursiveContainerStop($id);
|
||||||
|
|
@ -187,14 +190,10 @@ readonly class DockerController {
|
||||||
$installLatestMajor = "";
|
$installLatestMajor = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->configurationManager->GetConfig();
|
$this->configurationManager->setAIOURL($host . ':' . (string)$port . $path);
|
||||||
// set AIO_URL
|
$this->configurationManager->startButtonWasClicked();
|
||||||
$config['AIO_URL'] = $host . ':' . (string)$port . $path;
|
$this->configurationManager->setInstallLatestMajor($installLatestMajor);
|
||||||
// set wasStartButtonClicked
|
$this->configurationManager->save();
|
||||||
$config['wasStartButtonClicked'] = 1;
|
|
||||||
// set install_latest_major
|
|
||||||
$config['install_latest_major'] = $installLatestMajor;
|
|
||||||
$this->configurationManager->WriteConfig($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 +212,8 @@ readonly class DockerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function startTopContainer(bool $pullImage) : void {
|
public function startTopContainer(bool $pullImage) : void {
|
||||||
$config = $this->configurationManager->GetConfig();
|
$this->configurationManager->setToken(bin2hex(random_bytes(24)));
|
||||||
// set AIO_TOKEN
|
$this->configurationManager->save();
|
||||||
$config['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,15 +9,20 @@ class ConfigurationManager
|
||||||
{
|
{
|
||||||
private array $secrets = [];
|
private array $secrets = [];
|
||||||
|
|
||||||
public function GetConfig() : array
|
// Store the config on the instance, so multiple setter methods can change the config without writing the
|
||||||
|
// config file in between those changes.
|
||||||
|
private array $config = [];
|
||||||
|
|
||||||
|
private function GetConfig() : array
|
||||||
{
|
{
|
||||||
if(file_exists(DataConst::GetConfigFile()))
|
// Only load the config from disk if it's not present, yet.
|
||||||
|
if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
|
||||||
{
|
{
|
||||||
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
|
$configContent = (string)file_get_contents(DataConst::GetConfigFile());
|
||||||
return json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
|
$this->config = json_decode($configContent, true, 512, JSON_THROW_ON_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return $this->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetPassword() : string {
|
public function GetPassword() : string {
|
||||||
|
|
@ -28,10 +33,14 @@ class ConfigurationManager
|
||||||
return $this->GetConfig()['AIO_TOKEN'];
|
return $this->GetConfig()['AIO_TOKEN'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setToken(string $token) : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['AIO_TOKEN'] = $token;
|
||||||
|
}
|
||||||
|
|
||||||
public function SetPassword(string $password) : void {
|
public function SetPassword(string $password) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['password'] = $password;
|
$this->config['password'] = $password;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetAndGenerateSecret(string $secretId) : string {
|
public function GetAndGenerateSecret(string $secretId) : string {
|
||||||
|
|
@ -39,17 +48,17 @@ class ConfigurationManager
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
if(!isset($config['secrets'][$secretId])) {
|
if(!isset($this->config['secrets'][$secretId])) {
|
||||||
$config['secrets'][$secretId] = bin2hex(random_bytes(24));
|
$this->config['secrets'][$secretId] = bin2hex(random_bytes(24));
|
||||||
$this->WriteConfig($config);
|
$this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($secretId === 'BORGBACKUP_PASSWORD' && !file_exists(DataConst::GetBackupSecretFile())) {
|
if ($secretId === 'BORGBACKUP_PASSWORD' && !file_exists(DataConst::GetBackupSecretFile())) {
|
||||||
$this->DoubleSafeBackupSecret($config['secrets'][$secretId]);
|
$this->DoubleSafeBackupSecret($this->config['secrets'][$secretId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $config['secrets'][$secretId];
|
return $this->config['secrets'][$secretId];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRegisteredSecret(string $secretId) : string {
|
public function GetRegisteredSecret(string $secretId) : string {
|
||||||
|
|
@ -130,6 +139,11 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function startButtonWasClicked() : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['wasStartButtonClicked'] = '1';
|
||||||
|
}
|
||||||
|
|
||||||
private function isx64Platform() : bool {
|
private function isx64Platform() : bool {
|
||||||
if (php_uname('m') === 'x86_64') {
|
if (php_uname('m') === 'x86_64') {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -157,9 +171,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetDockerSocketProxyEnabledState(int $value) : void {
|
public function SetDockerSocketProxyEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isDockerSocketProxyEnabled'] = $value;
|
$this->config['isDockerSocketProxyEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isWhiteboardEnabled() : bool {
|
public function isWhiteboardEnabled() : bool {
|
||||||
|
|
@ -172,15 +185,13 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetWhiteboardEnabledState(int $value) : void {
|
public function SetWhiteboardEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isWhiteboardEnabled'] = $value;
|
$this->config['isWhiteboardEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetClamavEnabledState(int $value) : void {
|
public function SetClamavEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isClamavEnabled'] = $value;
|
$this->config['isClamavEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isImaginaryEnabled() : bool {
|
public function isImaginaryEnabled() : bool {
|
||||||
|
|
@ -193,9 +204,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetImaginaryEnabledState(int $value) : void {
|
public function SetImaginaryEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isImaginaryEnabled'] = $value;
|
$this->config['isImaginaryEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isFulltextsearchEnabled() : bool {
|
public function isFulltextsearchEnabled() : bool {
|
||||||
|
|
@ -213,9 +223,8 @@ class ConfigurationManager
|
||||||
$value = 0;
|
$value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isFulltextsearchEnabled'] = $value;
|
$this->config['isFulltextsearchEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isOnlyofficeEnabled() : bool {
|
public function isOnlyofficeEnabled() : bool {
|
||||||
|
|
@ -228,9 +237,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetOnlyofficeEnabledState(int $value) : void {
|
public function SetOnlyofficeEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isOnlyofficeEnabled'] = $value;
|
$this->config['isOnlyofficeEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCollaboraEnabled() : bool {
|
public function isCollaboraEnabled() : bool {
|
||||||
|
|
@ -243,9 +251,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetCollaboraEnabledState(int $value) : void {
|
public function SetCollaboraEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isCollaboraEnabled'] = $value;
|
$this->config['isCollaboraEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTalkEnabled() : bool {
|
public function isTalkEnabled() : bool {
|
||||||
|
|
@ -258,9 +265,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetTalkEnabledState(int $value) : void {
|
public function SetTalkEnabledState(int $value) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isTalkEnabled'] = $value;
|
$this->config['isTalkEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isTalkRecordingEnabled() : bool {
|
public function isTalkRecordingEnabled() : bool {
|
||||||
|
|
@ -280,9 +286,8 @@ class ConfigurationManager
|
||||||
$value = 0;
|
$value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['isTalkRecordingEnabled'] = $value;
|
$this->config['isTalkRecordingEnabled'] = $value;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -392,12 +397,11 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->GetConfig();
|
||||||
// Write domain
|
// Write domain
|
||||||
$config = $this->GetConfig();
|
$this->config['domain'] = $domain;
|
||||||
$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'] = '';
|
$this->config['borg_restore_password'] = '';
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetDomain() : string {
|
public function GetDomain() : string {
|
||||||
|
|
@ -427,9 +431,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetBackupMode(string $mode) : void {
|
public function SetBackupMode(string $mode) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['backup-mode'] = $mode;
|
$this->config['backup-mode'] = $mode;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSelectedRestoreTime() : string {
|
public function GetSelectedRestoreTime() : string {
|
||||||
|
|
@ -441,6 +444,11 @@ class ConfigurationManager
|
||||||
return $config['selected-restore-time'];
|
return $config['selected-restore-time'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSelectedRestoreTime(string $time) : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['selected-restore-time'] = $time;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetRestoreExcludePreviews() : string {
|
public function GetRestoreExcludePreviews() : string {
|
||||||
$config = $this->GetConfig();
|
$config = $this->GetConfig();
|
||||||
if(!isset($config['restore-exclude-previews'])) {
|
if(!isset($config['restore-exclude-previews'])) {
|
||||||
|
|
@ -450,6 +458,11 @@ class ConfigurationManager
|
||||||
return $config['restore-exclude-previews'];
|
return $config['restore-exclude-previews'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setRestoreExcludePreviews(mixed $value) : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['restore-exclude-previews'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetAIOURL() : string {
|
public function GetAIOURL() : string {
|
||||||
$config = $this->GetConfig();
|
$config = $this->GetConfig();
|
||||||
if(!isset($config['AIO_URL'])) {
|
if(!isset($config['AIO_URL'])) {
|
||||||
|
|
@ -459,16 +472,20 @@ class ConfigurationManager
|
||||||
return $config['AIO_URL'];
|
return $config['AIO_URL'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAIOURL(string $url) : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['AIO_URL'] = $host . ':' . (string)$port . $path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws InvalidSettingConfigurationException
|
* @throws InvalidSettingConfigurationException
|
||||||
*/
|
*/
|
||||||
public function SetBorgLocationVars(string $location, string $repo) : void {
|
public function SetBorgLocationVars(string $location, string $repo) : void {
|
||||||
$this->ValidateBorgLocationVars($location, $repo);
|
$this->ValidateBorgLocationVars($location, $repo);
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['borg_backup_host_location'] = $location;
|
$this->config['borg_backup_host_location'] = $location;
|
||||||
$config['borg_remote_repo'] = $repo;
|
$this->config['borg_remote_repo'] = $repo;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ValidateBorgLocationVars(string $location, string $repo) : void {
|
private function ValidateBorgLocationVars(string $location, string $repo) : void {
|
||||||
|
|
@ -514,10 +531,9 @@ class ConfigurationManager
|
||||||
|
|
||||||
public function DeleteBorgBackupLocationItems() : void {
|
public function DeleteBorgBackupLocationItems() : void {
|
||||||
// Delete the variables
|
// Delete the variables
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['borg_backup_host_location'] = '';
|
$this->config['borg_backup_host_location'] = '';
|
||||||
$config['borg_remote_repo'] = '';
|
$this->config['borg_remote_repo'] = '';
|
||||||
$this->WriteConfig($config);
|
|
||||||
|
|
||||||
// Also delete the borg config file to be able to start over
|
// Also delete the borg config file to be able to start over
|
||||||
if (file_exists(DataConst::GetBackupKeyFile())) {
|
if (file_exists(DataConst::GetBackupKeyFile())) {
|
||||||
|
|
@ -537,12 +553,11 @@ class ConfigurationManager
|
||||||
throw new InvalidSettingConfigurationException("Please enter the password!");
|
throw new InvalidSettingConfigurationException("Please enter the password!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['borg_backup_host_location'] = $location;
|
$this->config['borg_backup_host_location'] = $location;
|
||||||
$config['borg_remote_repo'] = $repo;
|
$this->config['borg_remote_repo'] = $repo;
|
||||||
$config['borg_restore_password'] = $password;
|
$this->config['borg_restore_password'] = $password;
|
||||||
$config['instance_restore_attempt'] = 1;
|
$this->config['instance_restore_attempt'] = 1;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -599,7 +614,7 @@ class ConfigurationManager
|
||||||
/**
|
/**
|
||||||
* @throws InvalidSettingConfigurationException
|
* @throws InvalidSettingConfigurationException
|
||||||
*/
|
*/
|
||||||
public function WriteConfig(array $config) : void {
|
public function save() : 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!");
|
||||||
}
|
}
|
||||||
|
|
@ -610,6 +625,9 @@ class ConfigurationManager
|
||||||
throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not have enough space for writing the config file! Not writing it back!");
|
throw new InvalidSettingConfigurationException(DataConst::GetDataDirectory() . " does not have enough space for writing the config file! Not writing it back!");
|
||||||
}
|
}
|
||||||
file_put_contents(DataConst::GetConfigFile(), $content);
|
file_put_contents(DataConst::GetConfigFile(), $content);
|
||||||
|
// Force reloading the config after it was written. It's not clear to me if keeping the config loaded
|
||||||
|
// might cause race conditions, e.g. in case multiple processes write to the file, so better safe than sorry.
|
||||||
|
$this->config = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {
|
private function GetEnvironmentalVariableOrConfig(string $envVariableName, string $configName, string $defaultValue) : string {
|
||||||
|
|
@ -627,8 +645,8 @@ class ConfigurationManager
|
||||||
$config[$configName] = '';
|
$config[$configName] = '';
|
||||||
}
|
}
|
||||||
if ($envVariableOutput !== $config[$configName]) {
|
if ($envVariableOutput !== $config[$configName]) {
|
||||||
$config[$configName] = $envVariableOutput;
|
$this->config[$configName] = $envVariableOutput;
|
||||||
$this->WriteConfig($config);
|
$this->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $envVariableOutput;
|
return $envVariableOutput;
|
||||||
|
|
@ -681,6 +699,12 @@ class ConfigurationManager
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setNoInstanceRestoreAttempt() : void
|
||||||
|
{
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['instance_restore_attempt'] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetNextcloudMount() : string {
|
public function GetNextcloudMount() : string {
|
||||||
$envVariableName = 'NEXTCLOUD_MOUNT';
|
$envVariableName = 'NEXTCLOUD_MOUNT';
|
||||||
$configName = 'nextcloud_mount';
|
$configName = 'nextcloud_mount';
|
||||||
|
|
@ -870,6 +894,11 @@ class ConfigurationManager
|
||||||
return $config['install_latest_major'] !== '';
|
return $config['install_latest_major'] !== '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setInstallLatestMajor(mixed $value) : void {
|
||||||
|
$this->GetConfig();
|
||||||
|
$this->config['install_latest_major'] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetAdditionalBackupDirectoriesString() : string {
|
public function GetAdditionalBackupDirectoriesString() : string {
|
||||||
if (!file_exists(DataConst::GetAdditionalBackupDirectoriesFile())) {
|
if (!file_exists(DataConst::GetAdditionalBackupDirectoriesFile())) {
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -912,15 +941,13 @@ class ConfigurationManager
|
||||||
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();
|
$this->GetConfig();
|
||||||
$config['timezone'] = $timezone;
|
$this->config['timezone'] = $timezone;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteTimezone() : void {
|
public function DeleteTimezone() : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['timezone'] = '';
|
$this->config['timezone'] = '';
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function shouldDomainValidationBeSkipped(bool $skipDomainValidation) : bool {
|
public function shouldDomainValidationBeSkipped(bool $skipDomainValidation) : bool {
|
||||||
|
|
@ -959,15 +986,13 @@ class ConfigurationManager
|
||||||
throw new InvalidSettingConfigurationException("The entered dictionaries do not seem to be a valid!");
|
throw new InvalidSettingConfigurationException("The entered dictionaries do not seem to be a valid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['collabora_dictionaries'] = $CollaboraDictionaries;
|
$this->config['collabora_dictionaries'] = $CollaboraDictionaries;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteCollaboraDictionaries() : void {
|
public function DeleteCollaboraDictionaries() : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['collabora_dictionaries'] = '';
|
$this->config['collabora_dictionaries'] = '';
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -982,9 +1007,8 @@ class ConfigurationManager
|
||||||
throw new InvalidSettingConfigurationException("The entered options must start with '--o:'. So the config does not seem to be a valid!");
|
throw new InvalidSettingConfigurationException("The entered options must start with '--o:'. So the config does not seem to be a valid!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['collabora_additional_options'] = $additionalCollaboraOptions;
|
$this->config['collabora_additional_options'] = $additionalCollaboraOptions;
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetAdditionalCollaboraOptions() : string {
|
public function GetAdditionalCollaboraOptions() : string {
|
||||||
|
|
@ -1004,9 +1028,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteAdditionalCollaboraOptions() : void {
|
public function DeleteAdditionalCollaboraOptions() : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['collabora_additional_options'] = '';
|
$this->config['collabora_additional_options'] = '';
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetApacheAdditionalNetwork() : string {
|
public function GetApacheAdditionalNetwork() : string {
|
||||||
|
|
@ -1089,9 +1112,8 @@ class ConfigurationManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetEnabledCommunityContainers(array $enabledCommunityContainers) : void {
|
public function SetEnabledCommunityContainers(array $enabledCommunityContainers) : void {
|
||||||
$config = $this->GetConfig();
|
$this->GetConfig();
|
||||||
$config['aio_community_containers'] = implode(' ', $enabledCommunityContainers);
|
$this->config['aio_community_containers'] = implode(' ', $enabledCommunityContainers);
|
||||||
$this->WriteConfig($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetEnabledDriDevice() : string {
|
private function GetEnabledDriDevice() : string {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ readonly class Setup {
|
||||||
|
|
||||||
$password = $this->passwordGenerator->GeneratePassword(8);
|
$password = $this->passwordGenerator->GeneratePassword(8);
|
||||||
$this->configurationManager->SetPassword($password);
|
$this->configurationManager->SetPassword($password);
|
||||||
|
$this->configurationManager->save();
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue