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;
17 'h' => \
$params->{help
},
18 'v' => \
$params->{verbose
},
19 'b' => \
$params->{batch
},
22 $|=1; # flushes output
23 if ( $params->{batch
} ) {
24 handle_batch
($params);
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(
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 ) {
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 )
50 # Following merge call handles both modifications and deletes
52 mergefrom
=> $req->authid,
53 MARCfrom
=> scalar $req->oldmarc,
54 mergeto
=> $req->authid_new,
60 my $timeneeded = gettimeofday
- $starttime;
61 print "Done in $timeneeded seconds\n" if $verbose;
70 Cron script to handle authority merge requests
74 merge_authorities.pl -h
76 merge_authorities.pl -b -v
80 -b : batch mode (You need to pass this parameter from crontab file)
82 -h : print usage statement