From 3d8fd974a9109265c86727be355864234babc9cc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 7 Nov 2023 13:45:01 +0000 Subject: [PATCH] Bug 35277: Pseudonymize in a background job This patch adds a new background job for pseduonymization To test: 1 - Download the benchmarking script 2 - Ensure your koha has bcrypt_settings in koha-conf.xml See bug 28911 3 - perl perf_check_pseudo.pl 4 - Note the slowdown after pseudonymization enabled 5 - Apply patches, restart all 6 - perl perf_check_pseudo.pl 7 - Note improvement 8 - Enable pseudonymization in sytem preferences 9 - Perform some checkouts and returns 10 - Verify the background jobs complete successfully 11 - Verify the pseudonymized_transactions table is updated correctly Signed-off-by: Martin Renvoize Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers --- Koha/BackgroundJob.pm | 1 + Koha/BackgroundJob/PseudonymizeStatistic.pm | 82 +++++++++++++++++++ Koha/Statistic.pm | 4 +- .../pseudonymize_statistic.inc | 25 ++++++ .../prog/en/modules/admin/background_jobs.tt | 4 + 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 Koha/BackgroundJob/PseudonymizeStatistic.pm create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/pseudonymize_statistic.inc diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 5eb4e640b1..579b0f9327 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -428,6 +428,7 @@ sub core_types_to_classes { stage_marc_for_import => 'Koha::BackgroundJob::StageMARCForImport', marc_import_commit_batch => 'Koha::BackgroundJob::MARCImportCommitBatch', marc_import_revert_batch => 'Koha::BackgroundJob::MARCImportRevertBatch', + pseudonymize_statistic => 'Koha::BackgroundJob::PseudonymizeStatistic', }; } diff --git a/Koha/BackgroundJob/PseudonymizeStatistic.pm b/Koha/BackgroundJob/PseudonymizeStatistic.pm new file mode 100644 index 0000000000..08c24b04c1 --- /dev/null +++ b/Koha/BackgroundJob/PseudonymizeStatistic.pm @@ -0,0 +1,82 @@ +package Koha::BackgroundJob::PseudonymizeStatistic; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::PseudonymizedTransactions; + +use base 'Koha::BackgroundJob'; + +=head1 NAME + +Koha::BackgroundJob::BatchCancelHold - Batch cancel holds + +This is a subclass of Koha::BackgroundJob. + +=head1 API + +=head2 Class methods + +=head3 job_type + +Define the job type of this job: batch_hold_cancel + +=cut + +sub job_type { + return 'pseudonymize_statistic'; +} + +=head3 process + +Process the modification. + +=cut + +sub process { + my ( $self, $args ) = @_; + $self->start; + my $statistic = $args->{statistic}; + my $stat_object = Koha::Statistic->new($statistic); + Koha::PseudonymizedTransaction->new_from_statistic($stat_object)->store(); + $self->finish( { data => "" } ); # We want to clear the job data to avoid storing patron information + +} + +=head3 enqueue + +Enqueue the new job + +=cut + +sub enqueue { + my ( $self, $args ) = @_; + + my $statistic = $args->{statistic}; + Koha::Exceptions::MissingParameter->throw("Missing statistic parameter is mandatory") + unless $statistic; + + $self->SUPER::enqueue( + { + job_size => 1, # Only handling one at time + job_args => { statistic => $statistic }, + job_queue => 'default', + } + ); +} + +1; diff --git a/Koha/Statistic.pm b/Koha/Statistic.pm index c3deb71b2a..19d56cbc32 100644 --- a/Koha/Statistic.pm +++ b/Koha/Statistic.pm @@ -23,7 +23,7 @@ use C4::Context; use Koha::Database; use Koha::DateUtils qw/dt_from_string/; use Koha::Items; -use Koha::PseudonymizedTransaction; +use Koha::BackgroundJob::PseudonymizeStatistic; use base qw(Koha::Object); @@ -121,7 +121,7 @@ sub new { sub store { my ($self) = @_; $self->SUPER::store; - Koha::PseudonymizedTransaction->new_from_statistic($self)->store + Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $self->unblessed } ) if C4::Context->preference('Pseudonymization') && $self->borrowernumber # Not a real transaction if the patron does not exist # For instance can be a transfer, or hold trigger diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/pseudonymize_statistic.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/pseudonymize_statistic.inc new file mode 100644 index 0000000000..dd6cc2ab05 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/background_jobs/pseudonymize_statistic.inc @@ -0,0 +1,25 @@ +[% USE KohaSpan %] +[% BLOCK report %] + [% IF job.status == 'finished' %] +
+ Statistic has been pseudonymized. +
+ [% ELSIF job.status == 'cancelled' %] +
+ Pseudonymization has been cancelled. +
+ [% ELSE %] +
+ Pseudonymization is pending. +
+ [% END %] +[% END %] + +[% BLOCK detail %] +
+ Pseudonymization. +
+[% END %] + +[% BLOCK js %] +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt index 5ed845b13e..11cec0dfcf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/background_jobs.tt @@ -209,6 +209,10 @@ '_id': 'batch_hold_cancel', '_str': _("Batch hold cancellation") }, + { + '_id': 'pseudonymize_statistic', + '_str': _("Pseudonymize statistic") + }, { '_id': 'create_eholdings_from_biblios', '_str': _("Create eHolding titles") -- 2.39.5