From 1fa4bf3a9609bc7066ce07952064ffd8a7b10253 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 9 Mar 2026 22:05:08 +0000 Subject: [PATCH] Bug 40136: (follow-up) Refactor MODIFY log to use _unblessed_for_log Replace the manual unblessed + skip_fields + blessed-stringify logic in the MODIFY actionlog section with calls to _unblessed_for_log, which already handles all three concerns. This removes the need for @skip_fields, the dateexpiry normalisation workaround, and the inline blessed checks. Also restrict the log_from/log_to hashrefs to only the changed keys, so the diff column contains only fields that actually changed rather than the full patron state. Signed-off-by: Lisette Scheer --- Koha/Patron.pm | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 7af330db6e8..b35d18dc522 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -375,20 +375,12 @@ sub store { # Actionlogs if ( C4::Context->preference("BorrowersLog") || C4::Context->preference("CardnumberLog") ) { - my $from_storage = $self_from_storage->unblessed; - my $from_object = $self->unblessed; + my $from_storage = $self_from_storage->_unblessed_for_log; + my $from_object = $self->_unblessed_for_log; - # Object's dateexpiry is a DateTime object which stringifies to iso8601 datetime, - # but the column is only a date so we need to convert the datetime to just a date - # to know if it has actually changed. - $from_object->{dateexpiry} = dt_from_string( $from_object->{dateexpiry} )->ymd - if $from_object->{dateexpiry}; - - my @skip_fields = (qw/lastseen updated_on password/); - my @keys = C4::Context->preference("BorrowersLog") ? keys %{$from_storage} : ('cardnumber'); + my @keys = C4::Context->preference("BorrowersLog") ? keys %{$from_storage} : ('cardnumber'); my $changed; for my $key (@keys) { - next if any { /$key/ } @skip_fields; my $storage_value = $from_storage->{$key} // q{}; my $object_value = $from_object->{$key} // q{}; if ( ( $storage_value || $object_value ) @@ -399,20 +391,8 @@ sub store { } if ( defined($changed) ) { - my %log_from = map { - my $v = $from_storage->{$_}; - $_ => ( blessed($v) ? "$v" : $v ) - } grep { - my $k = $_; - !any { /$k/ } @skip_fields - } keys %{$from_storage}; - my %log_to = map { - my $v = $from_object->{$_}; - $_ => ( blessed($v) ? "$v" : $v ) - } grep { - my $k = $_; - !any { /$k/ } @skip_fields - } keys %{$from_object}; + my %log_from = map { $_ => $from_storage->{$_} } keys %{$changed}; + my %log_to = map { $_ => $from_object->{$_} } keys %{$changed}; logaction( "MEMBERS", "MODIFY", $self->borrowernumber, \%log_to, undef, \%log_from ) if C4::Context->preference("BorrowersLog"); -- 2.39.5