From a3c7269fbb4920dddfa6ea0ff1dafb6afe050080 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 9 Mar 2026 22:15:08 +0000 Subject: [PATCH] Bug 40136: (follow-up) Fix extended_attributes logaction to populate diff column The extended_attributes setter and add_extended_attribute both logged attribute changes using the old custom {before, after} format passed as the info string, with no $original argument, so the diff column was never populated. Split the existing $change->{before}/$change->{after} into separate $log_from/$log_to hashrefs and call logaction with the standard signature, so Struct::Diff generates the diff column as with other MEMBERS/MODIFY entries. Update tests to reflect the new info column format (after-state only) and remove a stray debug Data::Dumper/print left in the test. Signed-off-by: Lisette Scheer --- Koha/Patron.pm | 18 +++++++----------- t/db_dependent/Koha/Patron/Attribute.t | 20 ++++---------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index b35d18dc522..9ab86dc27a2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -21,7 +21,6 @@ package Koha::Patron; use Modern::Perl; use List::MoreUtils qw( any none uniq notall zip6); -use JSON qw( to_json ); use Scalar::Util qw( blessed looks_like_number ); use Unicode::Normalize qw( NFKD ); use Try::Tiny; @@ -2553,10 +2552,10 @@ sub add_extended_attribute { if ( C4::Context->preference("BorrowersLog") ) { my $code = $attribute->{code}; logaction( - "MEMBERS", - "MODIFY", - $self->borrowernumber, - to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } ) + "MEMBERS", "MODIFY", $self->borrowernumber, + { "attribute.$code" => $change->{after} }, + undef, + { "attribute.$code" => $change->{before} } ); } @@ -2680,12 +2679,9 @@ sub extended_attributes { } if ( %{$all_changes} ) { - logaction( - "MEMBERS", - "MODIFY", - $self->borrowernumber, - to_json( $all_changes, { pretty => 1, canonical => 1 } ) - ); + my %log_from = map { $_ => $all_changes->{$_}->{before} } keys %{$all_changes}; + my %log_to = map { $_ => $all_changes->{$_}->{after} } keys %{$all_changes}; + logaction( "MEMBERS", "MODIFY", $self->borrowernumber, \%log_to, undef, \%log_from ); } } ); diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index baaf564ef42..8d80d32c2ba 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use JSON qw( to_json ); +use JSON qw( encode_json from_json ); use Test::NoWarnings; use Test::More tests => 5; @@ -531,20 +531,10 @@ subtest 'action log tests' => sub { my $get_info = sub { my ( $before, $after, $code, $repeatable ) = @_; - my $change = { - before => $before, - after => $after - }; if ($repeatable) { - while ( my ( $k, $v ) = each %{$change} ) { - if ( ref $v eq 'ARRAY' ) { - $change->{$k} = [ sort @{$v} ]; - } else { - $change->{$k} = $v ? [$v] : []; - } - } + $after = ref $after eq 'ARRAY' ? [ sort @{$after} ] : ( $after ? [$after] : [] ); } - return to_json( { "attribute.$code" => $change }, { pretty => 1, canonical => 1 } ); + return encode_json( { "attribute.$code" => $after } ); }; my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -689,9 +679,7 @@ subtest 'action log tests' => sub { ]; $patron->extended_attributes($attributes); - $info = $get_info->( [], [ 'Foo', 'Bar' ], $attribute_type->code, 1 ); - use Data::Dumper; - print Dumper($info); + $info = $get_info->( [], [ 'Foo', 'Bar' ], $attribute_type->code, 1 ); $action_logs = Koha::ActionLogs->search( { module => "MEMBERS", -- 2.39.5