Bug 21201: Replace C4::Items::GetItemnumbersForBiblio calls

Those calls to C4::Items::GetItemnumbersForBiblio can be replaced with
    my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber")

Test plan:
- Use the GetAvailability service of ILS-DI
- Try to place a hold on an item that is available and another one
- Use the batch record deletion tool to remove record with and without items.

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>
This commit is contained in:
Jonathan Druart 2018-08-06 16:40:44 -03:00 committed by Nick Clemens
parent a42af28317
commit 02633edc7d
5 changed files with 14 additions and 12 deletions

View File

@ -38,6 +38,7 @@ use Koha::DateUtils;
use Koha::Biblios;
use Koha::Checkouts;
use Koha::Items;
use Koha::Libraries;
use Koha::Patrons;
@ -138,14 +139,15 @@ sub GetAvailability {
} else {
my $status;
my $msg;
my $items = GetItemnumbersForBiblio($id);
if ($items) {
my $items = Koha::Items->search({ biblionumber => $id });
if ($items->count) {
# Open XML
$out .= " <dlf:record>\n";
$out .= " <dlf:bibliographic id=\"" .$id. "\" />\n";
$out .= " <dlf:items>\n";
# We loop over the items to clean them
foreach my $itemnumber (@$items) {
while ( my $item = $items->next ) {
my $itemnumber = $item->itemnumber;
my ( $biblionumber, $status, $msg, $location ) = _availability($itemnumber);
$out .= " <dlf:item id=\"" . $itemnumber . "\">\n";
$out .= " <dlf:simpleavailability>\n";

View File

@ -275,16 +275,16 @@ See CanItemBeReserved() for possible return values.
sub CanBookBeReserved{
my ($borrowernumber, $biblionumber) = @_;
my $items = GetItemnumbersForBiblio($biblionumber);
my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber})->get_column("itemnumber");
#get items linked via host records
my @hostitems = get_hostitemnumbers_of($biblionumber);
if (@hostitems){
push (@$items,@hostitems);
push (@itemnumbers, @hostitems);
}
my $canReserve;
foreach my $item (@$items) {
$canReserve = CanItemBeReserved( $borrowernumber, $item );
foreach my $itemnumber (@itemnumbers) {
$canReserve = CanItemBeReserved( $borrowernumber, $itemnumber );
return $canReserve if $canReserve->{status} eq 'OK';
}
return $canReserve;

View File

@ -22,7 +22,6 @@ use C4::Context;
use C4::Koha;
use C4::Members;
use C4::Reserves;
use C4::Items qw( GetItemnumbersForBiblio);
use C4::Auth qw(checkpw);
use Koha::Items;

View File

@ -652,8 +652,8 @@ if ($op eq "additem") {
#-------------------------------------------------------------------------------
} elsif ($op eq "delallitems") {
#-------------------------------------------------------------------------------
my $itemnumbers = C4::Items::GetItemnumbersForBiblio( $biblionumber );
foreach my $itemnumber ( @$itemnumbers ) {
my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber })->get_column('itemnumber');
foreach my $itemnumber ( @itemnumbers ) {
$error = C4::Items::DelItemCheck( $biblionumber, $itemnumber );
next if $error == 1; # Means ok
push @errors,$error;

View File

@ -30,6 +30,7 @@ use C4::Biblio;
use Koha::Authorities;
use Koha::Biblios;
use Koha::Items;
my $input = new CGI;
my $op = $input->param('op') // q|form|;
@ -84,7 +85,7 @@ if ( $op eq 'form' ) {
$biblio = $biblio->unblessed;
my $record = &GetMarcBiblio({ biblionumber => $record_id });
$biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
$biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
$biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
$biblio->{holds_count} = $holds_count;
$biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
push @records, $biblio;
@ -165,7 +166,7 @@ if ( $op eq 'form' ) {
}
# Delete items
my @itemnumbers = @{ C4::Items::GetItemnumbersForBiblio( $biblionumber ) };
my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber })->get_column('itemnumber');
ITEMNUMBER: for my $itemnumber ( @itemnumbers ) {
my $error = eval { C4::Items::DelItemCheck( $biblionumber, $itemnumber ) };
if ( $error != 1 or $@ ) {