diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 37f7dcaea5ca7..4b890d8a31131 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -241,6 +241,7 @@ public function init($force = false) { } /** + * @throws ServerNotAvailableException When connection failed or configuration is invalid * @return resource|\LDAP\Connection The LDAP resource */ public function getConnectionResource() { diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php index d787bfea4d40c..e014832b21611 100644 --- a/apps/user_ldap/lib/User_LDAP.php +++ b/apps/user_ldap/lib/User_LDAP.php @@ -300,7 +300,7 @@ public function getUsers($search = '', $limit = 10, $offset = 0) { * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user * name or an instance of that user * @throws \Exception - * @throws \OC\ServerNotAvailableException + * @throws ServerNotAvailableException */ public function userExistsOnLDAP($user, bool $ignoreCache = false): bool { if (is_string($user)) { @@ -586,14 +586,18 @@ public function countUsers() { return $this->userPluginManager->countUsers(); } - $filter = $this->access->getFilterForUserCount(); - $cacheKey = 'countUsers-'.$filter; - if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { + try { + $filter = $this->access->getFilterForUserCount(); + $cacheKey = 'countUsers-'.$filter; + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { + return $entries; + } + $entries = $this->access->countUsers($filter); + $this->access->connection->writeToCache($cacheKey, $entries); return $entries; + } catch (ServerNotAvailableException $e) { + return false; } - $entries = $this->access->countUsers($filter); - $this->access->connection->writeToCache($cacheKey, $entries); - return $entries; } public function countMappedUsers(): int {