Skip to content

Commit

Permalink
Fix infinite loop in Users.search
Browse files Browse the repository at this point in the history
If search results only contained, contacts, the offset would not advance.
  • Loading branch information
danmichaelo committed Oct 23, 2018
1 parent 66aafb1 commit f2085b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Added methods for retrieving task lists (lending requests and requested resources).

## [0.7.1] - 2018-10-23

### Fixed

- Fixed infinite loop in `Users::search()` when search result only contained contacts.

## [0.7.0] - 2018-09-02

### Added
Expand Down Expand Up @@ -65,6 +71,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

tbd.

[Unreleased]: https://github.com/scriptotek/php-marc/compare/v0.6.1...HEAD
[Unreleased]: https://github.com/scriptotek/php-marc/compare/v0.7.1...HEAD
[0.7.1]: https://github.com/scriptotek/php-marc/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/scriptotek/php-marc/compare/v0.6.1...v0.7.0
[0.6.1]: https://github.com/scriptotek/php-marc/compare/v0.6.0...v0.6.1
4 changes: 2 additions & 2 deletions src/Users/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ public function search($query, array $options = [])
break;
}

if (!isset($response->user)) {
if (!isset($response->user) || empty($response->user)) {
// We cannot trust the value in 'total_record_count', so if there are no more records,
// we have to assume the result set is depleted.
// See: https://github.com/scriptotek/php-alma-client/issues/7
break;
}

foreach ($response->user as $data) {
$offset++;
// Contacts without a primary identifier will have the primary_id
// field populated with something weird like "no primary id (123456789023)".
// We ignore those.
Expand All @@ -118,7 +119,6 @@ public function search($query, array $options = [])
$user->init();
}
yield $user;
$offset++;
}
if ($offset >= $response->total_record_count) {
break;
Expand Down

0 comments on commit f2085b6

Please sign in to comment.