Bugzilla – Attachment 155328 Details for
Bug 34737
Enhance SIP2SortBinMapping to support additional match conditions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34737: Add ability to match on combinations of item fields
Bug-34737-Add-ability-to-match-on-combinations-of-.patch (text/plain), 4.64 KB, created by
Martin Renvoize (ashimema)
on 2023-09-07 16:25:34 UTC
(
hide
)
Description:
Bug 34737: Add ability to match on combinations of item fields
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-09-07 16:25:34 UTC
Size:
4.64 KB
patch
obsolete
>From abb9e22c64add64185333d8725bed538445bb3f9 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 7 Sep 2023 16:53:00 +0100 >Subject: [PATCH] Bug 34737: Add ability to match on combinations of item > fields > >This patch updates the sort bin selection logic to allow for multiple >item field comparisons in a single config rule line. > >Test plan >--- > C4/SIP/ILS/Transaction/Checkin.pm | 78 ++++++++++++++++++++----------- > 1 file changed, 52 insertions(+), 26 deletions(-) > >diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm >index e512350be8..63e017018f 100644 >--- a/C4/SIP/ILS/Transaction/Checkin.pm >+++ b/C4/SIP/ILS/Transaction/Checkin.pm >@@ -216,11 +216,16 @@ The mapping should be: > > <branchcode>:<item field>:<comparator>:<item field value>:<sort bin number> > >+The field comparison triplet is repeatable, so you may include multiple sections >+ >+ :<item field>:<comparator>:<item field value>: >+ > For example: > > CPL:itype:eq:BOOK:1 > CPL:location:eq:OFFICE:2 > CPL:classmark:<:339.6:3 >+ CPL:itype:eq:BOOK:ccode:eq:TEEN:4 > > This will give: > >@@ -232,6 +237,8 @@ This will give: > > =item * sort_bin = "3" for items at the CPL branch with a classmark less than 339.6 > >+=item * sort_bin = "4" for items at the CPL branch with an itype of BOOK and a ccode of TEEN >+ > =back > > Returns the ID of the appropriate sort_bin, if there is one, or undef. >@@ -245,11 +252,12 @@ sub _get_sort_bin { > return unless $item; > > my @lines; >+ > # Mapping in SIP config takes precedence over syspref > if ( my $mapping = $account->{sort_bin_mapping} ) { > @lines = map { $_->{mapping} } @$mapping; >- } >- else { >+ } else { >+ > # Get the mapping and split on newlines > my $raw_map = C4::Context->preference('SIP2SortBinMapping'); > return unless $raw_map; >@@ -258,36 +266,54 @@ sub _get_sort_bin { > > # Iterate over the mapping. The first hit wins. > my $rule = 0; >- foreach my $line (@lines) { >+ RULE: foreach my $line (@lines) { >+ >+ my $match = 0; > > # Split the line into fields >- my ( $branchcode, $item_property, $comparator, $value, $sort_bin ) = >- split /:/, $line; >- if ( $value =~ s/^\$// ) { >- $value = $item->$value; >- } >- # Check the fields against values in the item >- if ( $branch eq $branchcode ) { >+ my @fields = split /:/, $line; >+ >+ # Capture branchcode from first field >+ my $branchcode = shift @fields; >+ next RULE unless ( $branch eq $branchcode ); >+ >+ # Capture sort_bin from last field >+ my $sort_bin = pop @fields; >+ >+ # Capture rule sets >+ while ( my ( $item_property, $comparator, $value ) = splice( @fields, 0, 3 ) ) { >+ >+ # Skip badly formed rules >+ next RULE if ( !defined($item_property) || !defined($comparator) || !defined($value) ); >+ >+ if ( $value =~ s/^\$// ) { >+ $value = $item->$value; >+ } >+ >+ # Check the fields against values in the item > my $property = $item->$item_property; > if ( ( $comparator eq 'eq' || $comparator eq '=' ) && ( $property eq $value ) ) { >- return $sort_bin; >- } >- if ( ( $comparator eq 'ne' || $comparator eq '!=' ) && ( $property ne $value ) ) { >- return $sort_bin; >- } >- if ( ( $comparator eq '<' ) && ( $property < $value ) ) { >- return $sort_bin; >- } >- if ( ( $comparator eq '>' ) && ( $property > $value ) ) { >- return $sort_bin; >- } >- if ( ( $comparator eq '<=' ) && ( $property <= $value ) ) { >- return $sort_bin; >- } >- if ( ( $comparator eq '>=' ) && ( $property >= $value ) ) { >- return $sort_bin; >+ $match = 1; >+ } elsif ( ( $comparator eq 'ne' || $comparator eq '!=' ) && ( $property ne $value ) ) { >+ $match = 1; >+ } elsif ( ( $comparator eq '<' ) && ( $property < $value ) ) { >+ $match = 1; >+ } elsif ( ( $comparator eq '>' ) && ( $property > $value ) ) { >+ $match = 1; >+ } elsif ( ( $comparator eq '<=' ) && ( $property <= $value ) ) { >+ $match = 1; >+ } elsif ( ( $comparator eq '>=' ) && ( $property >= $value ) ) { >+ $match = 1; >+ } else { >+ >+ # No match, skip to next rule >+ next RULE; > } > } >+ >+ # Return sort bin if match >+ return $sort_bin if $match; >+ > } > > # Return undef if no hits were found >-- >2.41.0
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 34737
:
155328
|
155329
|
155330
|
155360
|
155361
|
155362
|
155663
|
155664
|
155665
|
155666
|
156147
|
156148
|
156170
|
156171
|
156172
|
156173
|
156174
|
156175
|
156176
|
156177
|
156314
|
156315