Bug 23148: Fix bridge image paths in de-DE installer files
[koha.git] / misc / cronjobs / merge_authorities.pl
blob727d7d5f8c8123d1738f4f32f70deef030dca3a8
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Getopt::Long;
5 use Pod::Usage;
6 use Time::HiRes qw(gettimeofday);
8 use Koha::Script -cron;
9 use C4::AuthoritiesMarc;
10 use Koha::Authority::MergeRequests;
12 use constant RESET_HOURS => 24;
13 use constant REMOVE_DAYS => 30;
15 my ( $params );
16 GetOptions(
17 'h' => \$params->{help},
18 'v' => \$params->{verbose},
19 'b' => \$params->{batch},
22 $|=1; # flushes output
23 if ( $params->{batch} ) {
24 handle_batch($params);
25 } else {
26 pod2usage(1);
29 sub handle_batch {
30 my $params = shift;
31 my $verbose = $params->{verbose};
33 my $starttime = gettimeofday;
34 print "Started merging\n" if $verbose;
36 Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => RESET_HOURS, remove_days => REMOVE_DAYS });
37 my $rs = Koha::Authority::MergeRequests->search(
38 { done => 0 },
39 { order_by => { -asc => 'id' }}, # IMPORTANT
41 # For best results, postponed merges should be applied in right order.
42 # Similarly, we do not only select the last one for a specific id.
44 while( my $req = $rs->next ) {
45 $req->done(2)->store;
46 print "Merging auth " . $req->authid . " to " . ( $req->authid_new // 'NULL' ) . ".\n" if $verbose;
47 my $newmarc = $req->authid_new
48 ? GetAuthority( $req->authid_new )
49 : undef;
50 # Following merge call handles both modifications and deletes
51 merge({
52 mergefrom => $req->authid,
53 MARCfrom => scalar $req->oldmarc,
54 mergeto => $req->authid_new,
55 MARCto => $newmarc,
56 override_limit => 1,
57 });
58 $req->done(1)->store;
60 my $timeneeded = gettimeofday - $starttime;
61 print "Done in $timeneeded seconds\n" if $verbose;
64 =head1 NAME
66 merge_authorities.pl
68 =head1 DESCRIPTION
70 Cron script to handle authority merge requests
72 =head1 SYNOPSIS
74 merge_authorities.pl -h
76 merge_authorities.pl -b -v
78 =head1 OPTIONS
80 -b : batch mode (You need to pass this parameter from crontab file)
82 -h : print usage statement
84 -v : verbose mode
86 =head1 AUTHOR
88 Koha Development Team
90 =cut