Bugzilla – Attachment 155360 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), 7.57 KB, created by
Martin Renvoize (ashimema)
on 2023-09-08 07:01:53 UTC
(
hide
)
Description:
Bug 34737: Add ability to match on combinations of item fields
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-09-08 07:01:53 UTC
Size:
7.57 KB
patch
obsolete
>From 3259fc11dfc777a852074942ea9a7cdd19d7904a 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 >1) Run the unit tests before and after applying this patch and confirm > they pass in both cases (prove -v t/db_debendant/SIP/Transaction.t >2) Check out an item and return it via SIP2: > $ telnet localhost 8023 > 9300CNterm1|COterm1|CPCPL| > 09N20200422 12430020200422 124300APCPL|AOCPL|AB001|AC| > (Where 001 in |AB001| is the barcode of the item in question) >4) Check there is no CL field in the last response >5) Apply the patch, fill in SIP2SortBinMapping with e.g.: > CPL:itype:eq:BK:ccode:eq:TEEN:3 >6) Repeat the first step >7) Check the response contains a CL field with a value of 3 (or what > you put in the config). The field should look like |CL3| >--- > C4/SIP/ILS/Transaction/Checkin.pm | 78 ++++++++++++------- > .../admin/preferences/circulation.pref | 6 +- > 2 files changed, 56 insertions(+), 28 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 >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >index 55feb4d444..2a5cb1489e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >@@ -1339,12 +1339,14 @@ Circulation: > - "- 'comparator' is the type of comparison, possible values are: eq,<,<=,>,>=,ne<br/>" > - "- 'item field value' is the value to compare against the value in the specified 'item field'<br/>" > - "- 'sort bin number' is the expected return value in the CL field of the SIP response for an item matching a rule<br/><br/>" >+ - "The field comparison triplet, 'item field:comparator:item field value', is repeatable within a single line to allow for more complex cases" > - "NOTE: Specifying 'item_field_value' with a leading '\\$' and an item field name will use the value of that field in the item for comparison:<br/>" > - "i.e. \\$holdingbranch<br/></br>" > - "Examples:<br/>" > - "CPL:itype:eq:BOOK:1 - Will return sort bin 1 for an item of itemtype 'BOOK' returned to CPL.<br/>" >- - "CPL:itemcallnumber:<:339.6:3 - Will return sort bin 3 for an item with a callnumber less than 339.6 returned to CPL .<br/>" >- - "CPL:homebranch:ne:\\$holdingbranch:X - Will return sort bin 'X' for an item returned to CPL where the holdingbranch is not equal to the homebranch (i.e. any item belonging to a different branch than CPL).<br/><br/>" >+ - "CPL:itemcallnumber:<:339.6:3 - Will return sort bin 3 for an item with a callnumber less than 339.6 returned to CPL.<br/>" >+ - "CPL:homebranch:ne:\\$holdingbranch:X - Will return sort bin 'X' for an item returned to CPL where the holdingbranch is not equal to the homebranch (i.e. any item belonging to a different branch than CPL).<br/>" >+ - "CPL:itype:eq:BOOK:ccode:eq:TEEN:5 - Will return sort bin 5 for an item of itemtype 'BOOK' and a ccode 'TEEN' returned to CPL.<br/><br/>" > - pref: SIP2SortBinMapping > type: textarea > class: long >-- >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