|
52 | 52 | use OC\Hooks\PublicEmitter; |
53 | 53 | use OC\ServerNotAvailableException; |
54 | 54 | use OCA\User_LDAP\Exceptions\ConstraintViolationException; |
| 55 | +use OCA\User_LDAP\Exceptions\NoMoreResults; |
55 | 56 | use OCA\User_LDAP\Mapping\AbstractMapping; |
56 | 57 | use OCA\User_LDAP\Mapping\UserMapping; |
57 | 58 | use OCA\User_LDAP\User\Manager; |
@@ -264,7 +265,14 @@ public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
264 | 265 | * @throws ServerNotAvailableException |
265 | 266 | */ |
266 | 267 | public function executeRead($cr, $dn, $attribute, $filter, $maxResults) { |
267 | | - $this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0); |
| 268 | + try { |
| 269 | + $this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0); |
| 270 | + } catch (NoMoreResults $e) { |
| 271 | + // does not happen, no pagination here since offset is 0, but the |
| 272 | + // previous call is needed for a potential reset of the state. |
| 273 | + // Tools would still point out a possible NoMoreResults exception. |
| 274 | + return false; |
| 275 | + } |
268 | 276 | $dn = $this->helper->DNasBaseParameter($dn); |
269 | 277 | $rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, [$attribute]); |
270 | 278 | if (!$this->ldap->isResource($rr)) { |
@@ -1143,7 +1151,12 @@ private function executeSearch( |
1143 | 1151 | } |
1144 | 1152 |
|
1145 | 1153 | //check whether paged search should be attempted |
1146 | | - $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset); |
| 1154 | + try { |
| 1155 | + $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset); |
| 1156 | + } catch (NoMoreResults $e) { |
| 1157 | + // beyond last results page |
| 1158 | + return false; |
| 1159 | + } |
1147 | 1160 |
|
1148 | 1161 | $sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr); |
1149 | 1162 | // cannot use $cr anymore, might have changed in the previous call! |
@@ -1996,6 +2009,7 @@ public function getPagedSearchResultState() { |
1996 | 2009 | * @param int $offset |
1997 | 2010 | * @return bool|true |
1998 | 2011 | * @throws ServerNotAvailableException |
| 2012 | + * @throws NoMoreResults |
1999 | 2013 | */ |
2000 | 2014 | private function initPagedSearch( |
2001 | 2015 | string $filter, |
@@ -2027,7 +2041,7 @@ private function initPagedSearch( |
2027 | 2041 | if (!$this->hasMoreResults()) { |
2028 | 2042 | // when the cookie is reset with != 0 offset, there are no further |
2029 | 2043 | // results, so stop. |
2030 | | - return false; |
| 2044 | + throw new NoMoreResults(); |
2031 | 2045 | } |
2032 | 2046 | } |
2033 | 2047 | if ($this->lastCookie !== '' && $offset === 0) { |
|
0 commit comments