From 531f3d625997acb9787ad6b9cd04648796a6bacb Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 28 Nov 2023 13:31:13 +0000 Subject: [PATCH] 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 --- debian/koha-common.cron.daily | 1 + misc/cronjobs/anonymize_last_borrowers.pl | 70 +++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 misc/cronjobs/anonymize_last_borrowers.pl diff --git a/debian/koha-common.cron.daily b/debian/koha-common.cron.daily index 0d960ef0c5d..b6e16d084f1 100644 --- a/debian/koha-common.cron.daily +++ b/debian/koha-common.cron.daily @@ -30,4 +30,5 @@ 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 koha-run-backups --days 2 --output /var/spool/koha diff --git a/misc/cronjobs/anonymize_last_borrowers.pl b/misc/cronjobs/anonymize_last_borrowers.pl new file mode 100755 index 00000000000..06eef8601df --- /dev/null +++ b/misc/cronjobs/anonymize_last_borrowers.pl @@ -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 . + +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 < \$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); -- 2.30.2