diff --git a/app/src/Lib/Match/MatchService.php b/app/src/Lib/Match/MatchService.php index da65a260..5c6713c8 100644 --- a/app/src/Lib/Match/MatchService.php +++ b/app/src/Lib/Match/MatchService.php @@ -900,9 +900,19 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ Log::write('debug', $sor . "/" . $sorid . " Invalidate mode for $ruleAttributeName ($rulename) downgrading result to Potential"); + // An invalidated match could have matched more than one $rowId. + // We only check one $rowId per outer foreach() loop, but if any + // row invalidates then the entire match is invalidated. There's + // probably an argument to be made that if one row invalidates and + // a second doesn't it's still a valid match, but we don't treat it + // that way because (1) there is some inconsistency in the data + // according to its configuration, so an administrator should look + // at it before we link another record in, and (2) it's logically + // simpler. + $downgraded = [ 'rule' => "_invalidate", - 'attrs' => $attrs + 'results' => $results ]; // No need to continue with any loop @@ -925,29 +935,29 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ // Next we need to handle Potential Trust Mode, check to see if any result row // matched the SOR. - if($trustMode != TrustModeEnum::Potential) { - // Exact match, return - return $canonicalMatches; - } + if($trustMode != TrustModeEnum::Potential) { + // Exact match, return + return $canonicalMatches; + } - foreach($results as $rowId => $attrs) { - if($attrs['sor'] == $sor) { - $sorMatch = $attrs; - break; + foreach($results as $rowId => $attrs) { + if($attrs['sor'] == $sor) { + $sorMatch = $attrs; + break; + } } - } - if(!$sorMatch) { - // We matched against a _different_ SOR, so return a canonical match + if(!$sorMatch) { + // We matched against a _different_ SOR, so return a canonical match - return $canonicalMatches; - } + return $canonicalMatches; + } $downgraded = [ 'rule' => "_trustmode", - 'attrs' => $sorMatch + 'results' => $results ]; - Log::write('debug', $sor . "/" . $sorid . " Trust Mode downgrading result to Potential"); + Log::write('debug', $sor . "/" . $sorid . " Trust Mode downgrading result to Potential"); } break; case 0: @@ -974,8 +984,13 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ // Add in the downgraded potential match from above, if configured if($downgraded !== false) { - // We use a psuedo-rule name - $potentialMatches->add($downgraded['attrs'], $downgraded['rule']); + // We use a psuedo-rule name. Note a canonical match with 1 result may + // still have matched multiple rows, and we need to add them all so the + // reconciliation page will show the correct options. + + foreach($downgraded['results'] as $rowId => $attrs) { + $potentialMatches->add($attrs, $downgraded['rule']); + } } // The calling code generally checks to see if any rules successfully ran, diff --git a/app/src/Lib/Match/ResultManager.php b/app/src/Lib/Match/ResultManager.php index f19660c1..f84dbc0e 100644 --- a/app/src/Lib/Match/ResultManager.php +++ b/app/src/Lib/Match/ResultManager.php @@ -55,7 +55,6 @@ class ResultManager { * Add a Matchgrid result. * * @since COmanage Match v1.0.0 - * @param string $referenceId Reference ID * @param array $attributes Array of matchgrid attributes * @param string $rule Rule that generated this result * @throws RuntimeException