Bugzilla – Attachment 195037 Details for
Bug 40136
Record diff in action logs when modifying a patron
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40136: (follow-up) Fix extended_attributes logaction to populate diff column
b34124d.patch (text/plain), 4.35 KB, created by
Martin Renvoize (ashimema)
on 2026-03-09 22:15:44 UTC
(
hide
)
Description:
Bug 40136: (follow-up) Fix extended_attributes logaction to populate diff column
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-03-09 22:15:44 UTC
Size:
4.35 KB
patch
obsolete
>From b34124d48307f08af13536772924222819061575 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >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. >--- > 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 <https://www.gnu.org/licenses>. > > 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.53.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40136
:
194872
|
194940
|
195036
| 195037