6 use Time::HiRes qw(gettimeofday);
8 use C4::AuthoritiesMarc;
9 use Koha::Authority::MergeRequests;
11 use constant RESET_HOURS => 24;
12 use constant REMOVE_DAYS => 30;
16 'h' => \$params->{help},
17 'v' => \$params->{verbose},
18 'b' => \$params->{batch},
21 $|=1; # flushes output
22 if( $params->{batch} ) {
23 handle_batch( $params );
30 my $verbose = $params->{verbose};
32 my $starttime = gettimeofday;
33 print "Started merging\n" if $verbose;
35 Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => RESET_HOURS, remove_days => REMOVE_DAYS });
36 my $rs = Koha::Authority::MergeRequests->search(
38 { order_by => { -asc => 'id' }}, # IMPORTANT
40 # For best results, postponed merges should be applied in right order.
41 # Similarly, we do not only select the last one for a specific id.
43 while( my $req = $rs->next ) {
45 print "Merging auth " . $req->authid . " to " . ( $req->authid_new // 'NULL' ) . ".\n" if $verbose;
46 my $newmarc = $req->authid_new
47 ? GetAuthority( $req->authid_new )
49 # Following merge call handles both modifications and deletes
51 mergefrom => $req->authid,
52 MARCfrom => scalar $req->oldmarc,
53 mergeto => $req->authid_new,
59 my $timeneeded = gettimeofday - $starttime;
60 print "Done in $timeneeded seconds\n" if $verbose;
69 Cron script to handle authority merge requests
73 merge_authorities.pl -h
75 merge_authorities.pl -b -v
79 -b : batch mode (You need to pass this parameter from crontab file)
81 -h : print usage statement