|
Lines 27-32
use C4::Context;
Link Here
|
| 27 |
use C4::Log qw( cronlogaction ); |
27 |
use C4::Log qw( cronlogaction ); |
| 28 |
use Koha::Email; |
28 |
use Koha::Email; |
| 29 |
use Koha::DateUtils qw( dt_from_string ); |
29 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
30 |
use Koha::File::Transports; |
| 30 |
use Koha::SMTP::Servers; |
31 |
use Koha::SMTP::Servers; |
| 31 |
|
32 |
|
| 32 |
use Getopt::Long qw( GetOptions ); |
33 |
use Getopt::Long qw( GetOptions ); |
|
Lines 47-77
runreport.pl - Run pre-existing saved reports
Link Here
|
| 47 |
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] |
48 |
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] |
| 48 |
|
49 |
|
| 49 |
Options: |
50 |
Options: |
| 50 |
-h --help brief help message |
51 |
-h --help brief help message |
| 51 |
-m --man full documentation, same as --help --verbose |
52 |
-m --man full documentation, same as --help --verbose |
| 52 |
-v --verbose verbose output |
53 |
-v --verbose verbose output |
| 53 |
|
54 |
|
| 54 |
--format=s selects format. Choice of text, html, csv or tsv |
55 |
--format=s selects format. Choice of text, html, csv or tsv |
| 55 |
|
56 |
|
| 56 |
-e --email whether to use e-mail (implied by --to or --from) |
57 |
-e --email whether to use e-mail (implied by --to or --from) |
| 57 |
--send_empty whether to send an email when there are no results from the |
58 |
--send_empty whether to send an email when there are no results from the |
| 58 |
specified report |
59 |
specified report |
| 59 |
-a --attachment additionally attach the report as a file. cannot be used with html format |
60 |
-a --attachment additionally attach the report as a file. cannot be used with html format |
| 60 |
--username username to pass to the SMTP server for authentication |
61 |
-n --filename (ftp/sftp only) optionally specify the name to use when uploading the file |
| 61 |
--password password to pass to the SMTP server for authentication |
62 |
--username username to pass to the SMTP server for authentication |
| 62 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
63 |
--password password to pass to the SMTP server for authentication |
| 63 |
--to=s e-mail address to send report to |
64 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
| 64 |
--from=s e-mail address to send report from |
65 |
--to=s e-mail address to send report to |
| 65 |
--subject=s subject for the e-mail |
66 |
--from=s e-mail address to send report from |
| 66 |
--param=s parameters for the report |
67 |
--subject=s subject for the e-mail |
| 67 |
--store-results store the result of the report |
68 |
--param=s parameters for the report |
| 68 |
--separator separator character for csv |
69 |
--store-results store the result of the report |
| 69 |
--quote quote character for csv |
70 |
--sftp-dest-id=i the ID of the target FTP/SFTP server, if you wish to upload the report |
| 70 |
--csv-header add column names as first line of csv output |
71 |
--separator separator character for csv |
|
|
72 |
--quote quote character for csv |
| 73 |
--csv-header add column names as first line of csv output |
| 71 |
|
74 |
|
| 72 |
|
75 |
|
| 73 |
Arguments: |
76 |
Arguments: |
| 74 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
77 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
| 75 |
|
78 |
|
| 76 |
=head1 OPTIONS |
79 |
=head1 OPTIONS |
| 77 |
|
80 |
|
|
Lines 187-192
my $man = 0;
Link Here
|
| 187 |
my $verbose = 0; |
190 |
my $verbose = 0; |
| 188 |
my $send_email = 0; |
191 |
my $send_email = 0; |
| 189 |
my $send_empty = 0; |
192 |
my $send_empty = 0; |
|
|
193 |
my $sftp_dest_id = 0; |
| 190 |
my $attachment = 0; |
194 |
my $attachment = 0; |
| 191 |
my $format = "text"; |
195 |
my $format = "text"; |
| 192 |
my $to = ""; |
196 |
my $to = ""; |
|
Lines 200-205
my $csv_header = 0;
Link Here
|
| 200 |
my $csv_separator = ""; |
204 |
my $csv_separator = ""; |
| 201 |
my $csv_quote = ""; |
205 |
my $csv_quote = ""; |
| 202 |
|
206 |
|
|
|
207 |
my $filename = undef; |
| 203 |
my $username = undef; |
208 |
my $username = undef; |
| 204 |
my $password = undef; |
209 |
my $password = undef; |
| 205 |
my $method = 'LOGIN'; |
210 |
my $method = 'LOGIN'; |
|
Lines 208-231
my $command_line_options = join( " ", @ARGV );
Link Here
|
| 208 |
cronlogaction( { info => $command_line_options } ); |
213 |
cronlogaction( { info => $command_line_options } ); |
| 209 |
|
214 |
|
| 210 |
GetOptions( |
215 |
GetOptions( |
| 211 |
'help|?' => \$help, |
216 |
'help|?' => \$help, |
| 212 |
'man' => \$man, |
217 |
'man' => \$man, |
| 213 |
'verbose' => \$verbose, |
218 |
'verbose' => \$verbose, |
| 214 |
'format=s' => \$format, |
219 |
'format=s' => \$format, |
| 215 |
'separator=s' => \$csv_separator, |
220 |
'separator=s' => \$csv_separator, |
| 216 |
'quote=s' => \$csv_quote, |
221 |
'quote=s' => \$csv_quote, |
| 217 |
'to=s' => \$to, |
222 |
'to=s' => \$to, |
| 218 |
'from=s' => \$from, |
223 |
'from=s' => \$from, |
| 219 |
'subject=s' => \$subject, |
224 |
'subject=s' => \$subject, |
| 220 |
'param=s' => \@params, |
225 |
'param=s' => \@params, |
| 221 |
'email' => \$send_email, |
226 |
'email' => \$send_email, |
| 222 |
'send_empty' => \$send_empty, |
227 |
'send_empty' => \$send_empty, |
| 223 |
'a|attachment' => \$attachment, |
228 |
'sftp-dest-id=i' => \$sftp_dest_id, |
| 224 |
'username:s' => \$username, |
229 |
'a|attachment' => \$attachment, |
| 225 |
'password:s' => \$password, |
230 |
'n|filename:s' => \$filename, |
| 226 |
'method:s' => \$method, |
231 |
'username:s' => \$username, |
| 227 |
'store-results' => \$store_results, |
232 |
'password:s' => \$password, |
| 228 |
'csv-header' => \$csv_header, |
233 |
'method:s' => \$method, |
|
|
234 |
'store-results' => \$store_results, |
| 235 |
'csv-header' => \$csv_header, |
| 229 |
|
236 |
|
| 230 |
) or pod2usage(2); |
237 |
) or pod2usage(2); |
| 231 |
pod2usage( -verbose => 2 ) if ($man); |
238 |
pod2usage( -verbose => 2 ) if ($man); |
|
Lines 392-398
foreach my $report_id (@ARGV) {
Link Here
|
| 392 |
} catch { |
399 |
} catch { |
| 393 |
carp "Mail not sent: $_"; |
400 |
carp "Mail not sent: $_"; |
| 394 |
}; |
401 |
}; |
| 395 |
} else { |
402 |
} |
|
|
403 |
|
| 404 |
if ($sftp_dest_id) { |
| 405 |
my $sftp_server = Koha::File::Transports->find($sftp_dest_id); |
| 406 |
|
| 407 |
die("ERROR:\tSupplied FTP/SFTP Server doesn\'t exist") |
| 408 |
unless ($sftp_server); |
| 409 |
|
| 410 |
die("ERROR:\tUnable to connect to FTP/SFTP Server") |
| 411 |
unless ( $sftp_server->connect ); |
| 412 |
|
| 413 |
my $upload_directory = $sftp_server->upload_directory; |
| 414 |
my $content_type = "text/$format"; |
| 415 |
my $filename = $filename || "report$report_id-$date.$format"; |
| 416 |
|
| 417 |
open my $fh, "<", \$message; |
| 418 |
|
| 419 |
die("ERROR\tMessage supplied is empty, or, not suitable for upload") |
| 420 |
unless ($fh); |
| 421 |
|
| 422 |
die("ERROR\tNo upload directory specified in config") |
| 423 |
unless ($upload_directory); |
| 424 |
|
| 425 |
die("ERROR\tUnable to change directory") |
| 426 |
unless ( $sftp_server->change_directory($upload_directory) ); |
| 427 |
|
| 428 |
die("ERROR\tUnable to upload report to server") |
| 429 |
unless ( $sftp_server->upload_file( $fh, $filename ) ); |
| 430 |
} |
| 431 |
|
| 432 |
if ( !$send_email && !$sftp_dest_id ) { |
| 396 |
print $message; |
433 |
print $message; |
| 397 |
} |
434 |
} |
| 398 |
} |
435 |
} |
| 399 |
- |
|
|