From 48d5a93018cf50727e11c5ef0415aac2693ff7a8 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 16 Apr 2025 11:45:27 +0000 Subject: [PATCH] Bug 39652: store PseudonymizedTransaction before adding related entries Test plan: Run the tests before and after applying this patch: perl t/db_dependent/Koha/Pseudonymization.t They should fail before this patch and pass after applying patch. --- Koha/BackgroundJob/PseudonymizeStatistic.pm | 2 +- Koha/PseudonymizedTransaction.pm | 2 ++ t/db_dependent/Koha/Pseudonymization.t | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Koha/BackgroundJob/PseudonymizeStatistic.pm b/Koha/BackgroundJob/PseudonymizeStatistic.pm index a1dd525b941..822ee6c8564 100644 --- a/Koha/BackgroundJob/PseudonymizeStatistic.pm +++ b/Koha/BackgroundJob/PseudonymizeStatistic.pm @@ -52,7 +52,7 @@ sub process { $self->start; my $statistic = $args->{statistic}; my $stat_object = Koha::Statistic->new($statistic); - Koha::PseudonymizedTransaction->new_from_statistic($stat_object)->store(); + Koha::PseudonymizedTransaction->new_from_statistic($stat_object); $self->finish( { data => "" } ); # We want to clear the job data to avoid storing patron information } diff --git a/Koha/PseudonymizedTransaction.pm b/Koha/PseudonymizedTransaction.pm index ee243d76e67..f456c4d8403 100644 --- a/Koha/PseudonymizedTransaction.pm +++ b/Koha/PseudonymizedTransaction.pm @@ -96,6 +96,8 @@ sub new_from_statistic { my $self = $class->SUPER::new($values); + $self->store(); + if ($patron) { my $extended_attributes = $patron->extended_attributes->unblessed; for my $attribute (@$extended_attributes) { diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t index 36cfd57355f..3f73c778f4f 100755 --- a/t/db_dependent/Koha/Pseudonymization.t +++ b/t/db_dependent/Koha/Pseudonymization.t @@ -135,7 +135,7 @@ subtest 'Koha::Anonymized::Transactions tests' => sub { is( $pseudonymized->itemcallnumber, $item->itemcallnumber, 'itemcallnumber copied correctly' ); is( $pseudonymized->ccode, $item->ccode, 'ccode copied correctly' ); - my $next_p = Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store; + my $next_p = Koha::PseudonymizedTransaction->new_from_statistic($statistic); isnt( $pseudonymized->id, @@ -223,7 +223,7 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { } ); - my $p = Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store; + my $p = Koha::PseudonymizedTransaction->new_from_statistic($statistic); my $attributes = Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') ->search( { transaction_id => $p->id }, { order_by => 'attribute' } ); @@ -258,7 +258,7 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { } ); - my $next_p = Koha::PseudonymizedTransaction->new_from_statistic($second_statistic)->store; + my $next_p = Koha::PseudonymizedTransaction->new_from_statistic($second_statistic); my $next_attributes = Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') ->search( { transaction_id => $next_p->id }, { order_by => 'attribute' } ); -- 2.39.5