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, in format "integer-unit", e.g. 15-minutes. |
67 |
|
69 |
|
68 |
|
70 |
|
69 |
Arguments: |
71 |
Arguments: |
Lines 129-134
Store the result of the report into the saved_reports DB table.
Link Here
|
129 |
|
131 |
|
130 |
To access the results, go on Reports > Guided reports > Saved report. |
132 |
To access the results, go on Reports > Guided reports > Saved report. |
131 |
|
133 |
|
|
|
134 |
=item B<--recurring> |
135 |
|
136 |
Duration at which this script is repeated. |
137 |
|
138 |
Format for this parameter is "integer-unit" (without quotes) |
139 |
Example: 15-minutes. |
140 |
|
141 |
Regex: [1-9][0-9]*-(years|months|weeks|days|hours|minutes) |
142 |
|
143 |
Optional. |
144 |
|
132 |
=back |
145 |
=back |
133 |
|
146 |
|
134 |
=head1 DESCRIPTION |
147 |
=head1 DESCRIPTION |
Lines 181-186
my $separator = ',';
Link Here
|
181 |
my $quote = '"'; |
194 |
my $quote = '"'; |
182 |
my $store_results = 0; |
195 |
my $store_results = 0; |
183 |
my $csv_header = 0; |
196 |
my $csv_header = 0; |
|
|
197 |
my $recurring; |
184 |
|
198 |
|
185 |
my $username = undef; |
199 |
my $username = undef; |
186 |
my $password = undef; |
200 |
my $password = undef; |
Lines 202-207
GetOptions(
Link Here
|
202 |
'method:s' => \$method, |
216 |
'method:s' => \$method, |
203 |
'store-results' => \$store_results, |
217 |
'store-results' => \$store_results, |
204 |
'csv-header' => \$csv_header, |
218 |
'csv-header' => \$csv_header, |
|
|
219 |
'recurring:s' => \$recurring, |
205 |
|
220 |
|
206 |
) or pod2usage(2); |
221 |
) or pod2usage(2); |
207 |
pod2usage( -verbose => 2 ) if ($man); |
222 |
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'); |
241 |
$to or $to = C4::Context->preference('KohaAdminEmailAddress'); |
227 |
} |
242 |
} |
228 |
|
243 |
|
|
|
244 |
if ($recurring and $recurring !~ /^[1-9][0-9]*-(years|months|weeks|days|hours|minutes)$/) { |
245 |
print STDERR "ERROR: Invalid --recurring format, format is: \d+-(years|months|weeks|days|hours|minutes)\n"; |
246 |
pod2usage(1); |
247 |
} |
248 |
|
229 |
unless (scalar(@ARGV)) { |
249 |
unless (scalar(@ARGV)) { |
230 |
print STDERR "ERROR: No reportID(s) specified\n"; |
250 |
print STDERR "ERROR: No reportID(s) specified\n"; |
231 |
pod2usage(1); |
251 |
pod2usage(1); |
Lines 358-361
foreach my $report_id (@ARGV) {
Link Here
|
358 |
else { |
378 |
else { |
359 |
print $message; |
379 |
print $message; |
360 |
} |
380 |
} |
|
|
381 |
|
382 |
if ( $recurring ) { |
383 |
my ( $frequency, $frequency_unit ) = split( '-', $recurring ); |
384 |
my $base; |
385 |
if ( C4::Context->config('supportdir') ) { |
386 |
$base = C4::Context->config('supportdir'); |
387 |
} |
388 |
else { |
389 |
$base = "/usr/share/koha/bin"; |
390 |
} |
391 |
my $CONFIG_NAME = $ENV{'KOHA_CONF'}; |
392 |
my $command = |
393 |
"export KOHA_CONF=\"$CONFIG_NAME\"; " . |
394 |
"$base/cronjobs/runreport.pl " . $report->id . " --format=$format --to=$to --recurring=$recurring"; |
395 |
|
396 |
my $start = DateTime->now->add( $frequency_unit => $frequency )->truncate( to => 'minute' ); |
397 |
$start = $start->ymd('') . substr($start->hms(''), 0, 4); |
398 |
|
399 |
unless ( add_at_job( $start, $command ) ) { |
400 |
print STDERR "ERROR: Adding recurring job failed\n"; |
401 |
} |
402 |
|
403 |
print STDOUT "Recurring job added\n"; |
404 |
} |
361 |
} |
405 |
} |