Bugzilla – Attachment 166949 Details for
Bug 15536
Additional match check comparison operators
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15536: ui and store/fetch for new columns
Bug-15536-ui-and-storefetch-for-new-columns.patch (text/plain), 15.41 KB, created by
Andreas Jonsson
on 2024-05-21 00:49:18 UTC
(
hide
)
Description:
Bug 15536: ui and store/fetch for new columns
Filename:
MIME Type:
Creator:
Andreas Jonsson
Created:
2024-05-21 00:49:18 UTC
Size:
15.41 KB
patch
obsolete
>From a5f5a1b07135b178541688a82fd8b9bbaf2a9fe9 Mon Sep 17 00:00:00 2001 >From: Andreas Jonsson <andreas.jonsson@kreablo.se> >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 @@ > </select> > [% END %] > >+[% BLOCK operator_select %] >+[%# PARAMS: operator, id, name %] >+ <label for="[% id | html %]">Operator: </label> >+ <select id="[% id | html %]" name="[% name | html %]"> >+ <option value="eq" [% IF operator == 'eq' %] selected="selected" [% END %]>source = target (case sensitive string equality)</option> >+ <option value="ne" [% IF operator == 'ne' %] selected="selected" [% END %]>source â target (case sensitive string inequality)</option> >+ </select> >+[% 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}" %] > <fieldset class="rows" id="[% pc | html %]"> >+ <legend><input type="radio" name="[% pc | html %]_type" id="[% pc | html %]_type_field" value="field" [% IF component.type != 'constant' %]checked="checked"[% END %] /> > [% IF (which == 'src') %] >- <legend>Source (incoming) record check field</legend> >+ Source (incoming) record check field > [% ELSE %] >- <legend>Target (database) record check field</legend> >+ Target (database) record check field > [% END %] >+ </legend> > <ol> > <li> > <label for="[% pc | html %]_tag">Tag: </label> >@@ -104,7 +102,20 @@ > </li> > [% END %] > </ol> >- </fieldset> <!-- /#[% pc %] --> >+ <legend><input type="radio" name="[% pc | html %]_type" id="[% pc | html %]_type_field" value="constant" [% IF component.type == 'constant' %]checked="checked"[% END %] /> >+ [% IF (which == 'src') %] >+ Compare to constant value instead of source field >+ [% ELSE %] >+ Compare to constant value instead of target field >+ [% END %] >+ </legend> >+ <ol> >+ <li> >+ <label for="[% pc | html %]_constant">Constant value: </label> >+ <input type="text" id="[% pc | html %]_constant" name="[% pc | html %]_constant" value="[% component.constant | html %]" size="50" /> >+ </li> >+ </ol> >+ </fieldset> <!-- /#[% pc | html %] --> > [% END #/FOREACH component %] > [% END %] > >@@ -340,6 +351,7 @@ > <fieldset class="rows"> > <legend>Match check [% matchcheck.mc_num | html %]</legend> > <p><a href="#" class="btn btn-link" onclick="InsertMatchcheck('mc_[% matchcheck.mc_num | html %]', 'mc_template'); return false;"><i class="fa fa-plus" aria-hidden="true"></i> New match check</a> | <a href="#" class="btn btn-link" onclick="DeleteMatchcheck(this); return false;"><i class="fa fa-trash-can" aria-hidden="true"></i> Remove this match check</a></p> >+ [% PROCESS operator_select id="mc_${matchcheck.mc_num}_operator" name="mc_${matchcheck.mc_num}_operator" operator=matchcheck.operator %] > <input type="hidden" id="mc_[% matchcheck.mc_num | html %]_id" name="mc_[% matchcheck.mc_num | html %]_id" value="1" /> > [% 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 @@ > <fieldset class="rows"> > <legend>Match check 1</legend> > <p><a href="#" class="btn btn-link" onclick="InsertMatchcheck('mc_1', 'mc_template'); return false;"><i class="fa fa-plus" aria-hidden="true"></i> New match check</a> | <a href="#" class="btn btn-link" onclick="DeleteMatchcheck(this); return false;"><i class="fa fa-trash-can" aria-hidden="true"></i> Remove this match check</a></p> >+ [% PROCESS operator_select id="mc_1_operator" name="mc_1_operator" %] > <input type="hidden" id="mc_1_id" name="mc_1_id" value="1" /> > [% 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 @@ > <fieldset class="rows"> > <legend>Match check <span class="counter"></span></legend> > <p><a href="#" class="button" onclick="DeleteMatchcheck(this); return false;"><i class="fa fa-trash-can" aria-hidden="true"></i> Remove this match check</a></p> >+ [% PROCESS operator_select id="mc_num_operator" name="mc_num_operator" %] > <input type="hidden" id="mc_num_id" name="mc_num_id" value="1" /> > [% 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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15536
:
166947
|
166948
| 166949 |
166950