From 19bbce640e2de87ab129a1c454d833389e185384 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 6 Aug 2018 15:59:38 -0300 Subject: [PATCH] Bug 21184: Replace C4::Items::GetBarcodeFromItemnumber calls Those calls to C4::Items::GetBarcodeFromItemnumber can be replaced with my $barcode = Koha::Items->find($itemnumber)->barcode; But if we are not sure that the item exists, we should test the return of ->find before ->barcode Test plan: - Edit an item - Check an item in - Test SIP - I do not really know how to trigger that code, apparently misc/sip_cli_emulator.pl does not deal with holds. Any ideas? --- C4/SIP/ILS/Patron.pm | 15 ++++++++++----- cataloguing/additem.pl | 4 +++- svc/checkin | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 23c576493f..41c21a15f2 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -22,9 +22,10 @@ use C4::Context; use C4::Koha; use C4::Members; use C4::Reserves; -use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio); +use C4::Items qw( GetItemnumbersForBiblio); use C4::Auth qw(checkpw); +use Koha::Items; use Koha::Libraries; use Koha::Patrons; @@ -315,7 +316,8 @@ sub hold_items { my $self = shift; my $item_arr = $self->x_items('hold_items', @_); foreach my $item (@{$item_arr}) { - $item->{barcode} = GetBarcodeFromItemnumber($item->{itemnumber}); + my $item_obj = Koha::Items->find($item->{itemnumber}); + $item_arr->{barcode} = $item_obj ? $item_obj->barcode : undef; } return $item_arr; } @@ -483,15 +485,18 @@ sub _get_outstanding_holds { while ( my $hold = $holds->next ) { my $item; if ($hold->itemnumber) { - $item = $hold->itemnumber; + $item = $hold->item; } else { # We need to return a barcode for the biblio so the client # can request the biblio info - $item = ( GetItemnumbersForBiblio($hold->biblionumber) )->[0]; + my $items = $hold->biblio->items; + $item = $items->count ? $item->next : undef; } my $unblessed_hold = $hold->unblessed; - $unblessed_hold->{barcode} = GetBarcodeFromItemnumber($item); + + $unblessed_hold->{barcode} = $item ? $item->barcode : undef; + push @holds, $unblessed_hold; } return \@holds; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 7f4880f596..d36eb15651 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -903,6 +903,8 @@ foreach my $tag ( keys %{$tagslib}){ } @loop_data = sort {$a->{subfield} cmp $b->{subfield} } @loop_data; +my $item = Koha::Items->find($itemnumber); # We certainly want to fetch it earlier + # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param( biblionumber => $biblionumber, @@ -912,7 +914,7 @@ $template->param( item_header_loop => \@header_value_loop, item => \@loop_data, itemnumber => $itemnumber, - barcode => GetBarcodeFromItemnumber($itemnumber), + barcode => $item ? $item->barcode : undef, itemtagfield => $itemtagfield, itemtagsubfield => $itemtagsubfield, op => $nextop, diff --git a/svc/checkin b/svc/checkin index 78db9d923d..9b72abaa79 100755 --- a/svc/checkin +++ b/svc/checkin @@ -24,10 +24,11 @@ use CGI; use JSON qw(to_json); use C4::Circulation; -use C4::Items qw(GetBarcodeFromItemnumber GetItem ModItem); +use C4::Items qw(GetItem ModItem); use C4::Context; use C4::Auth qw(check_cookie_auth); use Koha::Checkouts; +use Koha::Items; my $input = new CGI; @@ -53,7 +54,9 @@ my $branchcode = $input->param('branchcode') $override_limit = $override_limit ? $override_limit eq 'true' : undef; $exempt_fine = $exempt_fine ? $exempt_fine eq 'true' : undef; -my $barcode = GetBarcodeFromItemnumber($itemnumber); +my $item = Koha::Items->find($itemnumber); + +my $barcode = $item ? $item->barcode : undef; # We certainly will want to return an error code my $data; $data->{itemnumber} = $itemnumber; -- 2.11.0