Bug 23260: (QA follow-up) 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

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:
Andrew Fuerste Henry 2025-09-24 20:16:56 +00:00 committed by Lucas Gass
parent 7eda8d23fa
commit f0d4240ee2
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 12 additions and 6 deletions

View File

@ -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"],

View File

@ -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";