From 2f73c12852ea18fdc7c302c9eaa69496f5d516d7 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 28 Feb 2025 13:06:15 +0100 Subject: [PATCH] Bug 26744: Cosolidate changes and change log format --- Koha/Patron.pm | 21 ++++++++++++--------- t/db_dependent/Koha/Patron/Attribute.t | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 3c4099f9839..bd3572d92c4 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2256,11 +2256,12 @@ sub add_extended_attribute { )->store; if ( C4::Context->preference("BorrowersLog") ) { + my $code = $attribute->{code}; logaction( "MEMBERS", "MODIFY", $self->borrowernumber, - "Patron attribute " . $attribute->{code} . ": " . to_json( $change, { pretty => 1, canonical => 1 } ) + to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } ) ); } @@ -2325,6 +2326,7 @@ sub extended_attributes { my $schema = $self->_result->result_source->schema; $schema->txn_do( sub { + my $all_changes = {}; while ( my ( $repeatable, $changes ) = each %attribute_changes ) { while ( my ( $code, $change ) = each %{$changes} ) { $change->{before} //= []; @@ -2348,14 +2350,7 @@ sub extended_attributes { $attribute->store() if ( $attribute->code eq $code ); } if ( C4::Context->preference("BorrowersLog") ) { - logaction( - "MEMBERS", - "MODIFY", - $self->borrowernumber, - "Patron attribute " - . $code . ": " - . to_json( $change, { pretty => 1, canonical => 1 } ) - ); + $all_changes->{"attribute.$code"} = $change; } } } @@ -2386,6 +2381,14 @@ sub extended_attributes { type => $type, ) if !$new_types->{$type}; } + if ( %{$all_changes} ) { + logaction( + "MEMBERS", + "MODIFY", + $self->borrowernumber, + to_json( $all_changes, { pretty => 1, canonical => 1 } ) + ); + } } ); } diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index c4b57e19f45..c561355c45e 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -543,7 +543,7 @@ subtest 'action log tests' => sub { } } } - return "Patron attribute " . $code . ": " . to_json( $change, { pretty => 1, canonical => 1 } ); + return to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } ); }; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); -- 2.48.1