From 24f4b3be9f48fd517e1993b9ac92cf54634329a3 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Mar 2017 19:50:18 -0300 Subject: [PATCH] Bug 18296: C4::Items - Remove GetItemInfosOf At this point this subroutine is only used once, from reserve/request.pl. Since we already have the items, it's easy to populate the different hashes as the rest of the code is expecting it. Test plan: You need to create analytical record relationships ( EasyAnalyticalRecords needs to be set). Link an item to a biblio using the 'Edit > Link to host item' menu from the biblio detail page. From the staff interface place a hold on the biblio. You should see the items from the biblio and the one you just linked --- C4/Items.pm | 21 --------------------- labels/label-item-search.pl | 1 - reserve/request.pl | 21 ++++++++++++--------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 4eaa6af..b9000ce 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -70,7 +70,6 @@ BEGIN { GetLostItems GetItemsForInventory GetItemsCount - GetItemInfosOf GetItemsByBiblioitemnumber GetItemsInfo GetItemsLocationInfo @@ -947,26 +946,6 @@ sub GetItemsCount { return ($count); } -=head2 GetItemInfosOf - - GetItemInfosOf(@itemnumbers); - -=cut - -sub GetItemInfosOf { - my @itemnumbers = @_; - - my $itemnumber_values = @itemnumbers ? join( ',', @itemnumbers ) : "''"; - - my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM items - WHERE itemnumber IN ($itemnumber_values) - "; - return $dbh->selectall_hashref($query, 'itemnumber'); -} - =head2 GetItemsByBiblioitemnumber GetItemsByBiblioitemnumber($biblioitemnumber); diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 1e81647..16703aa 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -30,7 +30,6 @@ use C4::Output qw(output_html_with_http_headers); use C4::Context; use C4::Search qw(SimpleSearch); use C4::Biblio qw(TransformMarcToKoha); -use C4::Items qw(GetItemInfosOf); use C4::Koha qw(GetItemTypes); use C4::Creators::Lib qw(html_table); use C4::Debug; diff --git a/reserve/request.pl b/reserve/request.pl index d622054..532331d 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -44,6 +44,7 @@ use C4::Members; use C4::Search; # enabled_staff_search_views use Koha::DateUtils; use Koha::Holds; +use Koha::Items; use Koha::Libraries; use Koha::Patrons; @@ -292,28 +293,30 @@ foreach my $biblionumber (@biblionumbers) { my %itemnumbers_of_biblioitem; - ## $items is array of 'item' table numbers - my $items = Koha::Items->search({ biblionumber => $biblionumber }); - my @itemnumbers = $items->get_column('itemnumber'); my @hostitems = get_hostitemnumbers_of($biblionumber); + my @itemnumbers; if (@hostitems){ $template->param('hostitemsflag' => 1); push(@itemnumbers, @hostitems); } - if (!@itemnumbers) { + my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } }); + + unless ( $items->count ) { + # FIXME Then why do we continue? $template->param('noitems' => 1); $biblioloopiter{noitems} = 1; } - ## Hash of item number to 'item' table fields - my $iteminfos_of = GetItemInfosOf(@itemnumbers); - ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers, ## when by definition all of the itemnumber have the same biblioitemnumber - foreach my $itemnumber (@itemnumbers) { - my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber}; + my ( $itemnumbers_of_biblioitem, $iteminfos_of); + while ( my $item = $items->next ) { + $item = $item->unblessed; + my $biblioitemnumber = $item->{biblioitemnumber}; + my $itemnumber = $item->{itemnumber}; push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber ); + $iteminfos_of->{$itemnumber} = $item; } ## Should be same as biblionumber -- 2.9.3