Bug 40082: Move the duplicate matching logic to the Koha::Patrons class

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>

Signed-off-by: Pamela Bird <pbird@cityofchesapeake.net>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Matt Blenkinsop 2025-06-05 13:38:37 +01:00 committed by Lucas Gass
parent f1c0d2d6d8
commit 5736c9175c
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 31 additions and 9 deletions

View File

@ -675,6 +675,33 @@ sub extended_attributes_config {
};
}
=head3 check_for_existing_matches
my $match_result = Koha::Patrons->check_for_existing_matches( $patron_data );
Uses the fields from the PatronDuplicateMatchingAddFields preference to check for existing matches
=cut
sub check_for_existing_matches {
my ( $self, $new_patron_data ) = @_;
my @duplicate_match_fields = split '\|', C4::Context->preference('PatronDuplicateMatchingAddFields');
my $match_conditions;
for my $field (@duplicate_match_fields) {
$match_conditions->{$field} = $new_patron_data->{$field} if $new_patron_data->{$field};
}
my $patrons = Koha::Patrons->search($match_conditions);
if ( $patrons->count > 0 ) {
return {
'duplicate_found' => 1,
'matching_patrons' => $patrons
};
}
return { 'duplicate_found' => 0 };
}
=head3 _type
=cut

View File

@ -252,18 +252,13 @@ if ( $op eq 'cud-insert' || $op eq 'edit_form' || $op eq 'cud-save' || $op eq 'd
}
}
# Test uniqueness of surname, firstname and dateofbirth
#Test uniqueness of fields in PatronDuplicateMatchingAddFields
if ( ( $op eq 'cud-insert' ) and !$nodouble ) {
my @dup_fields = split '\|', C4::Context->preference('PatronDuplicateMatchingAddFields');
my $conditions;
for my $f (@dup_fields) {
$conditions->{$f} = $newdata{$f} if $newdata{$f};
}
$nodouble = 1;
my $patrons = Koha::Patrons->search($conditions);
if ( $patrons->count > 0 ) {
my $match_result = Koha::Patrons->check_for_existing_matches( \%newdata );
if ( $match_result->{duplicate_found} ) {
$nodouble = 0;
$check_patron = $patrons->next;
$check_patron = $match_result->{matching_patrons}->next;
$check_member = $check_patron->borrowernumber;
}
}