From 406750552e1332f4419cd0c8b77891c1e8b4aee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 1 Dec 2022 10:30:19 +0100 Subject: [PATCH] Make code clearer for background host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/user_ldap/lib/Connection.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index a144810b39b..1cde3bc3960 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -598,16 +598,16 @@ class Connection extends LDAPUtility { } } - $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer - || $this->getFromCache('overrideMainServer')); - $isBackupHost = (trim($this->configuration->ldapBackupHost) !== "") - && (!\OC::$CLI || !$this->configuration->ldapBackgroundHost); + $forceBackupHost = ($this->configuration->ldapOverrideMainServer || $this->getFromCache('overrideMainServer')); + $hasBackupHost = (trim($this->configuration->ldapBackupHost ?? '') !== ''); + $hasBackgroundHost = (trim($this->configuration->ldapBackgroundHost ?? '') !== ''); + $useBackupHost = $hasBackupHost && (!\OC::$CLI || !$hasBackgroundHost); $bindStatus = false; try { - if (!$isOverrideMainServer) { + if (!$forceBackupHost) { $host = $this->configuration->ldapHost; $port = $this->configuration->ldapPort; - if (\OC::$CLI && $this->configuration->ldapBackgroundHost) { + if (\OC::$CLI && $hasBackgroundHost) { $host = $this->configuration->ldapBackgroundHost; $port = $this->configuration->ldapBackgroundPort; } @@ -615,7 +615,7 @@ class Connection extends LDAPUtility { return $this->bind(); } } catch (ServerNotAvailableException $e) { - if (!$isBackupHost) { + if (!$useBackupHost) { throw $e; } $this->logger->warning( @@ -627,7 +627,7 @@ class Connection extends LDAPUtility { } //if LDAP server is not reachable, try the Backup (Replica!) Server - if ($isBackupHost || $isOverrideMainServer) { + if ($useBackupHost || $forceBackupHost) { $this->doConnect($this->configuration->ldapBackupHost, $this->configuration->ldapBackupPort); $this->bindResult = [];