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>
44 lines
1.2 KiB
Perl
44 lines
1.2 KiB
Perl
#!/usr/bin/perl
|
|
|
|
use Modern::Perl;
|
|
use Test::More tests => 1;
|
|
|
|
use Koha::Authority::MergeRequest;
|
|
use Koha::Authority::MergeRequests;
|
|
use Koha::Database;
|
|
use Koha::DateUtils qw/dt_from_string/;
|
|
|
|
my $schema = Koha::Database->new->schema;
|
|
$schema->storage->txn_begin;
|
|
|
|
subtest "Tests for cron_cleanup" => sub {
|
|
plan tests => 3;
|
|
|
|
my $dt = dt_from_string;
|
|
$dt->subtract( hours => 2 );
|
|
my $req1 = Koha::Authority::MergeRequest->new({
|
|
authid => 1,
|
|
done => 2,
|
|
timestamp => $dt,
|
|
})->store;
|
|
|
|
$dt->subtract( days => 30 );
|
|
my $req2 = Koha::Authority::MergeRequest->new({
|
|
authid => 2,
|
|
done => 1,
|
|
timestamp => $dt,
|
|
})->store;
|
|
|
|
# Now test two cleanup calls
|
|
# First call should only remove req2; second call should reset req1
|
|
Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => 3 });
|
|
$req1->discard_changes; # requery
|
|
is( $req1->done, 2, 'My request was not touched' );
|
|
$req2->discard_changes; # requery
|
|
is( $req2->in_storage, 0, 'Second request removed' );
|
|
Koha::Authority::MergeRequests->cron_cleanup({ reset_hours => 1 });
|
|
$req1->discard_changes; # requery
|
|
is( $req1->done, 0, 'Yes, we got a reset' );
|
|
};
|
|
|
|
$schema->storage->txn_rollback;
|