From 95b5bc80da46b41dee051f5fc1ec659da56597f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Tue, 14 Apr 2015 13:13:18 +0200 Subject: [PATCH] Bug 11603 Add --send|--nosend, fix stuf Fix --html without --letter_code Fix --ods which was producing a 2 lines ods file --- misc/cronjobs/gather_print_notices.pl | 44 +++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index b852680..30aec0c 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -21,8 +21,19 @@ use Getopt::Long; use File::Basename qw( dirname ); use Koha::DateUtils; -my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes ); - +my ( + $stylesheet, + $help, + $split, + $html, + $csv, + $ods, + $delimiter, + @letter_codes, + $send, +); + +$send = 1; GetOptions( 'h|help' => \$help, 's|split' => \$split, @@ -31,6 +42,7 @@ GetOptions( 'ods' => \$ods, 'd|delimiter:s' => \$delimiter, 'letter_code:s' => \@letter_codes, + 'send!' => \$send, ) || pod2usage(1); pod2usage(0) if $help; @@ -72,7 +84,7 @@ my @all_messages = @{ GetPrintMessages() }; ( grep { /^$letter_code$/ } @letter_codes ) ? $_ : () -} @all_messages; +} @all_messages if @letter_codes; exit unless @all_messages; my ( $html_filenames, $csv_filenames, $ods_filenames ); @@ -151,13 +163,15 @@ sub print_notices { }); } - foreach my $message ( @$branch_messages ) { - C4::Letters::_set_message_status( - { - message_id => $message->{'message_id'}, - status => 'sent' - } - ); + if ( $send ) { + foreach my $message ( @$branch_messages ) { + C4::Letters::_set_message_status( + { + message_id => $message->{'message_id'}, + status => 'sent' + } + ); + } } push @filenames, $filename; } @@ -227,7 +241,7 @@ sub generate_ods { my $table = $doc->getTable(0); my @headers; - my ( $nb_rows, $nb_cols ) = ( scalar(@$messages), 0 ); + my ( $nb_rows, $nb_cols, $i ) = ( scalar(@$messages), 0, 0 ); foreach my $message ( @$messages ) { my @lines = split /\n/, $message->{content}; chomp for @lines; @@ -244,10 +258,10 @@ sub generate_ods { $doc->cellValue( $row, $j, Encode::encode( 'UTF8', $header ) ); $j++; } + $i = 1; } shift @lines; # remove headers - my $i = 1; for my $line ( @lines ) { my @row_data = split $delimiter, $line; my $row = $doc->getRow( $table, $i ); @@ -282,6 +296,12 @@ The generated filename will be holdnotices-TODAY.[csv|html|ods] or holdnotices-T Define the output directory where the files will be generated. +=item B<--send|--nosend> + +After files have been generated, messages status is changed from 'pending' to +'sent'. This is the default action, without this parameter or with --send. +Using --nosend, mesages status aren't changed. + =item B<-s|--split> Split messages into separate file by borrower home library to OUTPUT_DIRECTORY/notices-CURRENT_DATE-BRANCHCODE.[csv|html|ods] -- 2.1.0