From ec5d23fd584009865ef9168ed3c4504037b459d4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 19:22:10 +0000 Subject: [PATCH] refactor: deduplicate resolveHostname into DataConst Agent-Logs-Url: https://github.com/nextcloud/all-in-one/sessions/42427bd4-05e6-4197-bdb7-db3761815113 Co-authored-by: szaimen <42591237+szaimen@users.noreply.github.com> --- php/src/Data/ConfigurationManager.php | 21 ++------------------- php/src/Data/DataConst.php | 17 +++++++++++++++++ php/src/Docker/DockerActionManager.php | 19 +------------------ 3 files changed, 20 insertions(+), 37 deletions(-) diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index e57a2d90..a62fc621 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -1111,9 +1111,9 @@ class ConfigurationManager 'INSTALL_LATEST_MAJOR' => $this->installLatestMajor ? 'yes' : '', 'REMOVE_DISABLED_APPS' => $this->nextcloudKeepDisabledApps ? '' : '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' => $this->resolveHostname('nextcloud-aio-database'), + 'AIO_DATABASE_HOST' => DataConst::resolveHostname('nextcloud-aio-database'), // Allow to get local ip-address of caddy container and add it to trusted proxies automatically - 'CADDY_IP_ADDRESS' => in_array('caddy', $this->aioCommunityContainers, true) ? $this->resolveHostname('nextcloud-aio-caddy') : '', + 'CADDY_IP_ADDRESS' => in_array('caddy', $this->aioCommunityContainers, true) ? DataConst::resolveHostname('nextcloud-aio-caddy') : '', 'WHITEBOARD_ENABLED' => $this->isWhiteboardEnabled ? 'yes' : '', 'AIO_VERSION' => $this->getAioVersion(), default => $this->getRegisteredSecret($placeholder), @@ -1123,21 +1123,4 @@ class ConfigurationManager private function booleanize(mixed $value) : bool { return in_array($value, [true, 'true'], true); } - - /** - * Resolve a hostname to its IP address, trying IPv4 first and falling back - * to IPv6 (AAAA record) when no A record is found. Returns the hostname - * unchanged when neither record resolves successfully. - */ - private function resolveHostname(string $hostname): string { - $ipv4 = gethostbyname($hostname); - if ($ipv4 !== $hostname) { - return $ipv4; - } - $records = dns_get_record($hostname, DNS_AAAA); - if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') { - return $records[0]['ipv6']; - } - return $hostname; - } } diff --git a/php/src/Data/DataConst.php b/php/src/Data/DataConst.php index 10d5342b..0d4ff9c2 100644 --- a/php/src/Data/DataConst.php +++ b/php/src/Data/DataConst.php @@ -71,4 +71,21 @@ class DataConst { public static function GetAioVersionFile() : string { return (string)realpath(__DIR__ . '/../../templates/includes/aio-version.twig'); } + + /** + * Resolve a hostname to its IP address, trying IPv4 first and falling back + * to IPv6 (AAAA record) when no A record is found. Returns the hostname + * unchanged when neither record resolves successfully. + */ + public static function resolveHostname(string $hostname): string { + $ipv4 = gethostbyname($hostname); + if ($ipv4 !== $hostname) { + return $ipv4; + } + $records = dns_get_record($hostname, DNS_AAAA); + if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') { + return $records[0]['ipv6']; + } + return $hostname; + } } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index a53f0c92..a98685b7 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -449,7 +449,7 @@ readonly class DockerActionManager { // Special things for the jellyfin community container } elseif ($container->identifier === 'nextcloud-aio-jellyfin') { - $lldapIp = $this->resolveHostname('nextcloud-aio-lldap'); + $lldapIp = DataConst::resolveHostname('nextcloud-aio-lldap'); if ($lldapIp !== 'nextcloud-aio-lldap') { $requestBody['HostConfig']['ExtraHosts'] = ['nextcloud-aio-lldap:' . $lldapIp]; } @@ -1093,21 +1093,4 @@ readonly class DockerActionManager { sleep(10); } } - - /** - * Resolve a hostname to its IP address, trying IPv4 first and falling back - * to IPv6 (AAAA record) when no A record is found. Returns the hostname - * unchanged when neither record resolves successfully. - */ - private function resolveHostname(string $hostname): string { - $ipv4 = gethostbyname($hostname); - if ($ipv4 !== $hostname) { - return $ipv4; - } - $records = dns_get_record($hostname, DNS_AAAA); - if (is_array($records) && isset($records[0]['ipv6']) && $records[0]['ipv6'] !== '') { - return $records[0]['ipv6']; - } - return $hostname; - } }