View | Details | Raw Unified | Return to bug 3935
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/scheduler.tt (+13 lines)
Lines 51-56 Link Here
51
        <input type="text" size="10" id="startdate" name="startdate" class="flatpickr" data-flatpickr-futuredate="true" value="" />
51
        <input type="text" size="10" id="startdate" name="startdate" class="flatpickr" data-flatpickr-futuredate="true" value="" />
52
        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
52
        <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
53
    </li>
53
    </li>
54
<li>
55
    <label for="frequency">Recurring every:</label>
56
    <input type="text" name="frequency" id="frequency" value="" maxlength="10" size="10" />
57
    <select name="frequency_unit" id="frequency_unit">
58
        <option value="minutes">minutes</option>
59
        <option value="hours">hours</option>
60
        <option value="days">days</option>
61
        <option value="weeks">weeks</option>
62
        <option value="months">months</option>
63
        <option value="years">years</option>
64
    </select>
65
    <div class="hint">(optional)</div>
66
</li>
54
<li><label for="report">Report:</label>
67
<li><label for="report">Report:</label>
55
<select name="report" id="report">
68
<select name="report" id="report">
56
[% FOREACH savedreport IN savedreports %]
69
[% FOREACH savedreport IN savedreports %]
(-)a/misc/cronjobs/runreport.pl (+52 lines)
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
}
(-)a/tools/scheduler.pl (-10 / +11 lines)
Lines 68-82 if ( $mode eq 'job_add' ) { Link Here
68
        "export KOHA_CONF=\"$CONFIG_NAME\"; " .
68
        "export KOHA_CONF=\"$CONFIG_NAME\"; " .
69
        "$base/cronjobs/runreport.pl $report --format=$format --to=$email";
69
        "$base/cronjobs/runreport.pl $report --format=$format --to=$email";
70
70
71
#FIXME commit ea899bc55933cd74e4665d70b1c48cab82cd1257 added recurring parameter (it is not in template) and call to add_cron_job (undefined)
71
    my $recurring = $input->param('frequency');
72
#    my $recurring = $input->param('recurring');
72
    if ( $recurring ) {
73
#    if ($recurring) {
73
        my $frequency = $recurring;
74
#        my $frequency = $input->param('frequency');
74
        $frequency =~ s/^\s+|\s+$//g;
75
#        add_cron_job( $start, $command );
75
        my $frequency_unit = $input->param('frequency_unit');
76
#    }
76
77
#    else {
77
        my @allowed_units = qw( years months weeks days hours minutes );
78
#        #here was the the unless ( add_at_job
78
        if ( $frequency =~ /^[1-9][0-9]*$/ and grep( /^$frequency_unit$/, @allowed_units ) ) {
79
#    }
79
            $command = $command . ' --recurring=' . $frequency . '-' . $frequency_unit;
80
        }
81
    }
80
82
81
    unless ( add_at_job( $start, $command ) ) {
83
    unless ( add_at_job( $start, $command ) ) {
82
        $template->param( job_add_failed => 1 );
84
        $template->param( job_add_failed => 1 );
83
- 

Return to bug 3935