|
Lines 22-27
use Modern::Perl;
Link Here
|
| 22 |
|
22 |
|
| 23 |
use Koha::Script -cron; |
23 |
use Koha::Script -cron; |
| 24 |
use C4::Reports::Guided qw( store_results execute_query ); |
24 |
use C4::Reports::Guided qw( store_results execute_query ); |
|
|
25 |
use C4::Scheduler qw( add_at_job ); |
| 25 |
use Koha::Reports; |
26 |
use Koha::Reports; |
| 26 |
use C4::Context; |
27 |
use C4::Context; |
| 27 |
use C4::Log qw( cronlogaction ); |
28 |
use C4::Log qw( cronlogaction ); |
|
Lines 64-69
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
Link Here
|
| 64 |
--param=s parameters for the report |
65 |
--param=s parameters for the report |
| 65 |
--store-results store the result of the report |
66 |
--store-results store the result of the report |
| 66 |
--csv-header add column names as first line of csv output |
67 |
--csv-header add column names as first line of csv output |
|
|
68 |
--recurring optional, duration at which this script is repeated with "at"-command, |
| 69 |
in format "integer-unit", e.g. 15-minutes. |
| 67 |
|
70 |
|
| 68 |
|
71 |
|
| 69 |
Arguments: |
72 |
Arguments: |
|
Lines 129-134
Store the result of the report into the saved_reports DB table.
Link Here
|
| 129 |
|
132 |
|
| 130 |
To access the results, go on Reports > Guided reports > Saved report. |
133 |
To access the results, go on Reports > Guided reports > Saved report. |
| 131 |
|
134 |
|
|
|
135 |
=item B<--recurring> |
| 136 |
|
| 137 |
Duration at which this script is repeated. |
| 138 |
|
| 139 |
Used together with Koha's task scheduler tool. |
| 140 |
|
| 141 |
Format for this parameter is "integer-unit" (without quotes) |
| 142 |
Example: 15-minutes. |
| 143 |
|
| 144 |
Regex: [1-9][0-9]*-(years|months|weeks|days|hours|minutes) |
| 145 |
|
| 146 |
Optional. |
| 147 |
|
| 148 |
Warning: Do not use this option with crontab entries of this script. |
| 149 |
It would spawn a new never-ending cycle of this task every time this |
| 150 |
script was executed through crontab. |
| 151 |
|
| 132 |
=back |
152 |
=back |
| 133 |
|
153 |
|
| 134 |
=head1 DESCRIPTION |
154 |
=head1 DESCRIPTION |
|
Lines 181-186
my $separator = ',';
Link Here
|
| 181 |
my $quote = '"'; |
201 |
my $quote = '"'; |
| 182 |
my $store_results = 0; |
202 |
my $store_results = 0; |
| 183 |
my $csv_header = 0; |
203 |
my $csv_header = 0; |
|
|
204 |
my $recurring; |
| 184 |
|
205 |
|
| 185 |
my $username = undef; |
206 |
my $username = undef; |
| 186 |
my $password = undef; |
207 |
my $password = undef; |
|
Lines 202-207
GetOptions(
Link Here
|
| 202 |
'method:s' => \$method, |
223 |
'method:s' => \$method, |
| 203 |
'store-results' => \$store_results, |
224 |
'store-results' => \$store_results, |
| 204 |
'csv-header' => \$csv_header, |
225 |
'csv-header' => \$csv_header, |
|
|
226 |
'recurring:s' => \$recurring, |
| 205 |
|
227 |
|
| 206 |
) or pod2usage(2); |
228 |
) or pod2usage(2); |
| 207 |
pod2usage( -verbose => 2 ) if ($man); |
229 |
pod2usage( -verbose => 2 ) if ($man); |
|
Lines 226-231
if ($to or $from or $send_email) {
Link Here
|
| 226 |
$to or $to = C4::Context->preference('KohaAdminEmailAddress'); |
248 |
$to or $to = C4::Context->preference('KohaAdminEmailAddress'); |
| 227 |
} |
249 |
} |
| 228 |
|
250 |
|
|
|
251 |
if ($recurring and $recurring !~ /^[1-9][0-9]*-(years|months|weeks|days|hours|minutes)$/) { |
| 252 |
print STDERR "ERROR: Invalid --recurring format, format is: [1-9][0-9]*-(years|months|weeks|days|hours|minutes)\n"; |
| 253 |
pod2usage(1); |
| 254 |
} |
| 255 |
|
| 229 |
unless (scalar(@ARGV)) { |
256 |
unless (scalar(@ARGV)) { |
| 230 |
print STDERR "ERROR: No reportID(s) specified\n"; |
257 |
print STDERR "ERROR: No reportID(s) specified\n"; |
| 231 |
pod2usage(1); |
258 |
pod2usage(1); |
|
Lines 359-361
foreach my $report_id (@ARGV) {
Link Here
|
| 359 |
print $message; |
386 |
print $message; |
| 360 |
} |
387 |
} |
| 361 |
} |
388 |
} |
|
|
389 |
|
| 390 |
if ( $recurring ) { |
| 391 |
my ( $frequency, $frequency_unit ) = split( '-', $recurring ); |
| 392 |
my $base; |
| 393 |
if ( C4::Context->config('supportdir') ) { |
| 394 |
$base = C4::Context->config('supportdir'); |
| 395 |
} |
| 396 |
else { |
| 397 |
$base = "/usr/share/koha/bin"; |
| 398 |
} |
| 399 |
my $CONFIG_NAME = $ENV{'KOHA_CONF'}; |
| 400 |
my $command = |
| 401 |
"export KOHA_CONF=\"$CONFIG_NAME\"; " . |
| 402 |
"$base/cronjobs/runreport.pl " . join(' ', @ARGV) . " --format=$format --to=$to --recurring=$recurring"; |
| 403 |
|
| 404 |
my $start = dt_from_string->add( $frequency_unit => $frequency )->truncate( to => 'minute' ); |
| 405 |
$start = $start->ymd('') . substr($start->hms(''), 0, 4); |
| 406 |
|
| 407 |
unless ( add_at_job( $start, $command ) ) { |
| 408 |
print STDERR "ERROR: Adding recurring job failed\n"; |
| 409 |
} |
| 410 |
else { |
| 411 |
print STDOUT "Recurring job added\n"; |
| 412 |
} |
| 413 |
} |