Bug 18296: C4::Items - Remove GetItemInfosOf
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 15 Mar 2017 22:50:18 +0000 (19:50 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 7 Jun 2017 14:30:25 +0000 (11:30 -0300)
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

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

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

C4/Items.pm
labels/label-item-search.pl
reserve/request.pl

index 5d2f8ae..26c14a1 100644 (file)
@@ -69,7 +69,6 @@ BEGIN {
         CheckItemPreSave
     
         GetItemsForInventory
-        GetItemInfosOf
         GetItemsByBiblioitemnumber
         GetItemsInfo
        GetItemsLocationInfo
@@ -923,26 +922,6 @@ sub GetItemsForInventory {
     return (\@results, $iTotalRecords);
 }
 
-=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);
index d318987..ddc0bf8 100755 (executable)
@@ -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::Creators::Lib qw(html_table);
 use C4::Debug;
 
index b33ae70..9ec204c 100755 (executable)
@@ -294,28 +294,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