From 63e5e10bde71f08fda2025d74d143565eb73a4dc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 11 Mar 2025 11:08:26 +0000 Subject: [PATCH] Bug 39301: pseudonymize_statistics.pl script generates too many background jobs This patch changes the script to use 'Koha::PseudonymizedTransaction->new_from_statistic' directly rather than calling 'Koha::Statistic->pseudonymize()' which generates a background job. Additionally, some of the checks from 'pseudonymnize' and the background job are moved into the search so we don't fetch any to pseudonymize that should not be. To test: 1 - Generate some entries in statistics (checkin, checkout, renew, etc) 2 - Enable pseudonymization (see bug 28911 if you need bcrypt settings) 3 - perl misc/maintenance/pseudonymize_statistics.pl -v -c 4 - Statistics pseudonymized 5 - Check the background jobs table, note jobs were generated 6 - Apply patch 7 - perl misc/maintenance/pseudonymize_statistics.pl -v -c 8 - You get same count as before, and are warned of existing pseudonymized transactions 9 - enter 'Y' to continue 10 - Check the pseudonymized_transacations table 11 - Confirm same rows were generated twice 12 - Check the background jobs 13 - Confirm there were no new jobs generated (for pseudonymization) Signed-off-by: David Nind Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer (cherry picked from commit 342c1d599391035efa7ab52b754ceb7f35e12d16) Signed-off-by: Fridolin Somers --- misc/maintenance/pseudonymize_statistics.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misc/maintenance/pseudonymize_statistics.pl b/misc/maintenance/pseudonymize_statistics.pl index 1e51a1b498..0da03ce9c3 100755 --- a/misc/maintenance/pseudonymize_statistics.pl +++ b/misc/maintenance/pseudonymize_statistics.pl @@ -45,7 +45,13 @@ unless ( C4::Context->preference('Pseudonymization') ) { $before //= format_sqldatetime( dt_from_string(), 'sql', undef, 1 ); print "Searching for statistics before $before\n" if $verbose; -my $statistics = Koha::Statistics->search( { datetime => { '<=' => $before } } ); +my $statistics = Koha::Statistics->search( + { + datetime => { '<=' => $before }, + type => { '-in' => \@Koha::Statistic::pseudonymization_types }, + borrowernumber => { '!=' => undef } + } +); print $statistics->count() . " statistics found\n" if $verbose; @@ -67,7 +73,7 @@ if ( !$confirm ) { } while ( my $statistic = $statistics->next ) { - $statistic->pseudonymize(); + Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store(); } print $statistics->count() . " statistics pseudonymized\n" if $verbose;