From 27705ef38be3406c508d0913f852f9df4b2a5454 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Tue, 21 May 2024 01:55:05 +0200 Subject: [PATCH] Bug 15536: implement match control check --- C4/Matcher.pm | 22 +++++++++++++++++++++- admin/matching-rules.pl | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/C4/Matcher.pm b/C4/Matcher.pm index 457320354a..16f1895da1 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -23,6 +23,7 @@ use Modern::Perl; use Koha::SearchEngine; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; +use Koha::Logger; use Koha::Util::Normalize qw( ISBN legacy_default @@ -796,6 +797,21 @@ sub dump { return $result; } +sub _passes_required_check { + my ( $s, $t, $op ) = @_; + + if ( $op eq 'eq' ) { + return $s eq $t; + } + + if ( $op eq 'ne' ) { + return $s ne $t; + } + + Koha::Logger->get->error( "Unknown match control operator: '$op'!" ); + return 0; +} + sub _passes_required_checks { my ($source_record, $target_record, $matchchecks) = @_; @@ -805,7 +821,7 @@ sub _passes_required_checks { foreach my $matchcheck (@{ $matchchecks }) { my $source_key = join "", _get_match_keys($source_record, $matchcheck->{'source_matchpoint'}); my $target_key = join "", _get_match_keys($target_record, $matchcheck->{'target_matchpoint'}); - return 0 unless $source_key eq $target_key; + return 0 unless _passes_required_check( $source_key, $target_key, $matchcheck->{'operator'} ); } return 1; } @@ -834,6 +850,10 @@ sub _get_match_keys { my @keys = (); for (my $i = 0; $i <= $#{ $matchpoint->{'components'} }; $i++) { my $component = $matchpoint->{'components'}->[$i]; + if ( defined $component->{'type'} && $component->{'type'} eq 'constant' ) { + push @keys, $component->{'constant'}; + next; + } my $j = -1; my @fields = (); diff --git a/admin/matching-rules.pl b/admin/matching-rules.pl index 76668659a0..63080875ef 100755 --- a/admin/matching-rules.pl +++ b/admin/matching-rules.pl @@ -146,8 +146,8 @@ sub add_update_matching_rule { push @$components, $component; } } - - $matcher->add_required_check($src_components, $tgt_components, $input->param("mc_${mc_num}_operator")); + my $operator = $input->param( "mc_${mc_num}_operator" ); + $matcher->add_required_check( $src_components, $tgt_components, $operator ); } if (defined $matcher_id and $matcher_id =~ /^\d+/) { -- 2.39.2