Browse Source

Bug 21183: Replace C4::Items::GetItemnumberFromBarcode calls

C4::Items::GetItemnumberFromBarcode calls can be replaced with
  Koha::Items->find({ barcode => $barcode });

We should make sure the barcode existed in DB and so that ->find
returns an object. Note that most of the time we just wanted to know if
the barcode existed.
The changes are very simple, the only one that need attention is
the one in batchMod.pl. It is basically reusing what we did on
bug 21141.

Test plan:
Use the batch item modification/deletion tools to modify/delete items
from their barcode (using the textarea or a file)

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
18.11.x
Jonathan Druart 6 years ago
committed by Nick Clemens
parent
commit
2b1b168ec4
  1. 5
      C4/ImportBatch.pm
  2. 6
      C4/Items.pm
  3. 5
      circ/returns.pl
  4. 9
      labels/label-edit-batch.pl
  5. 4
      members/mancredit.pl
  6. 4
      members/maninvoice.pl
  7. 5
      rotating_collections/addItems.pl
  8. 9
      serials/serials-edit.pl
  9. 27
      tools/batchMod.pl

5
C4/ImportBatch.pm

@ -27,6 +27,7 @@ use C4::Items;
use C4::Charset;
use C4::AuthoritiesMarc;
use C4::MarcModificationTemplates;
use Koha::Items;
use Koha::Plugins::Handler;
use Koha::Logger;
@ -747,7 +748,7 @@ sub BatchCommitItems {
my $item = TransformMarcToKoha( $item_marc );
my $duplicate_barcode = exists( $item->{'barcode'} ) && GetItemnumberFromBarcode( $item->{'barcode'} );
my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} });
my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
@ -761,7 +762,7 @@ sub BatchCommitItems {
$updsth->finish();
$num_items_replaced++;
} elsif ( $action eq "replace" && $duplicate_barcode ) {
my $itemnumber = GetItemnumberFromBarcode( $item->{'barcode'} );
my $itemnumber = $duplicate_barcode->itemnumber;
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
$updsth->bind_param( 1, 'imported' );
$updsth->bind_param( 2, $item->{itemnumber} );

6
C4/Items.pm

@ -745,10 +745,10 @@ sub CheckItemPreSave {
# check for duplicate barcode
if (exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'}) {
my $existing_itemnumber = GetItemnumberFromBarcode($item_ref->{'barcode'});
if ($existing_itemnumber) {
my $existing_item= Koha::Items->find({barcode => $item_ref->{'barcode'}});
if ($existing_item) {
if (!exists $item_ref->{'itemnumber'} # new item
or $item_ref->{'itemnumber'} != $existing_itemnumber) { # existing item
or $item_ref->{'itemnumber'} != $existing_item->itemnumber) { # existing item
$errors{'duplicate_barcode'} = $item_ref->{'barcode'};
}
}

5
circ/returns.pl

@ -593,8 +593,9 @@ $template->param(
AudioAlerts => C4::Context->preference("AudioAlerts"),
);
$itemnumber = GetItemnumberFromBarcode( $barcode );
if ( $itemnumber ) {
my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
if ( $item_from_barcode ) {
$itemnumber = $item_from_barcode->itemnumber;
my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
if ( $holdingBranch and $collectionBranch ) {
$holdingBranch //= '';

9
labels/label-edit-batch.pl

@ -25,10 +25,12 @@ use CGI qw ( -utf8 );
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
use C4::Items qw(GetItem GetItemnumberFromBarcode);
use C4::Items qw(GetItem);
use C4::Creators;
use C4::Labels;
use Koha::Items;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
@ -90,9 +92,8 @@ elsif ($op eq 'add') {
push @item_numbers, $number;
}
elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm
if( my $item_number = GetItemnumberFromBarcode($number) ){
push @item_numbers, $item_number;
}
my $item = Koha::Items->find({barcode => $number});
push @item_numbers, $item->itemnumber if $item;
}
}
}

4
members/mancredit.pl

@ -34,6 +34,7 @@ use C4::Items;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Account;
use Koha::Items;
use Koha::Patrons;
use Koha::Patron::Categories;
use Koha::Token;
@ -67,7 +68,8 @@ if ($add){
my $barcode = $input->param('barcode');
my $item_id;
if ($barcode) {
$item_id = GetItemnumberFromBarcode($barcode);
my $item = Koha::Items->find({barcode => $barcode});
$item_id = $item->itemnumber if $item;
}
my $description = $input->param('desc');
my $note = $input->param('note');

4
members/maninvoice.pl

@ -33,6 +33,7 @@ use C4::Items;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Token;
use Koha::Items;
use Koha::Patrons;
use Koha::Patron::Categories;
@ -61,7 +62,8 @@ if ($add){
my $barcode=$input->param('barcode');
my $itemnum;
if ($barcode) {
$itemnum = GetItemnumberFromBarcode($barcode);
my $item = Koha::Items->find({barcode => $barcode});
$itemnum = $item->itemnumber if $item;
}
my $desc=$input->param('desc');
my $amount=$input->param('amount');

5
rotating_collections/addItems.pl

@ -24,6 +24,8 @@ use C4::Context;
use C4::RotatingCollections;
use C4::Items;
use Koha::Items;
use CGI qw ( -utf8 );
my $query = new CGI;
@ -44,7 +46,8 @@ if ( $query->param('action') eq 'addItem' ) {
my $colId = $query->param('colId');
my $barcode = $query->param('barcode');
my $removeItem = $query->param('removeItem');
my $itemnumber = GetItemnumberFromBarcode($barcode);
my $item = Koha::Items->find({barcode => $barcode});
my $itemnumber = $item ? $item->itemnumber : undef;
my ( $success, $errorCode, $errorMessage );

9
serials/serials-edit.pl

@ -72,7 +72,9 @@ use C4::Output;
use C4::Context;
use C4::Serials;
use C4::Search qw/enabled_staff_search_views/;
use Koha::DateUtils;
use Koha::Items;
use Koha::Serial::Items;
use List::MoreUtils qw/uniq/;
@ -372,11 +374,8 @@ if ( $op and $op eq 'serialchangestatus' ) {
)
)
{
$exists = GetItemnumberFromBarcode(
$bib_record->subfield(
$barcodetagfield, $barcodetagsubfield
)
);
my $barcode = $bib_record->subfield( $barcodetagfield, $barcodetagsubfield );
$exists = Koha::Items->find({barcode => $barcode});
}
# push @errors,"barcode_not_unique" if($exists);

27
tools/batchMod.pl

@ -245,15 +245,10 @@ if ($op eq "show"){
@contentlist = uniq @contentlist;
if ($filecontent eq 'barcode_file') {
foreach my $barcode (@contentlist) {
my $itemnumber = GetItemnumberFromBarcode($barcode);
if ($itemnumber) {
push @itemnumbers,$itemnumber;
} else {
push @notfoundbarcodes, $barcode;
}
}
my $existing_items = Koha::Items->search({ itemnumber => \@contentlist });
@itemnumbers = $existing_items->get_column('itemnumber');
my %exists = map {$_=>1} @{$existing_items->get_column('barcode')};
@notfoundbarcodes = grep { !$exists{$_} } @contentlist;
}
elsif ( $filecontent eq 'itemid_file') {
@itemnumbers = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber');
@ -270,16 +265,10 @@ if ($op eq "show"){
if ( my $list=$input->param('barcodelist')){
push my @barcodelist, uniq( split(/\s\n/, $list) );
foreach my $barcode (@barcodelist) {
my $itemnumber = GetItemnumberFromBarcode($barcode);
if ($itemnumber) {
push @itemnumbers,$itemnumber;
} else {
push @notfoundbarcodes, $barcode;
}
}
my $existing_items = Koha::Items->search({ barcode => \@barcodelist });
@itemnumbers = $existing_items->get_column('itemnumber');
my %exists = map {$_=>1} @{$existing_items->get_column('barcode')};
@notfoundbarcodes = grep { !$exists{$_} } @barcodelist;
}
}

Loading…
Cancel
Save