From f0096b7dfbf819a5393c00ac5f0e7bcae5c03998 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 5 Jun 2025 13:38:37 +0100 Subject: [PATCH] Bug 40082: Move the duplicate matching logic to the Koha::Patrons class --- Koha/Patrons.pm | 23 +++++++++++++++++++++++ members/memberentry.pl | 13 ++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 3156f4f60e7..35c22518bab 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -647,6 +647,29 @@ sub extended_attributes_config { }; } +=head3 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 diff --git a/members/memberentry.pl b/members/memberentry.pl index 5846b3b1c60..af96eef4977 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -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; } } -- 2.48.1