Bugzilla – Attachment 124258 Details for
Bug 26351
Add plugin hooks to transform item barcodes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26351: Add plugin hooks to transform item barcodes
Bug-26351-Add-plugin-hooks-to-transform-item-barco.patch (text/plain), 11.98 KB, created by
Jonathan Druart
on 2021-08-31 07:05:20 UTC
(
hide
)
Description:
Bug 26351: Add plugin hooks to transform item barcodes
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-08-31 07:05:20 UTC
Size:
11.98 KB
patch
obsolete
>From d835bf57bcb6d61ca330849b8e04e2688fd3788c Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 2 Sep 2020 09:17:31 -0400 >Subject: [PATCH] Bug 26351: Add plugin hooks to transform item barcodes > >Some of our partners have unusual barcode requirements that have >required us to transform scanned barcodes using javascript. This is not >the most reliable method. It would make more sense to have Koha >transform the barcodes on the backend using a plugin. We should add >hooks to transform and generate new item and patron barcodes. > >Test Plan: >1) Apply this patch >2) Download and install the Barcode Transformer plugin > https://github.com/bywatersolutions/koha-plugin-barcode-transformer/releases/ >3) Go to the plugin configuration page, set the configuration to the example configuration from the same page >4) In the item barcode field on the checkin and checkout pages, > and anywhere else you can scan an item barcode, type in some > valid barcodes, but prefix them with X and postfix them with > Y, e.g. X123456Y >5) Note the letters are removed by Koha! > >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > C4/Circulation.pm | 2 ++ > C4/ILSDI/Services.pm | 2 ++ > C4/Items.pm | 1 + > Koha/Item.pm | 3 +++ > cataloguing/additem.pl | 4 ++++ > circ/circulation.pl | 2 ++ > circ/returns.pl | 3 +++ > offline_circ/process_koc.pl | 9 +++++++++ > opac/sco/sco-main.pl | 3 +++ > t/db_dependent/Koha/Plugins/Plugins.t | 2 ++ > t/lib/Koha/Plugin/Test.pm | 9 +++++++++ > tools/batchMod.pl | 4 ++++ > tools/inventory.pl | 5 +++++ > 13 files changed, 49 insertions(+) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 03332f3836f..3e64fd24493 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -61,6 +61,7 @@ use Koha::Config::SysPref; > use Koha::Checkouts::ReturnClaims; > use Koha::SearchEngine::Indexer; > use Koha::Exceptions::Checkout; >+use Koha::Plugins; > use Carp qw( carp ); > use List::MoreUtils qw( any ); > use Scalar::Util qw( looks_like_number ); >@@ -165,6 +166,7 @@ sub barcodedecode { > my ($barcode, $filter) = @_; > my $branch = C4::Context::mybranch(); > $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter; >+ ($barcode) = Koha::Plugins->call('barcode_transform', 'item', $barcode ) || $barcode; > $filter or return $barcode; # ensure filter is defined, else return untouched barcode > if ($filter eq 'whitespace') { > $barcode =~ s/\s//g; >diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm >index 64b481bc6fd..f70100b263d 100644 >--- a/C4/ILSDI/Services.pm >+++ b/C4/ILSDI/Services.pm >@@ -34,6 +34,7 @@ use C4::Auth; > use Koha::DateUtils qw( dt_from_string ); > use C4::AuthoritiesMarc qw( GetAuthorityXML ); > >+use Koha::Plugins; > use Koha::Biblios; > use Koha::Checkouts; > use Koha::Items; >@@ -643,6 +644,7 @@ sub GetServices { > # Issuing management > my $barcode = $item->barcode || ''; > $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') ); >+ ($barcode) = Koha::Plugins->call('barcode_transform', 'item', $barcode ) || $barcode; > if ($barcode) { > my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode ); > >diff --git a/C4/Items.pm b/C4/Items.pm >index 7f83736ace6..2e6d1573371 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -71,6 +71,7 @@ use Koha::SearchEngine; > use Koha::SearchEngine::Indexer; > use Koha::SearchEngine::Search; > use Koha::Libraries; >+use Koha::Plugins; > > =head1 NAME > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 60d80a5c3eb..3710525a59c 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -89,6 +89,9 @@ sub store { > $self->itype($self->biblio->biblioitem->itemtype); > } > >+ my ($transformed_barcode) = Koha::Plugins->call( 'barcode_transform', 'item', $self->barcode ) || $self->barcode; >+ $self->barcode($transformed_barcode); >+ > my $today = dt_from_string; > my $action = 'create'; > >diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl >index e0992152562..246064870d0 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -46,6 +46,7 @@ use Koha::ItemTypes; > use Koha::Libraries; > use Koha::Patrons; > use Koha::SearchEngine::Indexer; >+use Koha::Plugins; > use List::MoreUtils qw( any ); > use C4::Search qw( enabled_staff_search_views ); > use Storable qw( freeze thaw ); >@@ -519,6 +520,9 @@ if ($op eq "additem") { > > my $addedolditem = TransformMarcToKoha( $record ); > >+ my ( $new_barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $addedolditem->{'barcode'} ) || $addedolditem->{'barcode'}; >+ $addedolditem->{'barcode'} = $new_barcode; >+ > # If we have to add or add & duplicate, we add the item > if ( $add_submit || $add_duplicate_submit ) { > >diff --git a/circ/circulation.pl b/circ/circulation.pl >index 7988782577f..0dfe8055acb 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -46,6 +46,7 @@ use Koha::CsvProfiles; > use Koha::Patrons; > use Koha::Patron::Debarments qw( GetDebarments ); > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Plugins; > use Koha::Database; > use Koha::BiblioFrameworks; > use Koha::Items; >@@ -159,6 +160,7 @@ for my $barcode ( @$barcodes ) { > $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace > $barcode = barcodedecode($barcode) > if( $barcode && C4::Context->preference('itemBarcodeInputFilter')); >+ ( $barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $barcode ) || $barcode; > } > > my $stickyduedate = $query->param('stickyduedate') || $session->param('stickyduedate'); >diff --git a/circ/returns.pl b/circ/returns.pl >index 914d5de35c2..1482a29828c 100755 >--- a/circ/returns.pl >+++ b/circ/returns.pl >@@ -55,6 +55,7 @@ use Koha::Holds; > use Koha::Items; > use Koha::Item::Transfers; > use Koha::Patrons; >+use Koha::Plugins; > > my $query = CGI->new; > >@@ -113,6 +114,7 @@ foreach ( $query->param ) { > > # decode barcode ## Didn't we already decode them before passing them back last time?? > $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace >+ ( $barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $barcode ) || $barcode; > $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter')); > > ###################### >@@ -247,6 +249,7 @@ if ($transit) { > my $returnbranch; > if ($barcode) { > $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace >+ ( $barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $barcode ) || $barcode; > $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter'); > my $item = Koha::Items->find({ barcode => $barcode }); > >diff --git a/offline_circ/process_koc.pl b/offline_circ/process_koc.pl >index 7eaa73b905b..27878f02104 100755 >--- a/offline_circ/process_koc.pl >+++ b/offline_circ/process_koc.pl >@@ -35,6 +35,7 @@ use Koha::UploadedFiles; > use Koha::Account; > use Koha::Checkouts; > use Koha::Patrons; >+use Koha::Plugins; > > use Date::Calc qw( Date_to_Days ); > >@@ -243,6 +244,10 @@ sub kocIssueItem { > my $circ = shift; > > $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter')); >+ >+ my ( $new_barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $circ->{barcode} ) || $circ->{barcode}; >+ $circ->{barcode} = $new_barcode; >+ > my $branchcode = C4::Context->userenv->{branch}; > my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } ); > my $borrower = $patron->unblessed; >@@ -323,6 +328,10 @@ sub kocIssueItem { > sub kocReturnItem { > my ( $circ ) = @_; > $circ->{'barcode'} = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter')); >+ >+ my ( $new_barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $circ->{barcode} ) || $circ->{barcode}; >+ $circ->{barcode} = $new_barcode; >+ > my $item = Koha::Items->find({ barcode => $circ->{barcode} }); > my $biblio = $item->biblio; > my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} ); >diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl >index 40d591519b1..54b4c53382c 100755 >--- a/opac/sco/sco-main.pl >+++ b/opac/sco/sco-main.pl >@@ -46,6 +46,7 @@ use Koha::Items; > use Koha::Patrons; > use Koha::Patron::Images; > use Koha::Patron::Messages; >+use Koha::Plugins; > use Koha::Token; > > my $query = CGI->new; >@@ -105,6 +106,8 @@ my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) = > $query->param("newissues") || '', > ); > >+( $barcode ) = Koha::Plugins->call( 'barcode_transform', 'item', $barcode ) || $barcode; >+ > my @newissueslist = split /,/, $newissues; > my $issuenoconfirm = 1; #don't need to confirm on issue. > my $issuer = Koha::Patrons->find( $issuerid )->unblessed; >diff --git a/t/db_dependent/Koha/Plugins/Plugins.t b/t/db_dependent/Koha/Plugins/Plugins.t >index 6549ca6960d..c156fbe343d 100755 >--- a/t/db_dependent/Koha/Plugins/Plugins.t >+++ b/t/db_dependent/Koha/Plugins/Plugins.t >@@ -211,6 +211,8 @@ ok( $plugin->can('opac_head'), 'Test plugin can opac_head' ); > ok( $plugin->can('opac_js'), 'Test plugin can opac_js' ); > ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' ); > ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' ); >+ok( $plugin->can('barcode_transform'), 'Test plugin can barcode_transform' ); >+ok( $plugin->can('barcode_generate'), 'Test plugin can barcode_generate' ); > ok( $plugin->can('configure'), 'Test plugin can configure' ); > ok( $plugin->can('install'), 'Test plugin can install' ); > ok( $plugin->can('upgrade'), 'Test plugin can upgrade' ); >diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm >index 98fcb85824a..ea9ff10b198 100644 >--- a/t/lib/Koha/Plugin/Test.pm >+++ b/t/lib/Koha/Plugin/Test.pm >@@ -93,6 +93,15 @@ sub intranet_js { > return "Koha::Plugin::Test::intranet_js"; > } > >+sub barcode_transform { >+ my ( $self, $type, $barcode ) = @_; >+ return "Koha::Plugin::Test::barcode_transform"; >+} >+ >+sub barcode_generate { >+ my ( $self, $type, $object ) >+} >+ > sub configure { > my ( $self, $args ) = @_; > return "Koha::Plugin::Test::configure";; >diff --git a/tools/batchMod.pl b/tools/batchMod.pl >index 0f57a2debd9..90f9b3bb36d 100755 >--- a/tools/batchMod.pl >+++ b/tools/batchMod.pl >@@ -50,6 +50,7 @@ use Koha::Items; > use Koha::ItemTypes; > use Koha::Patrons; > use Koha::SearchEngine::Indexer; >+use Koha::Plugins; > > my $input = CGI->new; > my $dbh = C4::Context->dbh; >@@ -372,6 +373,9 @@ if ($op eq "show"){ > if ( my $list = $input->param('barcodelist') ) { > my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list ); > @barcodelist = uniq @barcodelist; >+ >+ @barcodelist = map { ( Koha::Plugins->call( 'barcode_transform', 'item', $_ ) )[0] || $_ } @barcodelist; >+ > # Note: adding lc for case insensitivity > my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed }; > @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist; >diff --git a/tools/inventory.pl b/tools/inventory.pl >index 5eac6e4e743..4f692596aa6 100755 >--- a/tools/inventory.pl >+++ b/tools/inventory.pl >@@ -41,6 +41,8 @@ use Koha::AuthorisedValues; > use Koha::BiblioFrameworks; > use Koha::ClassSources; > use Koha::Items; >+use Koha::Plugins; >+ > use List::MoreUtils qw( none ); > > my $minlocation=$input->param('minlocation') || ''; >@@ -186,6 +188,9 @@ if ( ($uploadbarcodes && length($uploadbarcodes) > 0) || ($barcodelist && length > } > for my $barcode (@uploadedbarcodes) { > next unless $barcode; >+ >+ ($barcode) = Koha::Plugins->call('barcode_transform', 'item', $barcode ) || $barcode; >+ > ++$lines_read; > if (length($barcode)>$barcode_size) { > $err_length += 1; >-- >2.25.1
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 26351
:
109532
|
109548
|
109671
|
110844
|
110846
|
111575
|
111577
|
111578
|
111579
|
111862
|
111863
|
111894
|
111916
|
111917
|
111918
|
111919
|
111920
|
111921
|
111922
|
113571
|
113572
|
113573
|
113574
|
113575
|
113576
|
113577
|
113578
|
115172
|
115173
|
115174
|
115175
|
115176
|
115177
|
115178
|
115179
|
115180
|
118649
|
118650
|
118651
|
118652
|
118653
|
118654
|
118655
|
118656
|
118657
|
118658
|
118681
|
118682
|
118683
|
118684
|
118685
|
118686
|
118687
|
118688
|
118689
|
118690
|
122433
|
122434
|
122435
|
122436
|
122437
|
122438
|
122439
|
122440
|
122441
|
122442
|
124258
|
124259
|
124260
|
124261
|
124262
|
124263
|
124264
|
124265
|
124266
|
124313
|
125447
|
125763
|
125764
|
125765