[Koha-patches] [PATCH] (bug #4321) clean C4::Biblio::GetBiblio and uses

Nahuel ANGELINETTI nahuel.angelinetti at biblibre.com
Thu Mar 18 14:56:38 CET 2010


This change the getbiblio function to be correctly coded, and change all places where it was used.
---
 C4/Biblio.pm                        |   18 +++++++++---------
 C4/ILSDI/Services.pm                |    6 +++---
 C4/ImportBatch.pm                   |    4 ++--
 C4/Serials.pm                       |    2 +-
 catalogue/issuehistory.pl           |    4 ++--
 virtualshelves/addbybiblionumber.pl |   12 ++++++------
 6 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index ded50fc..2209467 100755
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -884,7 +884,7 @@ sub GetISBDView {
 
 =over 4
 
-( $count, @results ) = &GetBiblio($biblionumber);
+$results = &GetBiblio($biblionumber);
 
 =back
 
@@ -894,15 +894,15 @@ sub GetBiblio {
     my ($biblionumber) = @_;
     my $dbh            = C4::Context->dbh;
     my $sth            = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?");
-    my $count          = 0;
-    my @results;
+
     $sth->execute($biblionumber);
-    while ( my $data = $sth->fetchrow_hashref ) {
-        $results[$count] = $data;
-        $count++;
-    }    # while
-    $sth->finish;
-    return ( $count, @results );
+    
+    if ( my $data = $sth->fetchrow_hashref ) {
+        return $data;
+    }else{
+        return undef;
+    }
+    
 }    # sub GetBiblio
 
 =head2 GetBiblioItemInfosOf
diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm
index bb32166..fd96826 100644
--- a/C4/ILSDI/Services.pm
+++ b/C4/ILSDI/Services.pm
@@ -406,7 +406,7 @@ sub GetPatronInfo {
             # Add additional fields
             $reserve->{'item'}       = $item;
             $reserve->{'branchname'} = $branchname;
-            $reserve->{'title'}      = ( GetBiblio( $reserve->{'biblionumber'} ) )[1]->{'title'};
+            $reserve->{'title'}      = GetBiblio( $reserve->{'biblionumber'} )->{'title'};
         }
         $borrower->{'holds'}->{'hold'} = \@reserves;
     }
@@ -605,7 +605,7 @@ sub HoldTitle {
 
     # Get the biblio record, or return an error code
     my $biblionumber = $cgi->param('bib_id');
-    my ( $count, $biblio ) = GetBiblio($biblionumber);
+    my $biblio = GetBiblio($biblionumber);
     if ( not $biblio->{'biblionumber'} ) {
         return { message => 'RecordNotFound' };
     }
@@ -678,7 +678,7 @@ sub HoldItem {
 
     # Get the biblio or return an error code
     my $biblionumber = $cgi->param('bib_id');
-    my ( $count, $biblio ) = GetBiblio($biblionumber);
+    my $biblio = GetBiblio($biblionumber);
     if ( not $biblio->{'biblionumber'} ) {
         return { message => 'RecordNotFound' };
     }
diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm
index f8b5d54..e4dd3fe 100644
--- a/C4/ImportBatch.pm
+++ b/C4/ImportBatch.pm
@@ -503,7 +503,7 @@ sub BatchCommitBibRecords {
         } elsif ($bib_result eq 'replace') {
             $num_updated++;
             my $biblionumber = $bib_match;
-            my ($count, $oldbiblio) = GetBiblio($biblionumber);
+            my $oldbiblio = GetBiblio($biblionumber);
             my $oldxml = GetXmlBiblio($biblionumber);
 
             # remove item fields so that they don't get
@@ -649,7 +649,7 @@ sub BatchRevertBibRecords {
             $num_reverted++;
             my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'});
             my $biblionumber = $rowref->{'matched_biblionumber'};
-            my ($count, $oldbiblio) = GetBiblio($biblionumber);
+            my $oldbiblio = GetBiblio($biblionumber);
             $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
             ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
             SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
diff --git a/C4/Serials.pm b/C4/Serials.pm
index 439bd01..55dd8e0 100644
--- a/C4/Serials.pm
+++ b/C4/Serials.pm
@@ -1393,7 +1393,7 @@ sub NewSubscription {
     logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
 
     #set serial flag on biblio if not already set.
-    my ( $null, ($bib) ) = GetBiblio($biblionumber);
+    my $bib = GetBiblio($biblionumber);
     if ( !$bib->{'serial'} ) {
         my $record = GetMarcBiblio($biblionumber);
         my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
diff --git a/catalogue/issuehistory.pl b/catalogue/issuehistory.pl
index 8790bb5..1e1856f 100755
--- a/catalogue/issuehistory.pl
+++ b/catalogue/issuehistory.pl
@@ -56,10 +56,10 @@ if ($itemnumber){
 	);
 } else {
 	$issues = GetBiblioIssues($biblionumber);
-	my (undef, at biblio)=GetBiblio($biblionumber);
+	my $biblio = GetBiblio($biblionumber);
 	my $total  = scalar @$issues;
 	$template->param(
-		%{$biblio[0]},
+		%{$biblio},
 	);
 } 
 foreach (@$issues){
diff --git a/virtualshelves/addbybiblionumber.pl b/virtualshelves/addbybiblionumber.pl
index 8b8a6ca..9aaaa03 100755
--- a/virtualshelves/addbybiblionumber.pl
+++ b/virtualshelves/addbybiblionumber.pl
@@ -198,21 +198,21 @@ else {    # this shelf doesn't already exist.
     );
 
     unless (@biblionumbers) {
-        my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
+        my $biblio = GetBiblio($biblionumber);
     
         $template->param
           (
            biblionumber      => $biblionumber,
-           title             => $biblios[0]->{'title'},
-           author            => $biblios[0]->{'author'},
+           title             => $biblio->{'title'},
+           author            => $biblio->{'author'},
           );
     } else {
         my @biblioloop = ();
         foreach my $biblionumber (@biblionumbers) {
-            my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
+            my $biblio = GetBiblio($biblionumber);
             my %biblioiter = (
-                              title=>$biblios[0]->{'title'},
-                              author=>$biblios[0]->{'author'}
+                              title =>$biblio->{'title'},
+                              author=>$biblio->{'author'}
                              );
             push @biblioloop, \%biblioiter;
         }
-- 
1.6.3.3




More information about the Koha-patches mailing list