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>
use C4::Charset;
use C4::AuthoritiesMarc;
use C4::MarcModificationTemplates;
use C4::Charset;
use C4::AuthoritiesMarc;
use C4::MarcModificationTemplates;
use Koha::Plugins::Handler;
use Koha::Logger;
use Koha::Plugins::Handler;
use Koha::Logger;
my $item = TransformMarcToKoha( $item_marc );
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 = ?");
my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
$updsth->finish();
$num_items_replaced++;
} elsif ( $action eq "replace" && $duplicate_barcode ) {
$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} );
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
$updsth->bind_param( 1, 'imported' );
$updsth->bind_param( 2, $item->{itemnumber} );
# check for duplicate barcode
if (exists $item_ref->{'barcode'} and defined $item_ref->{'barcode'}) {
# 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
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'};
}
}
$errors{'duplicate_barcode'} = $item_ref->{'barcode'};
}
}
AudioAlerts => C4::Context->preference("AudioAlerts"),
);
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 //= '';
my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
if ( $holdingBranch and $collectionBranch ) {
$holdingBranch //= '';
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);
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 C4::Creators;
use C4::Labels;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
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
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;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Account;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Account;
use Koha::Patrons;
use Koha::Patron::Categories;
use Koha::Token;
use Koha::Patrons;
use Koha::Patron::Categories;
use Koha::Token;
my $barcode = $input->param('barcode');
my $item_id;
if ($barcode) {
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');
}
my $description = $input->param('desc');
my $note = $input->param('note');
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Token;
use C4::Members::Attributes qw(GetBorrowerAttributes);
use Koha::Token;
use Koha::Patrons;
use Koha::Patron::Categories;
use Koha::Patrons;
use Koha::Patron::Categories;
my $barcode=$input->param('barcode');
my $itemnum;
if ($barcode) {
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');
}
my $desc=$input->param('desc');
my $amount=$input->param('amount');
use C4::RotatingCollections;
use C4::Items;
use C4::RotatingCollections;
use C4::Items;
use CGI qw ( -utf8 );
my $query = new CGI;
use CGI qw ( -utf8 );
my $query = new CGI;
my $colId = $query->param('colId');
my $barcode = $query->param('barcode');
my $removeItem = $query->param('removeItem');
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 );
my ( $success, $errorCode, $errorMessage );
use C4::Context;
use C4::Serials;
use C4::Search qw/enabled_staff_search_views/;
use C4::Context;
use C4::Serials;
use C4::Search qw/enabled_staff_search_views/;
use Koha::Serial::Items;
use List::MoreUtils qw/uniq/;
use Koha::Serial::Items;
use List::MoreUtils qw/uniq/;
- $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);
}
# push @errors,"barcode_not_unique" if($exists);
@contentlist = uniq @contentlist;
if ($filecontent eq 'barcode_file') {
@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');
}
elsif ( $filecontent eq 'itemid_file') {
@itemnumbers = Koha::Items->search({ itemnumber => \@contentlist })->get_column('itemnumber');
if ( my $list=$input->param('barcodelist')){
push my @barcodelist, uniq( split(/\s\n/, $list) );
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;