Marcel de Rooy
dea93375dc
The cron job is moved from migration tools to cronjobs. And renamed to a plural form. The script is now based on Koha objects. It does no longer include the code to merge one record. This can be done via the interface, and will be added to a maintenance script on bug 18071. Should not be part of this cron job. Adding a cron_cleanup method to MergeRequests; this method is called from the cron script to reset older entries still marked in progress and to also remove old processed entries. Tested in a separate unit test. Test plan: [1] Run t/db_dependent/Authorities/MergeRequests.t [2] Set AuthorityMergeLimit to 0. (All merges are postponed.) [3] Modify an authority linked to a few records. [4] Delete an authority linked to a few records with batch delete tool. [5] And select two auth records with linked records. Merge these two records with authority/merge.pl. Note: Do not select Default. See also bug 17380. [6] Check the need_merge_authorities table for inserted records. [7] Run misc/cronjobs/merge_authorities.pl -b and inspect the linked records and the record status in need_merge_authorities. Signed-off-by: Marc Véron <veron@veron.ch> Signed-off-by: Jacek Ablewicz <abl@biblos.pk.edu.pl> Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
89 lines
2 KiB
Perl
Executable file
89 lines
2 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
use Getopt::Long;
|
|
use Pod::Usage;
|
|
use Time::HiRes qw(gettimeofday);
|
|
|
|
use C4::AuthoritiesMarc;
|
|
use Koha::Authority::MergeRequests;
|
|
|
|
use constant RESET_HOURS => 24;
|
|
use constant REMOVE_DAYS => 30;
|
|
|
|
my ( $params );
|
|
GetOptions(
|
|
'h' => \$params->{help},
|
|
'v' => \$params->{verbose},
|
|
'b' => \$params->{batch},
|
|
);
|
|
|
|
$|=1; # flushes output
|
|
if( $params->{batch} ) {
|
|
handle_batch( $params );
|
|
} else {
|
|
pod2usage(1);
|
|
}
|
|
|
|
sub handle_batch {
|
|
my $params = shift;
|
|
my $verbose = $params->{verbose};
|
|
|
|
my $starttime = gettimeofday;
|
|
print "Started merging\n" if $verbose;
|
|
|
|
Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => RESET_HOURS, remove_days => REMOVE_DAYS });
|
|
my $rs = Koha::Authority::MergeRequests->search(
|
|
{ done => 0 },
|
|
{ order_by => { -asc => 'id' }}, # IMPORTANT
|
|
);
|
|
# For best results, postponed merges should be applied in right order.
|
|
# Similarly, we do not only select the last one for a specific id.
|
|
|
|
while( my $req = $rs->next ) {
|
|
$req->done(2)->store;
|
|
print "Merging auth " . $req->authid . " to " . ( $req->authid_new // 'NULL' ) . ".\n" if $verbose;
|
|
my $newmarc = $req->authid_new
|
|
? GetAuthority( $req->authid_new )
|
|
: undef;
|
|
# Following merge call handles both modifications and deletes
|
|
merge({
|
|
mergefrom => $req->authid,
|
|
MARCfrom => scalar $req->oldmarc,
|
|
mergeto => $req->authid_new,
|
|
MARCto => $newmarc,
|
|
override_limit => 1,
|
|
});
|
|
$req->done(1)->store;
|
|
}
|
|
my $timeneeded = gettimeofday - $starttime;
|
|
print "Done in $timeneeded seconds\n" if $verbose;
|
|
}
|
|
|
|
=head1 NAME
|
|
|
|
merge_authorities.pl
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Cron script to handle authority merge requests
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
merge_authorities.pl -h
|
|
|
|
merge_authorities.pl -b -v
|
|
|
|
=head1 OPTIONS
|
|
|
|
-b : batch mode (You need to pass this parameter from crontab file)
|
|
|
|
-h : print usage statement
|
|
|
|
-v : verbose mode
|
|
|
|
=head1 AUTHOR
|
|
|
|
Koha Development Team
|
|
|
|
=cut
|