diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2019-05-06 12:42:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-06 12:42:15 +0300 |
commit | 8b5733828e5e1c7edfcd841eaafbbb579ddcec4f (patch) | |
tree | 61d4fadb5573422f665313fa6d9d1e505769f05c /lib | |
parent | a3ef1423d3d1c05b66ea97048af3ae628349f0ed (diff) | |
parent | 12e8767baa1074530af83cdb71b944608d01efa0 (diff) |
Merge pull request #319 from nextcloud/fix/noid/user-search-parity
user search parity as with local users
Diffstat (limited to 'lib')
-rw-r--r-- | lib/UserBackend.php | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 30d016d4..d60159cd 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -264,27 +264,13 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function getUsers($search = '', $limit = null, $offset = null) { - /* @var $qb IQueryBuilder */ - $qb = $this->db->getQueryBuilder(); - $qb->select('uid', 'displayname') - ->from('user_saml_users') - ->where( - $qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) - ) - ->setMaxResults($limit); - if($offset !== null) { - $qb->setFirstResult($offset); - } - $result = $qb->execute(); - $users = $result->fetchAll(); - $result->closeCursor(); - - $uids = []; - foreach($users as $user) { - $uids[] = $user['uid']; - } - - return $uids; + // shamelessly duplicated from \OC\User\Database + $users = $this->getDisplayNames($search, $limit, $offset); + $userIds = array_map(function ($uid) { + return (string)$uid; + }, array_keys($users)); + sort($userIds, SORT_STRING | SORT_FLAG_CASE); + return $userIds; } /** @@ -356,29 +342,33 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function getDisplayNames($search = '', $limit = null, $offset = null) { - $qb = $this->db->getQueryBuilder(); - $qb->select('uid', 'displayname') - ->from('user_saml_users') - ->where( - $qb->expr()->iLike('uid', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) - ) - ->orWhere( - $qb->expr()->iLike('displayname', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($search) . '%')) + // shamelessly duplicate from \OC\User\Database + $query = $this->db->getQueryBuilder(); + + $query->select('uid', 'displayname') + ->from('user_saml_users', 'u') + ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( + $query->expr()->eq('userid', 'uid'), + $query->expr()->eq('appid', $query->expr()->literal('settings')), + $query->expr()->eq('configkey', $query->expr()->literal('email'))) ) - ->setMaxResults($limit); - if($offset !== null) { - $qb->setFirstResult($offset); + // sqlite doesn't like re-using a single named parameter here + ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->db->escapeLikeParameter($search) . '%'))) + ->orderBy($query->func()->lower('displayname'), 'ASC') + ->orderBy('uid', 'ASC') + ->setMaxResults($limit) + ->setFirstResult($offset); + + $result = $query->execute(); + $displayNames = []; + while ($row = $result->fetch()) { + $displayNames[(string)$row['uid']] = (string)$row['displayname']; } - $result = $qb->execute(); - $users = $result->fetchAll(); $result->closeCursor(); - $uids = []; - foreach($users as $user) { - $uids[$user['uid']] = $user['displayname']; - } - - return $uids; + return $displayNames; } /** |