From 02633edc7de5f92d1fd69747b1fbe9ae9b38b891 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 6 Aug 2018 16:40:44 -0300 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- C4/ILSDI/Services.pm | 8 +++++--- C4/Reserves.pm | 8 ++++---- C4/SIP/ILS/Patron.pm | 1 - cataloguing/additem.pl | 4 ++-- tools/batch_delete_records.pl | 5 +++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index d3920dcc2f..4e0877a551 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -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 .= " \n"; $out .= " \n"; $out .= " \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 .= " \n"; $out .= " \n"; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 3b1ac5ef9f..8e8bea3349 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -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; diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 3d9de0d88d..82ccc756f2 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -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; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index d36eb15651..6af351d375 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -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; diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 149b44ddc0..0194c5dcc3 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -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 $@ ) { -- 2.39.5