From ee7184ff83a248adfc8707404e1ede7b89b1a4af Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 3 Mar 2025 15:30:11 -0100 Subject: [PATCH] Bug 37901: Consider illrequest_id when creating When a new PseudonymizedTransaction is created, consider the presence of illrequest_id and act on it accordingly. --- Koha/ILL/Request.pm | 41 ++++++++++++++++++++++++++++++++ Koha/PseudonymizedTransaction.pm | 8 +++++++ 2 files changed, 49 insertions(+) diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm index 90035032e42..48bfd6ba2d8 100644 --- a/Koha/ILL/Request.pm +++ b/Koha/ILL/Request.pm @@ -2218,6 +2218,47 @@ sub can_patron_place_ill_in_opac { return 1; } +=head3 pseudonymize_illrequestattributes + + $illrequest->pseudonymize_illrequestattributes($transaction); + +This method creates a Koha::PseudonymizedTransaction object, adding pseudonymized ILL request attributes and backend info as metadata values. + +=cut + +sub pseudonymize_illrequestattributes { + my ( $self, $transaction ) = @_; + + my @attributes_to_pseudonymize = qw( + type + ); + + my $extended_attributes = $self->extended_attributes; + while ( my $attribute = $extended_attributes->next ) { + if ( grep { $_ eq $attribute->type } @attributes_to_pseudonymize ) { + $transaction->_result->create_related( + 'pseudonymized_metadata_values', + { + key => $attribute->type, + value => $attribute->value, + tablename => 'illrequestattributes', + } + ) if $attribute->value ne ''; + } + } + + if ( $self->backend ) { + $transaction->_result->create_related( + 'pseudonymized_metadata_values', + { + key => 'backend', + value => $self->backend, + tablename => 'illrequestattributes', + } + ); + } +} + =head3 get_op_param_deprecation my $op = $req->check_url_param_deprecation($params); diff --git a/Koha/PseudonymizedTransaction.pm b/Koha/PseudonymizedTransaction.pm index 845505143ca..17079f4ce9e 100644 --- a/Koha/PseudonymizedTransaction.pm +++ b/Koha/PseudonymizedTransaction.pm @@ -22,6 +22,7 @@ use List::MoreUtils qw(any); use Koha::Database; use Koha::Exceptions::Config; use Koha::Patrons; +use Koha::ILL::Requests; use base qw(Koha::Object); @@ -111,6 +112,13 @@ sub new_from_statistic { } } + if ( $statistic->illrequest_id ) { + my $illrequest = Koha::ILL::Requests->find( $statistic->illrequest_id ); + if ($illrequest) { + $illrequest->pseudonymize_illrequestattributes($self); + } + } + return $self; } -- 2.39.5