Compare commits

...

2 commits

Author SHA1 Message Date
Pablo Zmdl
def99d66f8 Fix syntax errors
Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
2026-01-07 18:15:30 +01:00
Pablo Zmdl
104a847d03 Use property hooks to replace classic getter and setter methods.
Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
2026-01-07 18:08:29 +01:00
6 changed files with 91 additions and 165 deletions

View file

@ -103,7 +103,7 @@ $app->get('/containers', function (Request $request, Response $response, array $
'has_backup_run_once' => $configurationManager->hasBackupRunOnce(),
'is_backup_container_running' => $dockerActionManager->isBackupContainerRunning(),
'backup_exit_code' => $dockerActionManager->GetBackupcontainerExitCode(),
'is_instance_restore_attempt' => $configurationManager->isInstanceRestoreAttempt(),
'is_instance_restore_attempt' => $configurationManager->instanceRestoreAttempt,
'borg_backup_mode' => $configurationManager->GetBackupMode(),
'was_start_button_clicked' => $configurationManager->wasStartButtonClicked(),
'has_update_available' => $dockerActionManager->isAnyUpdateAvailable(),
@ -135,8 +135,8 @@ $app->get('/containers', function (Request $request, Response $response, array $
'is_dri_device_enabled' => $configurationManager->isDriDeviceEnabled(),
'is_nvidia_gpu_enabled' => $configurationManager->isNvidiaGpuEnabled(),
'is_talk_recording_enabled' => $configurationManager->isTalkRecordingEnabled(),
'is_docker_socket_proxy_enabled' => $configurationManager->isDockerSocketProxyEnabled(),
'is_whiteboard_enabled' => $configurationManager->isWhiteboardEnabled(),
'is_docker_socket_proxy_enabled' => $configurationManager->isDockerSocketProxyEnabled,
'is_whiteboard_enabled' => $configurationManager->isWhiteboardEnabled,
'community_containers' => $configurationManager->listAvailableCommunityContainers(),
'community_containers_enabled' => $configurationManager->GetEnabledCommunityContainers(),
'bypass_container_update' => $bypass_container_update,

View file

@ -87,11 +87,11 @@ readonly class ContainerDefinitionFetcher {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-docker-socket-proxy') {
if (!$this->configurationManager->isDockerSocketProxyEnabled()) {
if (!$this->configurationManager->isDockerSocketProxyEnabled) {
continue;
}
} elseif ($entry['container_name'] === 'nextcloud-aio-whiteboard') {
if (!$this->configurationManager->isWhiteboardEnabled()) {
if (!$this->configurationManager->isWhiteboardEnabled) {
continue;
}
}
@ -196,11 +196,11 @@ readonly class ContainerDefinitionFetcher {
continue;
}
} elseif ($value === 'nextcloud-aio-docker-socket-proxy') {
if (!$this->configurationManager->isDockerSocketProxyEnabled()) {
if (!$this->configurationManager->isDockerSocketProxyEnabled) {
continue;
}
} elseif ($value === 'nextcloud-aio-whiteboard') {
if (!$this->configurationManager->isWhiteboardEnabled()) {
if (!$this->configurationManager->isWhiteboardEnabled) {
continue;
}
}

View file

@ -114,16 +114,8 @@ readonly class ConfigurationController {
} else {
$this->configurationManager->SetFulltextsearchEnabledState(0);
}
if (isset($request->getParsedBody()['docker-socket-proxy'])) {
$this->configurationManager->SetDockerSocketProxyEnabledState(1);
} else {
$this->configurationManager->SetDockerSocketProxyEnabledState(0);
}
if (isset($request->getParsedBody()['whiteboard'])) {
$this->configurationManager->SetWhiteboardEnabledState(1);
} else {
$this->configurationManager->SetWhiteboardEnabledState(0);
}
$this->configurationManager->isDockerSocketProxyEnabled = isset($request->getParsedBody()['docker-socket-proxy']);
$this->configurationManager->isWhiteboardEnabled = isset($request->getParsedBody()['whiteboard']);
}
if (isset($request->getParsedBody()['community-form'])) {

View file

@ -123,15 +123,9 @@ readonly class DockerController {
}
public function StartBackupContainerRestore(Request $request, Response $response, array $args) : Response {
$this->configurationManager->SetBackupMode('restore');
$config = $this->configurationManager->GetConfig();
$config['selected-restore-time'] = $request->getParsedBody()['selected_restore_time'] ?? '';
if (isset($request->getParsedBody()['restore-exclude-previews'])) {
$config['restore-exclude-previews'] = 1;
} else {
$config['restore-exclude-previews'] = '';
}
$this->configurationManager->WriteConfig($config);
$this->configurationManager->backupMode = 'restore';
$this->configurationManager->selectedRestoreTime = $request->getParsedBody()['selected_restore_time'] ?? '';
$this->configurationManager->restoreExcludePreviews = isset($request->getParsedBody()['restore-exclude-previews']);
$id = self::TOP_CONTAINER;
$forceStopNextcloud = true;
@ -144,22 +138,20 @@ readonly class DockerController {
}
public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response {
$this->configurationManager->SetBackupMode('check-repair');
$this->configurationManager->backupMode = 'check-repair';
$id = 'nextcloud-aio-borgbackup';
$this->PerformRecursiveContainerStart($id);
// Restore to backup check which is needed to make the UI logic work correctly
$this->configurationManager->SetBackupMode('check');
$this->configurationManager->backupMode = 'check';
return $response->withStatus(201)->withHeader('Location', '.');
}
public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response {
$this->configurationManager->SetBackupMode('test');
$config = $this->configurationManager->GetConfig();
$config['instance_restore_attempt'] = 0;
$this->configurationManager->WriteConfig($config);
$this->configurationManager->backupMode = 'test';
$this->configurationManager->instanceRestoreAttempt = 0;
$id = self::TOP_CONTAINER;
$this->PerformRecursiveContainerStop($id);
@ -181,20 +173,12 @@ readonly class DockerController {
$port = 443;
}
if (isset($request->getParsedBody()['install_latest_major'])) {
$installLatestMajor = 32;
} else {
$installLatestMajor = "";
}
$config = $this->configurationManager->GetConfig();
// set AIO_URL
$config['AIO_URL'] = $host . ':' . (string)$port . $path;
// set wasStartButtonClicked
$config['wasStartButtonClicked'] = 1;
// set install_latest_major
$config['install_latest_major'] = $installLatestMajor;
$this->configurationManager->WriteConfig($config);
$this->configurationManager->installLatestMajor = isset($request->getParsedBody()['install_latest_major']);
// set AIO_URL
$this->configurationManager->aioUrl = $host . ':' . (string)$port . $path;
// set wasStartButtonClicked
$this->configurationManager->wasStartButtonClicked = true;
// Do not pull container images in case 'bypass_container_update' is set via url params
// Needed for local testing
@ -213,10 +197,7 @@ readonly class DockerController {
}
public function startTopContainer(bool $pullImage) : void {
$config = $this->configurationManager->GetConfig();
// set AIO_TOKEN
$config['AIO_TOKEN'] = bin2hex(random_bytes(24));
$this->configurationManager->WriteConfig($config);
$this->configurationManager->aioToken = bin2hex(random_bytes(24));
// Stop domaincheck since apache would not be able to start otherwise
$this->StopDomaincheckContainer();

View file

@ -9,7 +9,62 @@ class ConfigurationManager
{
private array $secrets = [];
public function GetConfig() : array
public string $password {
get => $this->GetConfig()['password'];
set { $this->set(['password' => $value]); }
}
public string $aioToken {
get => $this->get('AIO_TOKEN');
set { $this->set(['AIO_TOKEN' => $value]); }
}
public bool $isDockerSocketProxyEnabled {
get => $this->get('isDockerSocketProxyEnabled', false);
set { $this->set(['isDockerSocketProxyEnabled' => $value]); }
}
public bool $isWhiteboardEnabled {
get => $this->get('isWhiteboardEnabled', true);
set { $this->set(['isWhiteboardEnabled' => $value]); }
}
public bool $restoreExcludePreviews {
get => $this->get('restore-exclude-previews', false);
set { $this->set(['restore-exclude-previews' => $value]); }
}
public string $selectedRestoreTime {
get => $this->get('selected-restore-time', '');
set { $this->set(['selected-restore-time' => $value]); }
}
public string $backupMode {
get => $this->get('backup-mode', '');
set { $this->set(['backup-mode' => $value]); }
}
public bool $instanceRestoreAttempt {
get => $this->get('instance_restore_attempt', false);
set { $this->set(['instance_restore_attempt' => $value]); }
}
public string $aioUrl {
get => $this->get('AIO_URL', '');
set { $this->set(['AIO_URL' => $value]); }
}
public bool $wasStartButtonClicked {
get => $this->get('wasStartButtonClicked', false);
set { $this->set(['wasStartButtonClicked' => $value]); }
}
public bool $installLatestMajor {
get => $this->get('install_latest_major', false);
set { $this->set(['install_latest_major' => $value]); }
}
private function GetConfig() : array
{
if(file_exists(DataConst::GetConfigFile()))
{
@ -20,20 +75,18 @@ class ConfigurationManager
return [];
}
public function GetPassword() : string {
return $this->GetConfig()['password'];
}
public function GetToken() : string {
return $this->GetConfig()['AIO_TOKEN'];
}
public function SetPassword(string $password) : void {
private function set(array $keyValuePairs) {
$config = $this->GetConfig();
$config['password'] = $password;
foreach ($keyValuePairs as $key => $value) {
$config[$key] = $value;
}
$this->WriteConfig($config);
}
private function get(string $key, mixed $fallbackValue = null) {
return $this->GetConfig()[$key] ?? $fallbackValue;
}
public function GetAndGenerateSecret(string $secretId) : string {
if ($secretId === '') {
return '';
@ -122,14 +175,6 @@ class ConfigurationManager
return $backupTimes;
}
public function wasStartButtonClicked() : bool {
if (isset($this->GetConfig()['wasStartButtonClicked'])) {
return true;
} else {
return false;
}
}
private function isx64Platform() : bool {
if (php_uname('m') === 'x86_64') {
return true;
@ -147,36 +192,6 @@ class ConfigurationManager
}
}
public function isDockerSocketProxyEnabled() : bool {
$config = $this->GetConfig();
if (isset($config['isDockerSocketProxyEnabled']) && $config['isDockerSocketProxyEnabled'] === 1) {
return true;
} else {
return false;
}
}
public function SetDockerSocketProxyEnabledState(int $value) : void {
$config = $this->GetConfig();
$config['isDockerSocketProxyEnabled'] = $value;
$this->WriteConfig($config);
}
public function isWhiteboardEnabled() : bool {
$config = $this->GetConfig();
if (isset($config['isWhiteboardEnabled']) && $config['isWhiteboardEnabled'] === 0) {
return false;
} else {
return true;
}
}
public function SetWhiteboardEnabledState(int $value) : void {
$config = $this->GetConfig();
$config['isWhiteboardEnabled'] = $value;
$this->WriteConfig($config);
}
public function SetClamavEnabledState(int $value) : void {
$config = $this->GetConfig();
$config['isClamavEnabled'] = $value;
@ -417,48 +432,6 @@ class ConfigurationManager
return 'dc=' . implode(',dc=', explode('.', $domain));
}
public function GetBackupMode() : string {
$config = $this->GetConfig();
if(!isset($config['backup-mode'])) {
$config['backup-mode'] = '';
}
return $config['backup-mode'];
}
public function SetBackupMode(string $mode) : void {
$config = $this->GetConfig();
$config['backup-mode'] = $mode;
$this->WriteConfig($config);
}
public function GetSelectedRestoreTime() : string {
$config = $this->GetConfig();
if(!isset($config['selected-restore-time'])) {
$config['selected-restore-time'] = '';
}
return $config['selected-restore-time'];
}
public function GetRestoreExcludePreviews() : string {
$config = $this->GetConfig();
if(!isset($config['restore-exclude-previews'])) {
$config['restore-exclude-previews'] = '';
}
return $config['restore-exclude-previews'];
}
public function GetAIOURL() : string {
$config = $this->GetConfig();
if(!isset($config['AIO_URL'])) {
$config['AIO_URL'] = '';
}
return $config['AIO_URL'];
}
/**
* @throws InvalidSettingConfigurationException
*/
@ -669,18 +642,6 @@ class ConfigurationManager
return $config['borg_restore_password'];
}
public function isInstanceRestoreAttempt() : bool {
$config = $this->GetConfig();
if(!isset($config['instance_restore_attempt'])) {
$config['instance_restore_attempt'] = '';
}
if ($config['instance_restore_attempt'] === 1) {
return true;
}
return false;
}
public function GetNextcloudMount() : string {
$envVariableName = 'NEXTCLOUD_MOUNT';
$configName = 'nextcloud_mount';
@ -862,14 +823,6 @@ class ConfigurationManager
}
}
public function shouldLatestMajorGetInstalled() : bool {
$config = $this->GetConfig();
if(!isset($config['install_latest_major'])) {
$config['install_latest_major'] = '';
}
return $config['install_latest_major'] !== '';
}
public function GetAdditionalBackupDirectoriesString() : string {
if (!file_exists(DataConst::GetAdditionalBackupDirectoriesFile())) {
return '';

View file

@ -544,12 +544,12 @@ readonly class DockerActionManager {
return match ($placeholder) {
'NC_DOMAIN' => $this->configurationManager->GetDomain(),
'NC_BASE_DN' => $this->configurationManager->GetBaseDN(),
'AIO_TOKEN' => $this->configurationManager->GetToken(),
'AIO_TOKEN' => $this->configurationManager->aioToken,
'BORGBACKUP_REMOTE_REPO' => $this->configurationManager->GetBorgRemoteRepo(),
'BORGBACKUP_MODE' => $this->configurationManager->GetBackupMode(),
'AIO_URL' => $this->configurationManager->GetAIOURL(),
'SELECTED_RESTORE_TIME' => $this->configurationManager->GetSelectedRestoreTime(),
'RESTORE_EXCLUDE_PREVIEWS' => $this->configurationManager->GetRestoreExcludePreviews(),
'SELECTED_RESTORE_TIME' => $this->configurationManager->selectedRestoreTime,
'RESTORE_EXCLUDE_PREVIEWS' => $this->configurationManager->restoreExcludePreviews ? '1' : '',
'APACHE_PORT' => $this->configurationManager->GetApachePort(),
'APACHE_IP_BINDING' => $this->configurationManager->GetApacheIPBinding(),
'TALK_PORT' => $this->configurationManager->GetTalkPort(),
@ -566,7 +566,7 @@ readonly class DockerActionManager {
'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' : '',
'FULLTEXTSEARCH_ENABLED' => $this->configurationManager->isFulltextsearchEnabled() ? 'yes' : '',
'DOCKER_SOCKET_PROXY_ENABLED' => $this->configurationManager->isDockerSocketProxyEnabled() ? 'yes' : '',
'DOCKER_SOCKET_PROXY_ENABLED' => $this->configurationManager->isDockerSocketProxyEnabled ? 'yes' : '',
'NEXTCLOUD_UPLOAD_LIMIT' => $this->configurationManager->GetNextcloudUploadLimit(),
'NEXTCLOUD_MEMORY_LIMIT' => $this->configurationManager->GetNextcloudMemoryLimit(),
'NEXTCLOUD_MAX_TIME' => $this->configurationManager->GetNextcloudMaxTime(),
@ -580,7 +580,7 @@ readonly class DockerActionManager {
'NEXTCLOUD_STARTUP_APPS' => $this->configurationManager->GetNextcloudStartupApps(),
'NEXTCLOUD_ADDITIONAL_APKS' => $this->configurationManager->GetNextcloudAdditionalApks(),
'NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS' => $this->configurationManager->GetNextcloudAdditionalPhpExtensions(),
'INSTALL_LATEST_MAJOR' => $this->configurationManager->shouldLatestMajorGetInstalled() ? 'yes' : '',
'INSTALL_LATEST_MAJOR' => $this->configurationManager->installLatestMajor ? 'yes' : '',
'REMOVE_DISABLED_APPS' => $this->configurationManager->shouldDisabledAppsGetRemoved() ? 'yes' : '',
// Allow to get local ip-address of database container which allows to talk to it even in host mode (the container that requires this needs to be started first then)
'AIO_DATABASE_HOST' => gethostbyname('nextcloud-aio-database'),