Skip to content

Commit f2085b6

Browse files
committed
Fix infinite loop in Users.search
If search results only contained, contacts, the offset would not advance.
1 parent 66aafb1 commit f2085b6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88

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

11+
## [0.7.1] - 2018-10-23
12+
13+
### Fixed
14+
15+
- Fixed infinite loop in `Users::search()` when search result only contained contacts.
16+
1117
## [0.7.0] - 2018-09-02
1218

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

6672
tbd.
6773

68-
[Unreleased]: https://github.com/scriptotek/php-marc/compare/v0.6.1...HEAD
74+
[Unreleased]: https://github.com/scriptotek/php-marc/compare/v0.7.1...HEAD
75+
[0.7.1]: https://github.com/scriptotek/php-marc/compare/v0.7.0...v0.7.1
6976
[0.7.0]: https://github.com/scriptotek/php-marc/compare/v0.6.1...v0.7.0
7077
[0.6.1]: https://github.com/scriptotek/php-marc/compare/v0.6.0...v0.6.1

src/Users/Users.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ public function search($query, array $options = [])
9797
break;
9898
}
9999

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

107107
foreach ($response->user as $data) {
108+
$offset++;
108109
// Contacts without a primary identifier will have the primary_id
109110
// field populated with something weird like "no primary id (123456789023)".
110111
// We ignore those.
@@ -118,7 +119,6 @@ public function search($query, array $options = [])
118119
$user->init();
119120
}
120121
yield $user;
121-
$offset++;
122122
}
123123
if ($offset >= $response->total_record_count) {
124124
break;

0 commit comments

Comments
 (0)