Bug 18255: Koha::Biblio - Replace GetBiblioItemByBiblioNumber with Koha::Biblio-...
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 13 Mar 2017 16:04:01 +0000 (13:04 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Mar 2018 14:45:38 +0000 (11:45 -0300)
The subroutine GetBiblioItemByBiblioNumber considers that we have a 1-N
relation between biblio and biblioitems, which is wrong (it's 1-1).
So the calls can be replaced with Koha::biblio->biblioitem, it will ease
the read of the code.

Test plan:
1. Use the ILSDI service to display info of a bibliographic record,
biblioitems fields must be displayed
2. Search for items, biblioitems info must be displayed as well in the
result table

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Biblio.pm
C4/ILSDI/Services.pm
catalogue/itemsearch.pl
cataloguing/merge.pl
serials/routing-preview.pl

index dac0656..4eed6b7 100644 (file)
@@ -69,7 +69,6 @@ BEGIN {
       GetMarcBiblio
       GetBiblioItemData
       GetBiblioItemInfosOf
-      GetBiblioItemByBiblioNumber
 
       &GetRecordValue
 
@@ -750,29 +749,6 @@ sub GetBiblioItemData {
     return ($data);
 }    # sub &GetBiblioItemData
 
-=head2 GetBiblioItemByBiblioNumber
-
-NOTE : This function has been copy/paste from C4/Biblio.pm from head before zebra integration.
-
-=cut
-
-sub GetBiblioItemByBiblioNumber {
-    my ($biblionumber) = @_;
-    my $dbh            = C4::Context->dbh;
-    my $sth            = $dbh->prepare("Select * FROM biblioitems WHERE biblionumber = ?");
-    my $count          = 0;
-    my @results;
-
-    $sth->execute($biblionumber);
-
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @results, $data;
-    }
-
-    $sth->finish;
-    return @results;
-}
-
 =head2 GetISBDView 
 
   $isbd = &GetISBDView({
index 7e021a5..9abc87e 100644 (file)
@@ -208,9 +208,13 @@ sub GetRecords {
     foreach my $biblionumber ( split( / /, $cgi->param('id') ) ) {
 
         # Get the biblioitem from the biblionumber
-        my $biblioitem = ( GetBiblioItemByBiblioNumber( $biblionumber, undef ) )[0];
-        if ( not $biblioitem->{'biblionumber'} ) {
+        my $biblio = Koha::Biblios->find( $biblionumber );
+        my $biblioitem = $biblio->biblioitem;
+        if ( $biblioitem ) {
+            $biblioitem = $biblioitem->unblessed;
+        } else {
             $biblioitem->{code} = "RecordNotFound";
+            # FIXME We should not need to process something else; next?
         }
 
         my $embed_items = 1;
@@ -223,7 +227,6 @@ sub GetRecords {
 
         # Get most of the needed data
         my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
-        my $biblio = Koha::Biblios->find( $biblionumber );
         my $holds  = $biblio->current_holds->unblessed;
         my $issues           = GetBiblioIssues($biblionumber);
         my $items            = GetItemsByBiblioitemnumber($biblioitemnumber);
index 369142e..517aa81 100755 (executable)
@@ -233,8 +233,9 @@ if (scalar keys %params > 0) {
         }
 
         foreach my $item (@$results) {
-            $item->{biblio} = Koha::Biblios->find( $item->{biblionumber} );
-            ($item->{biblioitem}) = GetBiblioItemByBiblioNumber($item->{biblionumber});
+            my $biblio = Koha::Biblios->find( $item->{biblionumber} );
+            $item->{biblio} = $biblio;
+            $item->{biblioitem} = $biblio->biblioitem->unblessed;
             $item->{status} = $notforloan_map->{$item->{notforloan}};
             if (defined $item->{location}) {
                 $item->{location} = $location_map->{$item->{location}};
index 4594671..e8b576a 100755 (executable)
@@ -159,8 +159,6 @@ if ($merge) {
 
     # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio)
     my @allorders = GetOrdersByBiblionumber($biblionumber);
-    my @tobiblioitem = GetBiblioItemByBiblioNumber ($ref_biblionumber);
-    my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber };
     foreach my $myorder (@allorders) {
         $myorder->{'biblionumber'} = $ref_biblionumber;
         ModOrder ($myorder);
index 798b14c..015005c 100755 (executable)
@@ -66,7 +66,6 @@ my $library;
 if($ok){
     # get biblio information....
     my $biblionumber = $subs->{'bibnum'};
-    my ($count2,@bibitems) = GetBiblioItemByBiblioNumber($biblionumber);
     my @itemresults = GetItemsInfo( $biblionumber );
     my $branch = @itemresults ? $itemresults[0]->{'holdingbranch'} : $subs->{branchcode};
     $library = Koha::Libraries->find($branch);
@@ -95,7 +94,7 @@ if($ok){
                     branchcode     => $branch
                 });
             } else {
-                AddReserve($branch,$routing->{borrowernumber},$biblionumber,\@bibitems,$routing->{ranking}, undef, undef, $notes,$title);
+                AddReserve($branch,$routing->{borrowernumber},$biblionumber,undef,$routing->{ranking}, undef, undef, $notes,$title);
         }
     }
        }