[Koha-patches] [PATCH] Bug 3808 Fix off by one error in script

Colin Campbell colin.campbell at ptfs-europe.com
Tue Nov 24 17:22:08 CET 2009


Script was supplying an extra empty record to the template
Changed loop to remove the extra variable that was tempting
us into the error.
Removed the element highlight as the template didn't use (or need) it
---
 acqui/neworderbiblio.pl |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl
index 824b664..b41b0f5 100755
--- a/acqui/neworderbiblio.pl
+++ b/acqui/neworderbiblio.pl
@@ -55,6 +55,7 @@ the basket number to know on which basket this script have to add a new order.
 =cut
 
 use strict;
+use warnings;
 use C4::Search;
 use CGI;
 use C4::Bookseller;
@@ -104,25 +105,23 @@ if (defined $error) {
     exit;
 }
 
-my @results;
+my $results = [];
 
-foreach my $i ( 0 .. scalar @$marcresults ) {
-    my %resultsloop;
-    my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
-    my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
+foreach my $result ( @{$marcresults} ) {
+    my $marcrecord = MARC::File::USMARC::decode($result);
+    my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{});
 
     #build the hash for the template.
-    %resultsloop=%$biblio;
-    $resultsloop{highlight}       = ($i % 2)?(1):(0);
+    my %resultsloop=%{$biblio};
     $resultsloop{booksellerid} = $booksellerid;
-    push @results, \%resultsloop;
+    push @{ $results }, \%resultsloop;
 }
 
 $template->param(
     basketno             => $basketno,
     booksellerid     => $bookseller->{'id'},
     name             => $bookseller->{'name'},
-    resultsloop          => \@results,
+    resultsloop          => $results,
     total                => $total_hits,
     query                => $query,
     pagination_bar       => pagination_bar( "$ENV{'SCRIPT_NAME'}?q=$query&booksellerid=$booksellerid&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
-- 
1.6.5.2




More information about the Koha-patches mailing list