From a1a7193110d5f5121cf084d2cc787256e3753796 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 25 Oct 2023 19:08:00 +0000 Subject: [PATCH] Bug 34611: Confirm run if pseudonymized transactions found and add verbose feedback Signed-off-by: AFHDubCoLib Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer --- misc/maintenance/pseudonymize_statistics.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/misc/maintenance/pseudonymize_statistics.pl b/misc/maintenance/pseudonymize_statistics.pl index 1c20fe6f33..2f950b5c6d 100755 --- a/misc/maintenance/pseudonymize_statistics.pl +++ b/misc/maintenance/pseudonymize_statistics.pl @@ -22,6 +22,7 @@ use Pod::Usage qw( pod2usage ); use Koha::DateUtils qw( dt_from_string format_sqldatetime ); use Koha::Script; use Koha::Statistics; +use Koha::PseudonymizedTransactions; use C4::Context; @@ -41,13 +42,31 @@ 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 } } ); +print $statistics->count() . " statistics found\n" if $verbose; + + +my $existing_pseudo_stats = Koha::PseudonymizedTransactions->search( { datetime => { '<=' => $before } } )->count; + +if ( $statistics->count && $existing_pseudo_stats ) { + print "There are " + . $statistics->count() + . " statistics found, and $existing_pseudo_stats already in the database for the date provided.\n"; + print "You may have already run this script for the time period given.\n"; + print "Please enter 'Y' if you would like to continue:"; + chomp( my $continue = <> ); + exit unless uc($continue) eq 'Y'; +} + while ( my $statistic = $statistics->next ) { $statistic->pseudonymize(); } +print $statistics->count() . " statistics pseudonymized\n" if $verbose; + =head1 NAME pseudonymize_statistics - This script pseudonymizes statistics before a given date, or now if no date passed. -- 2.39.5