3 # This file is part of Koha.
5 # Copyright (C) 2022 PTFS Europe
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Getopt::Long qw( GetOptions );
22 use Koha::DateUtils qw( dt_from_string );
26 use Koha::ERM::EUsage::UsageDataProviders;
28 # Command line option values
35 my $options = GetOptions(
36 'h|help' => \$get_help,
37 'begin-date=s' => \$begin_date,
38 'end-date=s' => \$end_date,
39 'dry-run' => \$dry_run,
48 my $udproviders = Koha::ERM::EUsage::UsageDataProviders->search( { active => 1 } );
49 unless ( scalar @{ $udproviders->as_list() } ) {
50 die "ERROR: No usage data providers found.";
53 unless ($begin_date) {
54 die "ERROR: Please specify a begin-date";
57 debug_msg("Dry run: Harvests will not be enqueued") if $dry_run;
58 while ( my $udprovider = $udproviders->next ) {
61 "Processing usage data provider #%d - %s", $udprovider->erm_usage_data_provider_id, $udprovider->name
65 my $harvest_begin_date = dt_from_string($begin_date);
66 my $harvest_end_date = dt_from_string($end_date) || dt_from_string();
68 if ( $harvest_begin_date > $harvest_end_date ) {
70 "ERROR: begin-date must be earlier than end-date. Begin is %s and end date is %s",
71 $harvest_begin_date->ymd,
72 $harvest_end_date->ymd,
77 my $job_ids = $udprovider->enqueue_sushi_harvest_jobs(
79 begin_date => $harvest_begin_date->ymd,
80 end_date => $harvest_end_date->ymd
83 my $report_type_jobs = join ", ", map { $_->{report_type} . ': Job ID #' . $_->{job_id} } @{$job_ids};
87 " - Harvest job enqueued (yyyy-mm-dd):\n - Begin date: %s \n - End date: %s \n - %s",
88 $harvest_begin_date->ymd,
89 $harvest_end_date->ymd,
104 if ( ref $msg eq 'HASH' ) {
108 print STDERR "$msg\n";
113 $0: Run a SUSHI harvesting for a ERM usage data provider
115 This script will run the SUSHI harvesting for usage data providers
118 --help or -h get help
119 --begin-date begin date for the harvest in yyyy-mm-dd format (e.g.: '2023-08-21')
120 --end-date end date for the harvest in yyyy-mm-dd format (e.g.: '2023-08-21')
121 --dry-run only produce a run report, without actually doing anything permanent
122 --debug print additional debugging info during run
125 ./misc/cronjobs/erm_run_harvester.pl --begin-date 2023-06-21 --debug