Bug 23260: Add cronjob anonymize_last_borrowers.pl

This patch adds the feature to anonymize patrons from items_last_borrower table. This code is run from batch_anonymize script, which is triggered from a new cron job anonymize_last_borrowers.pl

To test:
 1) apply this patch and the previous ones
 2) perl installer/data/mysql/updatedatabase.pl
 3) set StoreLastBorrower preference to Allow.
 4) set AnonymousPatron preference to a valid patron id
 5) Create a Check out followed by a Check in.
    CHECK => a row should appear in items_last_borrower table with the borrower and the item number.
 6) In mysql, update created_on of items_last_borrower and returndate of old_issues to two days earlier.
 7) perl misc/cronjobs/anonymize_last_borrowers.pl
    CHECK => borrower number in items_last_borrower is not anonymized yet.
 8) Repeat step 5 and 6 but instead of two days earlier, set the new entry in items_last_borrower to three days earlier.
 9) set AnonymizeLastBorrower to 'Anonymize' and AnonymizeLastBorrowerDays to 2 days.
10) perl misc/cronjobs/anonymize_last_borrowers.pl
    SUCCESS => borrower number in items_last_borrower changed to AnonymousPatron id
11) repeat step 8
12) set AnonymousPatron preference to 0
13) perl misc/cronjobs/anonymize_last_borrowers.pl
SUCCESS => borrower number in items_last_borrower changed to null
14) prove t/db_dependent/Koha/Patrons.t

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Peter Moore <peter@mrcpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2023-11-28 13:31:13 +00:00 committed by Lucas Gass
parent 39ce85bf84
commit ecfd85ebb8
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 71 additions and 0 deletions

View File

@ -32,3 +32,4 @@ koha-foreach --chdir --enabled --noemail /usr/share/koha/bin/cronjobs/cleanup_da
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/holds/auto_unsuspend_holds.pl > /dev/null 2>&1
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/merge_authorities.pl -b
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/plugins_nightly.pl
koha-foreach --chdir --enabled /usr/share/koha/bin/cronjobs/anonymize_last_borrowers.pl

View File

@ -0,0 +1,70 @@
#!/usr/bin/perl
# Copyright 2011, ByWater Solutions.
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <https://www.gnu.org/licenses>.
use Modern::Perl;
BEGIN {
# find Koha's Perl modules
# test carefully before changing this
use FindBin;
eval { require "$FindBin::Bin/../kohalib.pl" };
}
use Koha::Script -cron;
use C4::Context;
use Koha::Patrons;
use Getopt::Long;
use C4::Log;
sub usage {
print STDERR <<USAGE;
Usage: $0 [-h|--help]
-v --verbose gives a little more information
-h --help prints this help message, and exits, ignoring all
other options
Note: If the system preference 'AnonymousPatron' is not defined, NULL will be used.
USAGE
exit $_[0];
}
my ( $help, $verbose );
GetOptions(
'h|help' => \$help,
'v|verbose' => \$verbose,
) || usage(1);
if ($help) {
usage(0);
}
my $pref = C4::Context->preference("AnonymizeLastBorrower");
if ( !$pref ) {
print "Preference 'AnonymizeLastBorrower' must be enabled to anonymize item's last borrower\n\n";
usage(1);
}
cronlogaction();
my $rows = Koha::Patrons->anonymize_last_borrowers();
$verbose and print int($rows) . " item's last borrowers anonymized.\n";
exit(0);