Browse Source

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?

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Jonathan Druart 6 years ago
committed by Nick Clemens
parent
commit
62a075987a
  1. 15
      C4/SIP/ILS/Patron.pm
  2. 4
      cataloguing/additem.pl
  3. 7
      svc/checkin

15
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;

4
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,

7
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;

Loading…
Cancel
Save