From 36988e9ea5f90328f732fd19d5bea70b842b5277 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 30 Oct 2020 15:17:25 -0300 Subject: [PATCH] Bug 23260: (follow-up) Add AnonymiseLastBorrower and AnonymiseLastBorrowerDays sysprefs --- .../data/mysql/atomicupdate/bug_23260.perl | 9 ++- installer/data/mysql/mandatory/sysprefs.sql | 2 + .../en/modules/admin/preferences/patrons.pref | 8 ++ misc/cronjobs/anonymise_last_borrowers.pl | 75 +++++++++++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100755 misc/cronjobs/anonymise_last_borrowers.pl diff --git a/installer/data/mysql/atomicupdate/bug_23260.perl b/installer/data/mysql/atomicupdate/bug_23260.perl index b758f58b33..2e66865b19 100644 --- a/installer/data/mysql/atomicupdate/bug_23260.perl +++ b/installer/data/mysql/atomicupdate/bug_23260.perl @@ -3,6 +3,11 @@ if( CheckVersion( $DBversion ) ) { # you can use $dbh here like: $dbh->do( "ALTER TABLE items_last_borrower MODIFY COLUMN `borrowernumber` int(11) default NULL" ); - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23260 - make borrowernumber from items_last_borrower nullable)\n"; + $dbh->do(q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('AnonymiseLastBorrower','0',NULL,'If enabled, anonymise item\'s last borrower','YesNo'), + ('AnonymiseLastBorrowerDays','0',NULL,'Item\'s last borrower older than this preference will be anonymised','Integer') + }); + + NewVersion( $DBversion, 23260, "Make borrowernumber from items_last_borrower nullable, and add AnonymiseLastBorrower and AnonymiseLastBorrowerDays preferences"); } diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 2b2794106e..b45feb41e7 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -54,6 +54,8 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AmazonCoverImages','0','','Display Cover Images in staff interface from Amazon Web Services','YesNo'), ('AmazonLocale','US','US|CA|DE|FR|IN|JP|UK','Use to set the Locale of your Amazon.com Web Services','Choice'), ('AnonSuggestions','0',NULL,'Set to enable Anonymous suggestions to AnonymousPatron borrowernumber','YesNo'), +('AnonymiseLastBorrower','0',NULL,'If enabled, anonymise item\'s last borrower','YesNo'), +('AnonymiseLastBorrowerDays','0',NULL,'Item\'s last borrower older than this preference will be anonymised','Integer'), ('AnonymousPatron','0',NULL,'Set the identifier (borrowernumber) of the anonymous patron. Used for suggestion and checkout history privacy',''), ('ApplyFrameworkDefaults', 'new', 'new|duplicate|changed|imported', 'Configure when to apply framework default values - when cataloguing a new record, or when editing a record as new (duplicating), or when changing framework, or when importing a record', 'multiple'), ('ArticleRequests', '0', NULL, 'Enables the article request feature', 'YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 0a39164237..19f17c2e79 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -408,6 +408,14 @@ Patrons: type: modaljs initiator: populateCookieConsentedJS processor: prepareCookieConsentedJS + - + - pref: AnonymiseLastBorrower + choices: + yes: Anonymise + no: "Don't anonymise" + - " item's last borrower after " + - pref: AnonymiseLastBorrowerDays + - days. Security: - - Login passwords for staff and patrons must be at least diff --git a/misc/cronjobs/anonymise_last_borrowers.pl b/misc/cronjobs/anonymise_last_borrowers.pl new file mode 100755 index 0000000000..a2dd57da43 --- /dev/null +++ b/misc/cronjobs/anonymise_last_borrowers.pl @@ -0,0 +1,75 @@ + +#!/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 strict; +use warnings; +use Carp; + +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("AnonymiseLastBorrower"); + + +if( !$pref ) { + print "Preference 'AnonymiseLastBorrower' must be enabled to anonymise item's last borrower\n\n"; + usage(1); +} + +cronlogaction(); + +my $rows = Koha::Patrons->anonymise_last_borrowers(); +$verbose and print int($rows) . " item's last borrowers anonymised.\n"; + +exit(0); -- 2.30.2