Bugzilla – Attachment 15644 Details for
Bug 9656
fines.pl creating a log file should be optional
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 9656: Make logging to a file optional (for fines)
SIGNED-OFF-Bug-9656-Make-logging-to-a-file-optiona.patch (text/plain), 3.32 KB, created by
Bernardo Gonzalez Kriegel
on 2013-02-23 10:34:25 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 9656: Make logging to a file optional (for fines)
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2013-02-23 10:34:25 UTC
Size:
3.32 KB
patch
obsolete
>From ffc81d0df14305859031e0ee957af2691a8e3f62 Mon Sep 17 00:00:00 2001 >From: Chris Cormack <chrisc@catalyst.net.nz> >Date: Thu, 21 Feb 2013 22:10:48 +1300 >Subject: [PATCH] [SIGNED-OFF] Bug 9656: Make logging to a file optional (for > fines) > >To test: >1/ Before the patch run misc/cronjobs/fines.pl > Notice that a file has been written to /tmp > >2/ rm the file > >3/ Apply the patch and run the script again > Notice the file is not created > >4/ run the script with -l > Notice the file is created again > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> > >Comment: Now it work as described. No errors. >--- > misc/cronjobs/fines.pl | 43 +++++++++++++++++++++++++++++-------------- > 1 file changed, 29 insertions(+), 14 deletions(-) > >diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl >index 27bd061..3801450 100755 >--- a/misc/cronjobs/fines.pl >+++ b/misc/cronjobs/fines.pl >@@ -42,10 +42,12 @@ use Koha::DateUtils; > my $help; > my $verbose; > my $output_dir; >+my $log; > > GetOptions( > 'h|help' => \$help, > 'v|verbose' => \$verbose, >+ 'l|log' => \$log, > 'o|out:s' => \$output_dir, > ); > my $usage = << 'ENDUSAGE'; >@@ -58,6 +60,7 @@ calculated but not applied. > > This script has the following parameters : > -h --help: this message >+ -l --log: log the output to a file > -o --out: ouput directory for logs (defaults to env or /tmp if !exist) > -v --verbose > >@@ -81,11 +84,13 @@ my %is_holiday; > my $today = DateTime->now( time_zone => C4::Context->tz() ); > my $filename = get_filename($output_dir); > >-open my $fh, '>>', $filename or croak "Cannot write file $filename: $!"; >-print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); >-print {$fh} "\n"; >- >-my $counted = 0; >+my $fh; >+if ($log) { >+ open $fh, '>>', $filename or croak "Cannot write file $filename: $!"; >+ print {$fh} join $delim, ( @borrower_fields, @item_fields, @other_fields ); >+ print {$fh} "\n"; >+} >+my $counted = 0; > my $overdues = Getoverdues(); > for my $overdue ( @{$overdues} ) { > if ( !defined $overdue->{borrowernumber} ) { >@@ -126,19 +131,29 @@ for my $overdue ( @{$overdues} ) { > ); > } > } >- my @cells; >- push @cells, >- map { defined $borrower->{$_} ? $borrower->{$_} : q{} } @borrower_fields; >- push @cells, map { $overdue->{$_} } @item_fields; >- push @cells, $type, $unitcounttotal, $amount; >- say {$fh} join $delim, @cells; >+ if ($log) { >+ my @cells; >+ push @cells, >+ map { defined $borrower->{$_} ? $borrower->{$_} : q{} } >+ @borrower_fields; >+ push @cells, map { $overdue->{$_} } @item_fields; >+ push @cells, $type, $unitcounttotal, $amount; >+ say {$fh} join $delim, @cells; >+ } >+} >+if ($log){ >+ close $fh; > } >-close $fh; > > if ($verbose) { > my $overdue_items = @{$overdues}; > print <<"EOM"; >-Fines assessment -- $today -- Saved to $filename >+Fines assessment -- $today >+EOM >+ if ($log) { >+ say "Saved to $filename"; >+ } >+ print <<"EOM"; > Number of Overdue Items: > counted $overdue_items > reported $counted >@@ -165,7 +180,7 @@ sub get_filename { > $name =~ s/\W//; > $name .= join q{}, q{_}, $today->ymd(), '.log'; > $name = File::Spec->catfile( $directory, $name ); >- if ($verbose) { >+ if ($verbose && $log) { > say "writing to $name"; > } > return $name; >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9656
:
15581
|
15643
|
15644
|
15767
|
15814
|
15860
|
15861