Refactor getPlaceholderValue to use match

Signed-off-by: Alan Savage <3028205+asavageiv@users.noreply.github.com>
This commit is contained in:
Alan Savage 2025-06-19 17:49:42 -07:00 committed by Simon L.
parent 026707240f
commit d374fd2c1c

View file

@ -498,162 +498,60 @@ readonly class DockerActionManager {
} }
private function getPlaceholderValue($placeholder) { private function getPlaceholderValue($placeholder) {
if ($placeholder === 'NC_DOMAIN') { return match ($placeholder) {
return $this->configurationManager->GetDomain(); 'NC_DOMAIN' => $this->configurationManager->GetDomain(),
} elseif ($placeholder === 'NC_BASE_DN') { 'NC_BASE_DN' => $this->configurationManager->GetBaseDN(),
return $this->configurationManager->GetBaseDN(); 'AIO_TOKEN' => $this->configurationManager->GetToken(),
} elseif ($placeholder === 'AIO_TOKEN') { 'BORGBACKUP_REMOTE_REPO' => $this->configurationManager->GetBorgRemoteRepo(),
return $this->configurationManager->GetToken(); 'BORGBACKUP_MODE' => $this->configurationManager->GetBackupMode(),
} elseif ($placeholder === 'BORGBACKUP_REMOTE_REPO') { 'AIO_URL' => $this->configurationManager->GetAIOURL(),
return $this->configurationManager->GetBorgRemoteRepo(); 'SELECTED_RESTORE_TIME' => $this->configurationManager->GetSelectedRestoreTime(),
} elseif ($placeholder === 'BORGBACKUP_MODE') { 'RESTORE_EXCLUDE_PREVIEWS' => $this->configurationManager->GetRestoreExcludePreviews(),
return $this->configurationManager->GetBackupMode(); 'APACHE_PORT' => $this->configurationManager->GetApachePort(),
} elseif ($placeholder === 'AIO_URL') { 'TALK_PORT' => $this->configurationManager->GetTalkPort(),
return $this->configurationManager->GetAIOURL(); 'NEXTCLOUD_MOUNT' => $this->configurationManager->GetNextcloudMount(),
} elseif ($placeholder === 'SELECTED_RESTORE_TIME') { 'BACKUP_RESTORE_PASSWORD' => $this->configurationManager->GetBorgRestorePassword(),
return $this->configurationManager->GetSelectedRestoreTime(); 'CLAMAV_ENABLED' => $this->configurationManager->isClamavEnabled() ? 'yes' : '',
} elseif ($placeholder === 'RESTORE_EXCLUDE_PREVIEWS') { 'TALK_RECORDING_ENABLED' => $this->configurationManager->isTalkRecordingEnabled() ? 'yes' : '',
return $this->configurationManager->GetRestoreExcludePreviews(); 'ONLYOFFICE_ENABLED' => $this->configurationManager->isOnlyofficeEnabled() ? 'yes' : '',
} elseif ($placeholder === 'APACHE_PORT') { 'COLLABORA_ENABLED' => $this->configurationManager->isCollaboraEnabled() ? 'yes' : '',
return $this->configurationManager->GetApachePort(); 'TALK_ENABLED' => $this->configurationManager->isTalkEnabled() ? 'yes' : '',
} elseif ($placeholder === 'TALK_PORT') { 'UPDATE_NEXTCLOUD_APPS' => ($this->configurationManager->isDailyBackupRunning() && $this->configurationManager->areAutomaticUpdatesEnabled()) ? 'yes' : '',
return $this->configurationManager->GetTalkPort(); 'TIMEZONE' => $this->configurationManager->GetTimezone() === '' ? 'Etc/UTC' : $this->configurationManager->GetTimezone(),
} elseif ($placeholder === 'NEXTCLOUD_MOUNT') { '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(),
return $this->configurationManager->GetNextcloudMount(); 'IMAGINARY_ENABLED' => $this->configurationManager->isImaginaryEnabled() ? 'yes' : '',
} elseif ($placeholder === 'BACKUP_RESTORE_PASSWORD') { 'FULLTEXTSEARCH_ENABLED' => $this->configurationManager->isFulltextsearchEnabled() ? 'yes' : '',
return $this->configurationManager->GetBorgRestorePassword(); 'DOCKER_SOCKET_PROXY_ENABLED' => $this->configurationManager->isDockerSocketProxyEnabled() ? 'yes' : '',
} elseif ($placeholder === 'CLAMAV_ENABLED') { 'NEXTCLOUD_UPLOAD_LIMIT' => $this->configurationManager->GetNextcloudUploadLimit(),
if ($this->configurationManager->isClamavEnabled()) { 'NEXTCLOUD_MEMORY_LIMIT' => $this->configurationManager->GetNextcloudMemoryLimit(),
return 'yes'; 'NEXTCLOUD_MAX_TIME' => $this->configurationManager->GetNextcloudMaxTime(),
} else { 'BORG_RETENTION_POLICY' => $this->configurationManager->GetBorgRetentionPolicy(),
return ''; 'FULLTEXTSEARCH_JAVA_OPTIONS' => $this->configurationManager->GetFulltextsearchJavaOptions(),
} 'NEXTCLOUD_TRUSTED_CACERTS_DIR' => $this->configurationManager->GetTrustedCacertsDir(),
} elseif ($placeholder === 'TALK_RECORDING_ENABLED') { 'ADDITIONAL_DIRECTORIES_BACKUP' => $this->configurationManager->GetAdditionalBackupDirectoriesString() !== '' ? 'yes' : '',
if ($this->configurationManager->isTalkRecordingEnabled()) { 'BORGBACKUP_HOST_LOCATION' => $this->configurationManager->GetBorgBackupHostLocation(),
return 'yes'; 'APACHE_MAX_SIZE' => $this->configurationManager->GetApacheMaxSize(),
} else { 'COLLABORA_SECCOMP_POLICY' => $this->configurationManager->GetCollaboraSeccompPolicy(),
return ''; 'NEXTCLOUD_STARTUP_APPS' => $this->configurationManager->GetNextcloudStartupApps(),
} 'NEXTCLOUD_ADDITIONAL_APKS' => $this->configurationManager->GetNextcloudAdditionalApks(),
} elseif ($placeholder === 'ONLYOFFICE_ENABLED') { 'NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS' => $this->configurationManager->GetNextcloudAdditionalPhpExtensions(),
if ($this->configurationManager->isOnlyofficeEnabled()) { 'INSTALL_LATEST_MAJOR' => $this->configurationManager->shouldLatestMajorGetInstalled() ? 'yes' : '',
return 'yes'; 'REMOVE_DISABLED_APPS' => $this->configurationManager->shouldDisabledAppsGetRemoved() ? 'yes' : '',
} else {
return '';
}
} elseif ($placeholder === 'COLLABORA_ENABLED') {
if ($this->configurationManager->isCollaboraEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'TALK_ENABLED') {
if ($this->configurationManager->isTalkEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'UPDATE_NEXTCLOUD_APPS') {
if ($this->configurationManager->isDailyBackupRunning() && $this->configurationManager->areAutomaticUpdatesEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'TIMEZONE') {
if ($this->configurationManager->GetTimezone() === '') {
return 'Etc/UTC';
} else {
return $this->configurationManager->GetTimezone();
}
} elseif ($placeholder === 'COLLABORA_DICTIONARIES') {
if ($this->configurationManager->GetCollaboraDictionaries() === '') {
return 'de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru';
} else {
return $this->configurationManager->GetCollaboraDictionaries();
}
} elseif ($placeholder === 'IMAGINARY_ENABLED') {
if ($this->configurationManager->isImaginaryEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'FULLTEXTSEARCH_ENABLED') {
if ($this->configurationManager->isFulltextsearchEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'DOCKER_SOCKET_PROXY_ENABLED') {
if ($this->configurationManager->isDockerSocketProxyEnabled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'NEXTCLOUD_UPLOAD_LIMIT') {
return $this->configurationManager->GetNextcloudUploadLimit();
} elseif ($placeholder === 'NEXTCLOUD_MEMORY_LIMIT') {
return $this->configurationManager->GetNextcloudMemoryLimit();
} elseif ($placeholder === 'NEXTCLOUD_MAX_TIME') {
return $this->configurationManager->GetNextcloudMaxTime();
} elseif ($placeholder === 'BORG_RETENTION_POLICY') {
return $this->configurationManager->GetBorgRetentionPolicy();
} elseif ($placeholder === 'FULLTEXTSEARCH_JAVA_OPTIONS') {
return $this->configurationManager->GetFulltextsearchJavaOptions();
} elseif ($placeholder === 'NEXTCLOUD_TRUSTED_CACERTS_DIR') {
return $this->configurationManager->GetTrustedCacertsDir();
} elseif ($placeholder === 'ADDITIONAL_DIRECTORIES_BACKUP') {
if ($this->configurationManager->GetAdditionalBackupDirectoriesString() !== '') {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'BORGBACKUP_HOST_LOCATION') {
return $this->configurationManager->GetBorgBackupHostLocation();
} elseif ($placeholder === 'APACHE_MAX_SIZE') {
return $this->configurationManager->GetApacheMaxSize();
} elseif ($placeholder === 'COLLABORA_SECCOMP_POLICY') {
return $this->configurationManager->GetCollaboraSeccompPolicy();
} elseif ($placeholder === 'NEXTCLOUD_STARTUP_APPS') {
return $this->configurationManager->GetNextcloudStartupApps();
} elseif ($placeholder === 'NEXTCLOUD_ADDITIONAL_APKS') {
return $this->configurationManager->GetNextcloudAdditionalApks();
} elseif ($placeholder === 'NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS') {
return $this->configurationManager->GetNextcloudAdditionalPhpExtensions();
} elseif ($placeholder === 'INSTALL_LATEST_MAJOR') {
if ($this->configurationManager->shouldLatestMajorGetInstalled()) {
return 'yes';
} else {
return '';
}
} elseif ($placeholder === 'REMOVE_DISABLED_APPS') {
if ($this->configurationManager->shouldDisabledAppsGetRemoved()) {
return 'yes';
} else {
return '';
}
// 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) // 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)
} elseif ($placeholder === 'AIO_DATABASE_HOST') { 'AIO_DATABASE_HOST' => gethostbyname('nextcloud-aio-database'),
return gethostbyname('nextcloud-aio-database');
// Allow to get local ip-address of caddy container and add it to trusted proxies automatically // Allow to get local ip-address of caddy container and add it to trusted proxies automatically
} elseif ($placeholder === 'CADDY_IP_ADDRESS') { 'CADDY_IP_ADDRESS' => in_array('caddy', $this->configurationManager->GetEnabledCommunityContainers(), true) ? gethostbyname('nextcloud-aio-caddy') : '',
$communityContainers = $this->configurationManager->GetEnabledCommunityContainers(); 'WHITEBOARD_ENABLED' => $this->configurationManager->isWhiteboardEnabled() ? 'yes' : '',
if (in_array('caddy', $communityContainers, true)) { default => $this->getSecretOrThrow($placeholder),
return gethostbyname('nextcloud-aio-caddy'); };
} else { }
return '';
} private function getSecretOrThrow($secretName) {
} elseif ($placeholder === 'WHITEBOARD_ENABLED') { $secret = $this->configurationManager->GetSecret($secretName);
if ($this->configurationManager->isWhiteboardEnabled()) { if ($secret === "") {
return 'yes'; throw new \Exception("The secret " . $secretName . " is empty. Cannot substitute its value. Please check if it is defined in secrets of containers.json.");
} else {
return '';
}
} else {
$secret = $this->configurationManager->GetSecret($placeholder);
if ($secret === "") {
throw new \Exception("The secret " . $placeholder . " is empty. Cannot substitute its value. Please check if it is defined in secrets of containers.json.");
}
return $secret;
} }
return $secret;
} }
private function isContainerUpdateAvailable(string $id): string { private function isContainerUpdateAvailable(string $id): string {