Make code clearer for background host

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2022-12-01 10:30:19 +01:00
parent 4758bdc476
commit 406750552e
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A

View file

@ -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 = [];