Skip to content

Commit

Permalink
[#42] fixed findbyiban for duplicate entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Oct 23, 2019
1 parent 953b664 commit 56a6988
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion api/v3/Bic.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,29 @@ function civicrm_api3_bic_getfromiban($params) {

foreach ($nbids as $nbid) {
try {
return civicrm_api3('Bic', 'getsingle', array('country' => $country, 'nbid' => $nbid));
$search = civicrm_api3('Bic', 'get', ['country' => $country, 'nbid' => $nbid]);
// check if all entities are the same
$candidate = NULL;
foreach ($search['values'] as $entity) {
if ($candidate == NULL) {
$candidate = $entity;
} else {
if ($candidate != $entity) {
// two different matches found!
Civi::log()->debug("LittleBIC: contradicting bank records detected: {$country}{$nbid}");
return civicrm_api3_create_error("Contradicting bank records detected: {$country}{$nbid}");

} else {
// identical records!
Civi::log()->debug("LittleBIC: duplicate bank records detected: {$country}{$nbid}");
}
}
}

if ($candidate) {
return $candidate;
}

} catch (Exception $e) {
// not found? no problem, just keep looking
}
Expand Down

0 comments on commit 56a6988

Please sign in to comment.