Lines 8-16
BEGIN {
Link Here
|
8 |
use FindBin; |
8 |
use FindBin; |
9 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
9 |
eval { require "$FindBin::Bin/../kohalib.pl" }; |
10 |
} |
10 |
} |
|
|
11 |
BEGIN { |
12 |
use C4::Context; |
13 |
C4::Context->interface('commandline'); #The interface must be set prior to initializing any loggers. |
14 |
} |
11 |
|
15 |
|
12 |
use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy |
16 |
use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy |
13 |
use C4::Context; |
|
|
14 |
use C4::Debug; |
17 |
use C4::Debug; |
15 |
use C4::Letters; |
18 |
use C4::Letters; |
16 |
use C4::Templates; |
19 |
use C4::Templates; |
Lines 22-28
use C4::Log;
Link Here
|
22 |
use File::Basename qw( dirname ); |
25 |
use File::Basename qw( dirname ); |
23 |
use Koha::DateUtils; |
26 |
use Koha::DateUtils; |
24 |
use MIME::Lite; |
27 |
use MIME::Lite; |
|
|
28 |
use Data::Printer; |
25 |
|
29 |
|
|
|
30 |
my $verbose = 0; |
26 |
my ( |
31 |
my ( |
27 |
$stylesheet, |
32 |
$stylesheet, |
28 |
$help, |
33 |
$help, |
Lines 39-44
my (
Link Here
|
39 |
$send = 1; |
44 |
$send = 1; |
40 |
GetOptions( |
45 |
GetOptions( |
41 |
'h|help' => \$help, |
46 |
'h|help' => \$help, |
|
|
47 |
'v|verbose+' => \$verbose, |
42 |
's|split' => \$split, |
48 |
's|split' => \$split, |
43 |
'html' => \$html, |
49 |
'html' => \$html, |
44 |
'csv' => \$csv, |
50 |
'csv' => \$csv, |
Lines 51-56
GetOptions(
Link Here
|
51 |
|
57 |
|
52 |
pod2usage(0) if $help; |
58 |
pod2usage(0) if $help; |
53 |
|
59 |
|
|
|
60 |
use Koha::Logger; |
61 |
Koha::Logger->setConsoleVerbosity($verbose); |
62 |
my $logger = bless({lazyLoad => {category => __PACKAGE__}}, 'Koha::Logger'); |
63 |
|
54 |
my $output_directory = $ARGV[0]; |
64 |
my $output_directory = $ARGV[0]; |
55 |
|
65 |
|
56 |
if ( !$output_directory || !-d $output_directory || !-w $output_directory ) { |
66 |
if ( !$output_directory || !-d $output_directory || !-w $output_directory ) { |
Lines 83-90
cronlogaction();
Link Here
|
83 |
|
93 |
|
84 |
my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ) ; |
94 |
my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ) ; |
85 |
my $today_syspref = output_pref( { dt => dt_from_string, dateonly => 1 } ); |
95 |
my $today_syspref = output_pref( { dt => dt_from_string, dateonly => 1 } ); |
|
|
96 |
$logger->debug("Today is '$today_iso'"); |
86 |
|
97 |
|
87 |
my @all_messages = @{ GetPrintMessages() }; |
98 |
my @all_messages = @{ GetPrintMessages() }; |
|
|
99 |
$logger->debug("Found '".scalar(@all_messages)."' print messages"); |
88 |
|
100 |
|
89 |
# Filter by letter_code |
101 |
# Filter by letter_code |
90 |
@all_messages = map { |
102 |
@all_messages = map { |
Lines 93-98
my @all_messages = @{ GetPrintMessages() };
Link Here
|
93 |
grep { /^$letter_code$/ } @letter_codes |
105 |
grep { /^$letter_code$/ } @letter_codes |
94 |
) ? $_ : () |
106 |
) ? $_ : () |
95 |
} @all_messages if @letter_codes; |
107 |
} @all_messages if @letter_codes; |
|
|
108 |
$logger->info("'".scalar(@all_messages)."' print messages found with letter codes '".(scalar(@letter_codes) ? scalar(@letter_codes) : 'ANY')."'"); |
96 |
exit unless @all_messages; |
109 |
exit unless @all_messages; |
97 |
|
110 |
|
98 |
my ( $html_filenames, $csv_filenames, $ods_filenames ); |
111 |
my ( $html_filenames, $csv_filenames, $ods_filenames ); |
Lines 128-133
if ( $html ) {
Link Here
|
128 |
} |
141 |
} |
129 |
|
142 |
|
130 |
if ( @emails ) { |
143 |
if ( @emails ) { |
|
|
144 |
$logger->info("Emailing files as attachments from '".C4::Context->preference('KohaAdminEmailAddress')."' to '@emails'"); |
131 |
my $files = { |
145 |
my $files = { |
132 |
html => $html_filenames, |
146 |
html => $html_filenames, |
133 |
csv => $csv_filenames, |
147 |
csv => $csv_filenames, |
Lines 150-158
sub print_notices {
Link Here
|
150 |
my $split = $params->{split}; |
164 |
my $split = $params->{split}; |
151 |
my $output_directory = $params->{output_directory}; |
165 |
my $output_directory = $params->{output_directory}; |
152 |
my $format = $params->{format} // 'html'; |
166 |
my $format = $params->{format} // 'html'; |
|
|
167 |
$logger->debug("Printing notices to '$output_directory' as '$format'.".($split ? ' Splitting files by branch.' : '')) if $logger->is_debug(); |
153 |
|
168 |
|
154 |
die "Format $format is not known" |
169 |
die "Format $format is not known" |
155 |
unless $format =~ m[^html$|^csv$|^ods$]; |
170 |
unless $format =~ m!^html$|^csv$|^ods$!; # =~ m[..] messes up syntax highlighting in VSCode |
156 |
|
171 |
|
157 |
my ( @filenames, $messages_by_branch ); |
172 |
my ( @filenames, $messages_by_branch ); |
158 |
|
173 |
|
Lines 192-204
sub print_notices {
Link Here
|
192 |
C4::Letters::_set_message_status( |
207 |
C4::Letters::_set_message_status( |
193 |
{ |
208 |
{ |
194 |
message_id => $message->{'message_id'}, |
209 |
message_id => $message->{'message_id'}, |
195 |
status => 'sent' |
210 |
status => 'sent' #This is not true. The messages have not been delivered at this point. They are written to disk, but nobody can tell what happens afterwards. |
196 |
} |
211 |
} |
197 |
); |
212 |
); |
198 |
} |
213 |
} |
199 |
} |
214 |
} |
200 |
push @filenames, $filename; |
215 |
push @filenames, $filename; |
201 |
} |
216 |
} |
|
|
217 |
$logger->info("Generated print notice files '@filenames'"); |
202 |
return \@filenames; |
218 |
return \@filenames; |
203 |
} |
219 |
} |
204 |
|
220 |
|
Lines 306-312
sub send_files {
Link Here
|
306 |
my $files = $params->{files}; |
322 |
my $files = $params->{files}; |
307 |
my $to = $params->{to}; |
323 |
my $to = $params->{to}; |
308 |
my $from = $params->{from}; |
324 |
my $from = $params->{from}; |
309 |
return unless $to and $from; |
325 |
unless ($to and $from) { |
|
|
326 |
$logger->error("Trying to send email, but no 'To:' or 'From:' -addresses given?"); |
327 |
return ; |
328 |
} |
310 |
|
329 |
|
311 |
my $mail = MIME::Lite->new( |
330 |
my $mail = MIME::Lite->new( |
312 |
From => $from, |
331 |
From => $from, |
Lines 325-346
sub send_files {
Link Here
|
325 |
? 'application/vnd.oasis.opendocument.spreadsheet' |
344 |
? 'application/vnd.oasis.opendocument.spreadsheet' |
326 |
: undef; |
345 |
: undef; |
327 |
|
346 |
|
328 |
next unless $mimetype; |
347 |
unless ($mimetype) { |
|
|
348 |
$logger->error("Trying to attach file '$filename' as type '$type', but no mimetype mapping for that type exists?"); |
349 |
next; |
350 |
} |
329 |
|
351 |
|
330 |
my $filepath = File::Spec->catdir( $directory, $filename ); |
352 |
my $filepath = File::Spec->catdir( $directory, $filename ); |
331 |
|
353 |
|
332 |
next unless $filepath or -f $filepath; |
354 |
unless ($filepath or -f $filepath) { |
|
|
355 |
$logger->error("Trying to attach file '$filepath', but the file is missing?"); |
356 |
next; |
357 |
} |
333 |
|
358 |
|
334 |
$mail->attach( |
359 |
$mail->attach( |
335 |
Type => $mimetype, |
360 |
Type => $mimetype, |
336 |
Path => $filepath, |
361 |
Path => $filepath, |
337 |
Filename => $filename, |
362 |
Filename => $filename, |
338 |
Encoding => 'base64', |
363 |
Encoding => 'base64', |
339 |
); |
364 |
) or $logger->logdie("Attaching file '$filepath' as '$mimetype' failed!"); #Guessing this |
340 |
} |
365 |
} |
341 |
} |
366 |
} |
342 |
|
367 |
|
343 |
$mail->send; |
368 |
$mail->send() or $logger->logdie("you DON'T have mail!"); #Direct quote from https://metacpan.org/pod/MIME::Lite |
344 |
} |
369 |
} |
345 |
|
370 |
|
346 |
=head1 NAME |
371 |
=head1 NAME |
Lines 349-355
gather_print_notices - Print waiting print notices
Link Here
|
349 |
|
374 |
|
350 |
=head1 SYNOPSIS |
375 |
=head1 SYNOPSIS |
351 |
|
376 |
|
352 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help] |
377 |
gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help] [-v|--verbose, ...] |
353 |
|
378 |
|
354 |
Will print all waiting print notices to the output_directory. |
379 |
Will print all waiting print notices to the output_directory. |
355 |
|
380 |
|
Lines 409-414
E-mail address to send generated files to.
Link Here
|
409 |
|
434 |
|
410 |
Print a brief help message |
435 |
Print a brief help message |
411 |
|
436 |
|
|
|
437 |
=item B<-v|--verbose> |
438 |
|
439 |
Increase Log4perl verbosity one level for each -v -v -v |
440 |
|
412 |
=back |
441 |
=back |
413 |
|
442 |
|
414 |
=head1 AUTHOR |
443 |
=head1 AUTHOR |
415 |
- |
|
|