From a1a1812d78889c6451c5c9bd75f718b59b8fadfc Mon Sep 17 00:00:00 2001 From: Andrew Fuerste Henry Date: Wed, 24 Sep 2025 20:16:56 +0000 Subject: [PATCH] Bug 23260: (QA followup) Prevent use of cronjob when AnonymousPatron not set To test: 1 - configure StoreLastBorrower but not AnonymousPatron 2 - perl misc/cronjobs/anonymize_last_borrowers.pl -c 3 - the cron tells 'Preference 'AnonymousPatron' must be enabled to anonymize item's last borrower' 4 - put a value in AnonymousPatron 5 - repeat 2 6 - cron runs good --- Koha/Patrons.pm | 7 ++++--- misc/cronjobs/anonymize_last_borrowers.pl | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index a3bf56530d9..3ebd17d5a43 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -204,19 +204,20 @@ sub anonymize_last_borrowers { my ( $self, $params ) = @_; return unless C4::Context->preference("AnonymizeLastBorrower"); + return unless C4::Context->preference("AnonymousPatron"); my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0; my ( $year, $month, $day ) = Today(); my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days ); my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday ); - my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; + my $anonymous_patron = C4::Context->preference('AnonymousPatron'); my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $rs = $self->_resultset->search( { created_on => { '<' => $dtf->format_datetime($older_than_date), }, - 'items_last_borrowers.borrowernumber' => { 'not' => undef }, # Keep forever - ( $anonymous_patron ? ( 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), + 'items_last_borrowers.borrowernumber' => { 'not' => undef }, # Keep forever + 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron }, }, { join => ["items_last_borrowers"], diff --git a/misc/cronjobs/anonymize_last_borrowers.pl b/misc/cronjobs/anonymize_last_borrowers.pl index 5e6b809c2fe..900639f309e 100755 --- a/misc/cronjobs/anonymize_last_borrowers.pl +++ b/misc/cronjobs/anonymize_last_borrowers.pl @@ -40,7 +40,6 @@ 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]; } @@ -57,13 +56,19 @@ if ($help) { usage(0); } -my $pref = C4::Context->preference("AnonymizeLastBorrower"); +my $pref1 = C4::Context->preference("AnonymizeLastBorrower"); +my $pref2 = C4::Context->preference("AnonymousPatron"); -if ( !$pref ) { +if ( !$pref1 ) { print "Preference 'AnonymizeLastBorrower' must be enabled to anonymize item's last borrower\n\n"; usage(1); } +if ( !$pref2 ) { + print "Preference 'AnonymousPatron' must be enabled to anonymize item's last borrower\n\n"; + usage(1); +} + unless ($confirm) { print STDERR "You must use the --confirm flag to run this script.\n"; print STDERR "Add --confirm to actually perform the anonymization.\n"; -- 2.39.5