From 4abdfe7b122a6f2601e88dd0e92403b6fba57506 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 22 Jan 2014 09:50:16 -0500 Subject: [PATCH] [SIGNED-OFF] Bug 11598 - Add --text option to overdue_notices similar to --html option We have a number of reports of libraries that were upset by Bug 10720 being fixed! These libraries preferred this single file output, but as text only. We should bring back this behavior, but as a feature, not a bug. Test Plan: 1) Apply this patch 2) Run overdue_notices.pl --html 3) Note the output is wrapped in html tags 4) Run overdue_notices.pl --text 5) Note the same output, but not wrapped in html tags Signed-off-by: wajasu --- misc/cronjobs/overdue_notices.pl | 62 ++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 7745047..ca3a991 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -64,6 +64,7 @@ overdue_notices.pl -library only deal with overdues from this library (repeatable : several libraries can be given) -csv populate CSV file -html Output html to a file in the given directory + -text Output plain text to a file in the given directory -itemscontent item information in templates -borcat category code that must be included -borcatout category code that must be excluded @@ -119,6 +120,14 @@ directory. This can be downloaded or futher processed by library staff. The file will be called notices-YYYY-MM-DD.html and placed in the directory specified. +=item B<-text> + +Produces plain text data. if patron does not have a mail address or +-n (no mail) flag is set, a text file is generated in the specified +directory. This can be downloaded or futher processed by library staff. +The file will be called notices-YYYY-MM-DD.txt and placed in the directory +specified. + =item B<-itemscontent> comma separated list of fields that get substituted into templates in @@ -274,6 +283,7 @@ my @emails_to_use; # Emails to use for messaging my @emails; # Emails given in command-line parameters my $csvfilename; my $htmlfilename; +my $text_filename; my $triggered = 0; my $listall = 0; my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) ); @@ -290,6 +300,7 @@ GetOptions( 'library=s' => \@branchcodes, 'csv:s' => \$csvfilename, # this optional argument gets '' if not supplied. 'html:s' => \$htmlfilename, # this optional argument gets '' if not supplied. + 'text:s' => \$text_filename, # this optional argument gets '' if not supplied. 'itemscontent=s' => \$itemscontent, 'list-all' => \$listall, 't|triggered' => \$triggered, @@ -375,26 +386,34 @@ if ( defined $csvfilename ) { } @branches = @overduebranches unless @branches; -our $html_fh; +our $fh; if ( defined $htmlfilename ) { if ( $htmlfilename eq '' ) { - $html_fh = *STDOUT; + $fh = *STDOUT; } else { my $today = DateTime->now(time_zone => C4::Context->tz ); - open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html"); + open $fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html"); } - print $html_fh "\n"; - print $html_fh "\n"; - print $html_fh "\n"; - print $html_fh "\n"; - print $html_fh "\n"; + print $fh "\n"; + print $fh "\n"; + print $fh "\n"; + print $fh "\n"; + print $fh "\n"; +} +elsif ( defined $text_filename ) { + if ( $text_filename eq '' ) { + $fh = *STDOUT; + } else { + my $today = DateTime->now(time_zone => C4::Context->tz ); + open $fh, ">",File::Spec->catdir ($text_filename,"notices-".$today->ymd().".txt"); + } } foreach my $branchcode (@branches) { @@ -606,7 +625,7 @@ END_SQL email => $notice_email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', + outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : defined $text_filename ? 'text' : '', } ); } @@ -620,7 +639,10 @@ END_SQL print $csv_fh @output_chunks; } elsif ( defined $htmlfilename ) { - print $html_fh @output_chunks; + print $fh @output_chunks; + } + elsif ( defined $text_filename ) { + print $fh @output_chunks; } elsif ($nomail){ local $, = "\f"; # pagebreak @@ -658,9 +680,11 @@ if ($csvfilename) { } if ( defined $htmlfilename ) { - print $html_fh "\n"; - print $html_fh "\n"; - close $html_fh; + print $fh "\n"; + print $fh "\n"; + close $fh; +} elsif ( defined $text_filename ) { + close $fh; } =head1 INTERNAL METHODS -- 1.8.5.3