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

(-)a/misc/cronjobs/erm_run_harvester.pl (-33 / +88 lines)
Lines 18-52 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
use Getopt::Long qw( GetOptions );
22
use Getopt::Long qw( GetOptions );
22
use Koha::DateUtils qw( dt_from_string );
23
use Pod::Usage   qw( pod2usage );
23
use POSIX;
24
use POSIX;
24
25
25
use C4::Log qw( cronlogaction );
26
use C4::Log         qw( cronlogaction );
26
use Koha::Script;
27
use Koha::DateUtils qw( dt_from_string );
27
use Koha::ERM::EUsage::UsageDataProviders;
28
use Koha::ERM::EUsage::UsageDataProviders;
29
use Koha::Script -cron;
30
31
=head1 NAME
32
33
erm_run_harvester.pl This script will run the SUSHI harvesting for usage data providers
34
35
=cut
36
37
=head1 SYNOPSIS
38
39
erm_run_harvester.pl
40
  --begin-date <YYYY-MM-DD>
41
  [ --dry-run ][ --debug ][ --end-date <YYYY-MM-DD> ]
42
43
 Options:
44
   --help                         brief help message
45
   --man                          detailed help message
46
   --debug                        print additional debug messages during run
47
   --dry-run                      test run only, do not harvest data
48
   --begin-date <YYYY-MM-DD>      date to harvest from
49
   --end-date <YYYY-MM-DD>        date to harvest until, defaults to today if not set
50
51
=head1 OPTIONS
52
53
=over 8
54
55
=item B<-help>
56
57
Print a brief help message and exits.
58
59
=item B<-man>
60
61
Print a detailed help message and exits.
62
63
=item B<--debug>
64
65
Add debug statements to run
66
67
=item B<--begin-date>
68
69
Date from which to harvest, previously harvested data will be ignored
70
71
=item B<--end-date>
72
73
Date to harvest until, defaults to today if not set
74
75
=item B<--dry-run>
28
76
29
my $command_line_options = join(" ",@ARGV);
77
Test run only, do not harvest
78
79
=back
80
81
=head1 DESCRIPTION
82
83
This script fetches usage data from ERM data providers defined in the interface.
84
85
=head2 Configuration
86
87
This script harvests from the given date to the specified end date, or until today
88
89
=head1 USAGE EXAMPLES
90
91
C<erm_run_harvester.pl> - With no arguments help is printed
92
93
94
C<erm_run_harvester.pl --begin-date 2000-01-01> - Harvest from the given date until today
95
96
C<erm_run_harvester.pl --begin-date 2000-01-01 --end-date 2024-01-01> - Harvest from the given date until the end date
97
98
C<erm_run_harvester.pl --begin-date 2000-01-01 --end-date 2024-01-01 --debug --dry-run> - Dry run, with debuig information
99
100
=cut
101
102
my $command_line_options = join( " ", @ARGV );
30
103
31
# Command line option values
104
# Command line option values
32
my $get_help   = 0;
105
my $help       = 0;
106
my $man        = 0;
33
my $begin_date = 0;
107
my $begin_date = 0;
34
my $end_date   = 0;
108
my $end_date   = 0;
35
my $dry_run    = 0;
109
my $dry_run    = 0;
36
my $debug      = 0;
110
my $debug      = 0;
37
111
38
my $options = GetOptions(
112
my $options = GetOptions(
39
    'h|help'       => \$get_help,
113
    'h|help'       => \$help,
114
    'm|man'        => \$man,
40
    'begin-date=s' => \$begin_date,
115
    'begin-date=s' => \$begin_date,
41
    'end-date=s'   => \$end_date,
116
    'end-date=s'   => \$end_date,
42
    'dry-run'      => \$dry_run,
117
    'dry-run'      => \$dry_run,
43
    'debug'        => \$debug
118
    'debug'        => \$debug
44
);
119
);
45
120
46
if ($get_help) {
121
pod2usage(1) if $help;
47
    get_help();
122
pod2usage( -verbose => 2 ) if $man;
48
    exit 1;
49
}
50
123
51
my $udproviders = Koha::ERM::EUsage::UsageDataProviders->search( { active => 1 } );
124
my $udproviders = Koha::ERM::EUsage::UsageDataProviders->search( { active => 1 } );
52
unless ( scalar @{ $udproviders->as_list() } ) {
125
unless ( scalar @{ $udproviders->as_list() } ) {
Lines 54-63 unless ( scalar @{ $udproviders->as_list() } ) { Link Here
54
}
127
}
55
128
56
unless ($begin_date) {
129
unless ($begin_date) {
57
    die "ERROR: Please specify a begin-date";
130
    print "ERROR: You must specify a begin-date\n\n";
131
    pod2usage(1);
58
}
132
}
59
133
60
cronlogaction({ info => $command_line_options });
134
cronlogaction( { info => $command_line_options } );
135
61
debug_msg("Dry run: Harvests will not be enqueued") if $dry_run;
136
debug_msg("Dry run: Harvests will not be enqueued") if $dry_run;
62
while ( my $udprovider = $udproviders->next ) {
137
while ( my $udprovider = $udproviders->next ) {
63
    debug_msg(
138
    debug_msg(
Lines 98-104 while ( my $udprovider = $udproviders->next ) { Link Here
98
173
99
}
174
}
100
175
101
cronlogaction({ action => 'End', info => "COMPLETED" });
176
cronlogaction( { action => 'End', info => "COMPLETED" } );
102
177
103
sub debug_msg {
178
sub debug_msg {
104
    my ($msg) = @_;
179
    my ($msg) = @_;
Lines 113-134 sub debug_msg { Link Here
113
    }
188
    }
114
    print STDERR "$msg\n";
189
    print STDERR "$msg\n";
115
}
190
}
116
117
sub get_help {
118
    print <<"HELP";
119
$0: Run a SUSHI harvesting for a ERM usage data provider
120
121
This script will run the SUSHI harvesting for usage data providers
122
123
Parameters:
124
    --help or -h                         get help
125
    --begin-date                         begin date for the harvest in yyyy-mm-dd format (e.g.: '2023-08-21')
126
    --end-date                           end date for the harvest in yyyy-mm-dd format (e.g.: '2023-08-21')
127
    --dry-run                            only produce a run report, without actually doing anything permanent
128
    --debug                              print additional debugging info during run
129
130
Usage example:
131
./misc/cronjobs/erm_run_harvester.pl --begin-date 2023-06-21 --debug
132
133
HELP
134
}
135
- 

Return to bug 38237