From f08a1c9fe1db3220ef791411ca9513feb813e4a0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 30 Sep 2013 15:10:25 +0200 Subject: [PATCH] Bug 8007: Followup: fix read dir error This patch fixes: - an error on reading the discharges directory - the parameter sent to CancelReserves (API has been changed) - the parameters sent to output_pref (API has been changed) --- C4/Discharges.pm | 22 ++++++++++++++-------- members/discharge.pl | 6 +++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/C4/Discharges.pm b/C4/Discharges.pm index 6774c79..aac0703 100644 --- a/C4/Discharges.pm +++ b/C4/Discharges.pm @@ -62,16 +62,22 @@ sub GetDischarges { my $dischargePath = C4::Context->preference('dischargePath'); my $dischargeWebPath = C4::Context->preference('dischargeWebPath'); - my @return; - - my $pdf_path = qq{$dischargePath/$borrowernumber/*.pdf}; - my @files = <$pdf_path>; - foreach (@files) { - my ($file, $dir, $ext) = fileparse("$_"); - push @return, $file; + my @discharges; + + my $discharges_dir = qq{$dischargePath/$borrowernumber}; + opendir my $dh, $discharges_dir + or warn qq{Error: Can't open dir $discharges_dir} + and return (); + + for my $file ( readdir $dh ) { + next unless $file =~ /\.pdf$/; + my $filepath = qq{$discharges_dir/$file}; + my ($file, $dir, $ext) = fileparse( $filepath ); + push @discharges, $file; } + closedir $dh; - return @return; + return @discharges; } =head2 removeUnprocessedDischarges($borrowernumber) diff --git a/members/discharge.pl b/members/discharge.pl index cb232d4..d041a72 100755 --- a/members/discharge.pl +++ b/members/discharge.pl @@ -71,8 +71,8 @@ if ( $input->param('borrowernumber') ) { # Generating discharge if needed if ($input->param('generatedischarge')) { # If borrower has pending reserves, we cancel them - foreach (@reserves) { - CancelReserve($_->{'reservenumber'}); + for my $reserve (@reserves) { + CancelReserve({ reserve_id => $reserve->{reserve_id} }); } $hasreserves = 0; @@ -118,7 +118,7 @@ if ( $input->param('borrowernumber') ) { # Error handling: # Check if we really got our discharge as a pdf file - my $todayiso = output_pref(dt_from_string(), 'iso', 1); + my $todayiso = output_pref(dt_from_string(), 'iso', 0, 1); # If we don't, then unless (-e "$dischargePath/$borrowernumber/discharge-$todayiso.pdf") { # Show an error message to the librarian -- 1.7.10.4