From a5f5a1b07135b178541688a82fd8b9bbaf2a9fe9 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Tue, 21 May 2024 01:23:49 +0200 Subject: [PATCH] Bug 15536: ui and store/fetch for new columns --- C4/Matcher.pm | 60 ++++++++++++------- admin/matching-rules.pl | 16 +++-- .../prog/en/modules/admin/matching-rules.tt | 50 ++++++++++------ 3 files changed, 81 insertions(+), 45 deletions(-) diff --git a/C4/Matcher.pm b/C4/Matcher.pm index fbfcc1cb40..457320354a 100644 --- a/C4/Matcher.pm +++ b/C4/Matcher.pm @@ -199,6 +199,7 @@ sub fetch { my $matchcheck = {}; $matchcheck->{'source_matchpoint'} = $source_matchpoint; $matchcheck->{'target_matchpoint'} = $target_matchpoint; + $matchcheck->{'operator'} = $row->{'operator'}; push @{ $self->{'required_checks'} }, $matchcheck; } @@ -208,7 +209,7 @@ sub fetch { sub _fetch_matchpoint { my $self = shift; my $matchpoint_id = shift; - + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare_cached("SELECT * FROM matchpoints WHERE matchpoint_id = ?"); $sth->execute($matchpoint_id); @@ -223,13 +224,15 @@ sub _fetch_matchpoint { $sth->execute($matchpoint_id); while ($row = $sth->fetchrow_hashref) { my $component = {}; - $component->{'tag'} = $row->{'tag'}; + $component->{'tag'} = $row->{'tag'}; $component->{'subfields'} = { map { $_ => 1 } split(//, $row->{'subfields'}) }; - $component->{'offset'} = int($row->{'offset'}); - $component->{'length'} = int($row->{'length'}); - $component->{'norms'} = []; - my $sth2 = $dbh->prepare_cached("SELECT * - FROM matchpoint_component_norms + $component->{'offset'} = int($row->{'offset'}); + $component->{'length'} = int($row->{'length'}); + $component->{'norms'} = []; + $component->{'constant'} = $row->{'constant'}; + $component->{'type'} = defined $row->{'constant'} ? 'constant' : 'field'; + my $sth2 = $dbh->prepare_cached("SELECT * + FROM matchpoint_component_norms WHERE matchpoint_component_id = ? ORDER BY sequence"); $sth2->execute($row->{'matchpoint_component_id'}); while (my $row2 = $sth2->fetchrow_hashref) { @@ -319,10 +322,12 @@ sub _store_matcher_components { foreach my $matchcheck (@{ $self->{'required_checks'} }) { my $source_matchpoint_id = $self->_store_matchpoint($matchcheck->{'source_matchpoint'}); my $target_matchpoint_id = $self->_store_matchpoint($matchcheck->{'target_matchpoint'}); - $sth = $dbh->prepare_cached("INSERT INTO matchchecks - (matcher_id, source_matchpoint_id, target_matchpoint_id) - VALUES (?, ?, ?)"); - $sth->execute($matcher_id, $source_matchpoint_id, $target_matchpoint_id); + $sth = $dbh->prepare_cached( + "INSERT INTO matchchecks + (matcher_id, source_matchpoint_id, target_matchpoint_id, operator) + VALUES (?, ?, ?, ?)" + ); + $sth->execute( $matcher_id, $source_matchpoint_id, $target_matchpoint_id, $matchcheck->{'operator'} ); } } @@ -341,15 +346,18 @@ sub _store_matchpoint { my $seqnum = 0; foreach my $component (@{ $matchpoint->{'components'} }) { $seqnum++; - $sth = $dbh->prepare_cached("INSERT INTO matchpoint_components - (matchpoint_id, sequence, tag, subfields, `offset`, length) - VALUES (?, ?, ?, ?, ?, ?)"); + $sth = $dbh->prepare_cached( + "INSERT INTO matchpoint_components + (matchpoint_id, sequence, tag, subfields, `offset`, length, `constant`) + VALUES (?, ?, ?, ?, ?, ?, ?)" + ); $sth->bind_param(1, $matchpoint_id); $sth->bind_param(2, $seqnum); $sth->bind_param(3, $component->{'tag'}); $sth->bind_param(4, join "", sort keys %{ $component->{'subfields'} }); $sth->bind_param(5, $component->{'offset'}||0); $sth->bind_param(6, $component->{'length'}); + $sth->bind_param( 7, $component->{'constant'} ); $sth->execute(); my $matchpoint_component_id = $dbh->{'mysql_insertid'}; my $normseq = 0; @@ -552,9 +560,9 @@ to the source string. sub add_required_check { my $self = shift; - my ($source_matchpoint, $target_matchpoint) = @_; + my ( $source_matchpoint, $target_matchpoint, $operator ) = @_; - my $matchcheck = {}; + my $matchcheck = { 'operator' => $operator }; $matchcheck->{'source_matchpoint'}->{'index'} = ''; $matchcheck->{'source_matchpoint'}->{'score'} = 0; $matchcheck->{'source_matchpoint'}->{'components'} = []; @@ -903,11 +911,21 @@ sub _parse_match_component { my $input_component = shift; my $component = {}; - $component->{'tag'} = $input_component->{'tag'}; - $component->{'subfields'} = { map { $_ => 1 } split(//, $input_component->{'subfields'}) }; - $component->{'offset'} = exists($input_component->{'offset'}) ? $input_component->{'offset'} : -1; - $component->{'length'} = $input_component->{'length'} ? $input_component->{'length'} : 0; - $component->{'norms'} = $input_component->{'norms'} ? $input_component->{'norms'} : []; + if ( $input_component->{'type'} eq 'constant' ) { + $component->{'tag'} = ''; + $component->{'subfields'} = {}; + $component->{'offset'} = 0; + $component->{'length'} = 0; + $component->{'norms'} = []; + $component->{'constant'} = $input_component->{'constant'}; + } else { + $component->{'tag'} = $input_component->{'tag'}; + $component->{'subfields'} = { map { $_ => 1 } split( //, $input_component->{'subfields'} ) }; + $component->{'offset'} = exists( $input_component->{'offset'} ) ? $input_component->{'offset'} : -1; + $component->{'length'} = $input_component->{'length'} ? $input_component->{'length'} : 0; + $component->{'norms'} = $input_component->{'norms'} ? $input_component->{'norms'} : []; + $component->{'constant'} = undef; + } return $component; } diff --git a/admin/matching-rules.pl b/admin/matching-rules.pl index 6c3d3d3ffb..76668659a0 100755 --- a/admin/matching-rules.pl +++ b/admin/matching-rules.pl @@ -136,7 +136,7 @@ sub add_update_matching_rule { foreach my $comp_num (@comp_nums) { my $component = {}; my $p = "mc_${mc_num}_${which}_c_${comp_num}_"; - map { $component->{$_} = $input->param("${p}$_") } qw(tag subfields offset length); + map { $component->{$_} = $input->param("${p}$_") } qw(tag subfields offset length constant type); # norms $component->{'norms'} = []; my @norm_nums = sort map { /^${p}n_(\d+)_norm/ ? int($1): () } $input->multi_param; @@ -146,7 +146,8 @@ sub add_update_matching_rule { push @$components, $component; } } - $matcher->add_required_check($src_components, $tgt_components); + + $matcher->add_required_check($src_components, $tgt_components, $input->param("mc_${mc_num}_operator")); } if (defined $matcher_id and $matcher_id =~ /^\d+/) { @@ -200,12 +201,12 @@ sub edit_matching_rule_form { foreach my $matchpoint (@{ $matcher_info->{'matchpoints'} }) { $mp_num++; my @components = _parse_components($matchpoint->{'components'}); - push @matchpoints, { - mp_num => $mp_num, - index => $matchpoint->{'index'}, + push @matchpoints, { + mp_num => $mp_num, + index => $matchpoint->{'index'}, score => $matchpoint->{'score'}, components => \@components - }; + }; } $template->param(matchpoints => \@matchpoints); @@ -217,6 +218,7 @@ sub edit_matching_rule_form { my @tgt_components = _parse_components($matchcheck->{'target_matchpoint'}->{'components'}); push @matchchecks, { mc_num => $mc_num, + operator => $matchcheck->{'operator'}, src_components => \@src_components, tgt_components => \@tgt_components }; @@ -252,6 +254,8 @@ sub _parse_components { subfields => join("", sort keys %{ $component->{'subfields'} }), offset => $component->{'offset'}, 'length' => $component->{'length'}, + constant => $component->{'constant'}, + type => $component->{'type'}, norms => \@norms }; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt index 7abd5784e2..fa0cd5d340 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/matching-rules.tt @@ -54,32 +54,30 @@ [% END %] +[% BLOCK operator_select %] +[%# PARAMS: operator, id, name %] + + +[% END %] + [% BLOCK match_check_component %] [%# PARAMS mc_num, which, components %] [% IF (!components) %] - [% SET components = [ - { - comp_num => 1, norms => [ - { - norm_num => 1, - norm = "none" - } - ], - tag => '', - subfields => '', - offset => '', - length => '' - } - ] %] + [% SET components = [ { comp_num => 1, norms => [ { norm_num => 1, norm = "none" } ], tag => '', subfields => '', offset => '', length => '', type => 'field', constant => '' } ] %] [% END %] [% FOREACH component IN components %] [% SET pc = "mc_${mc_num}_${which}_c_${component.comp_num}" %]
+ [% IF (which == 'src') %] - Source (incoming) record check field + Source (incoming) record check field [% ELSE %] - Target (database) record check field + Target (database) record check field [% END %] +
  1. @@ -104,7 +102,20 @@
  2. [% END %]
-
+ + [% IF (which == 'src') %] + Compare to constant value instead of source field + [% ELSE %] + Compare to constant value instead of target field + [% END %] + +
    +
  1. + + +
  2. +
+ [% END #/FOREACH component %] [% END %] @@ -340,6 +351,7 @@
Match check [% matchcheck.mc_num | html %]

New match check | Remove this match check

+ [% PROCESS operator_select id="mc_${matchcheck.mc_num}_operator" name="mc_${matchcheck.mc_num}_operator" operator=matchcheck.operator %] [% PROCESS match_check_component mc_num=matchcheck.mc_num which="src" components=matchcheck.src_components %] [% PROCESS match_check_component mc_num=matchcheck.mc_num which="tgt" components=matchcheck.tgt_components %] @@ -352,6 +364,7 @@
Match check 1

New match check | Remove this match check

+ [% PROCESS operator_select id="mc_1_operator" name="mc_1_operator" %] [% PROCESS match_check_component mc_num=1 which="src" components=0 %] [% PROCESS match_check_component mc_num=1 which="tgt" components=0 %] @@ -480,6 +493,7 @@
Match check

Remove this match check

+ [% PROCESS operator_select id="mc_num_operator" name="mc_num_operator" %] [% PROCESS match_check_component mc_num="num" which="src" components=0 %] [% PROCESS match_check_component mc_num="num" which="tgt" components=0 %] @@ -562,7 +576,7 @@ $(this).attr("id",s.replace(/mc_num/, 'mc_' + maxMatchCheck)); } }); - $("input",clone).each(function(){ + $("input, select",clone).each(function(){ var s = $(this).attr("id"); if(s.match(/mc_num/)){ $(this).attr("id",s.replace(/mc_num/, 'mc_' + maxMatchCheck)); -- 2.39.2