From 4de2a58f54983ab3f3b7f99aaa36df18580018c1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 3 Feb 2020 17:04:19 +0000 Subject: [PATCH] Bug 23260: Proposed preference driven filtering --- Koha/Patrons.pm | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 141209f87c..799df58fbb 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -180,6 +180,13 @@ sub anonymise_issue_history { $older_than_date = dt_from_string $older_than_date if $older_than_date; + my $filter_damaged = + C4::Context->preference("KeepDamagedCheckouts") || 0; + my $filter_lost = + C4::Context->preference("KeepLostCheckouts") || 0; + my $filter_withdrawn = + C4::Context->preference("KeepWithdrawnCheckouts") || 0; + # The default of 0 does not work due to foreign key constraints # The anonymisation should not fail quietly if AnonymousPatron is not a valid entry # Set it to undef (NULL) @@ -187,14 +194,20 @@ sub anonymise_issue_history { my $nb_rows = 0; while ( my $patron = $self->next ) { my $old_issues_to_anonymise = $patron->old_checkouts->search( - { - ( - $older_than_date - ? ( returndate => - { '<' => $dtf->format_datetime($older_than_date) } ) - : () - ) - } + { + ( + $older_than_date + ? ( returndate => + { '<' => $dtf->format_datetime($older_than_date) } ) + : () + ), + ( $filter_damaged ? ( "itemnumber.damaged" => 0 ) : () ), + ( $filter_lost ? ( "itemnumber.itemlost" => 0 ) : () ), + ( $filter_withdrawn ? ( "itemnumber.withdrawn" => 0 ) : () ) + }, + { + join => ['itemnumber'] + } ); my $last_borrowers_to_anonymise = @@ -205,10 +218,10 @@ sub anonymise_issue_history { ? ( created_on => { '<' => $dtf->format_datetime($older_than_date) } ) : (), - "itemnumber.damaged" => 0, - "itemnumber.itemlost" => 0, - "itemnumber.withdrawn" => 0, - ) + ), + ( $filter_damaged ? ( "itemnumber.damaged" => 0 ) : () ), + ( $filter_lost ? ( "itemnumber.itemlost" => 0 ) : () ), + ( $filter_withdrawn ? ( "itemnumber.withdrawn" => 0 ) : () ) }, { join => ['itemnumber'] -- 2.20.1