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 (+44 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, 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
}
(-)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