From ee6fc112d5f99b3f70c9a50ea187220143e25d50 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 14 Feb 2019 10:45:26 +0000 Subject: [PATCH] Bug 3820: Add changes to MEMBERS MODIFY logaction This patch attemps to add a more refined and detailed info structure detailing what fields were changed and what they were changed from and to. Test Plan: Enable BorrowersLog in the system preferences and undertake a series of borrower detail changes. Go to view the actionlogs and note that MEMBER MODIFY logs now detail what fields you have changed using the following form: { FIELD1: { before: BEFORE_VALUE, after: AFTER_VALUE } } Signed-off-by: Owen Leonard Signed-off-by: Charles Farmer Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Patron.pm | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index dff9320084..ad99c2c804 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -255,33 +255,23 @@ sub store { $self->add_enrolment_fee_if_needed; } - my $borrowers_log = C4::Context->preference("BorrowersLog"); - my $previous_cardnumber = $self_from_storage->cardnumber; - if ($borrowers_log - && ( !defined $previous_cardnumber - || $previous_cardnumber ne $self->cardnumber ) - ) - { - logaction( - "MEMBERS", - "MODIFY", - $self->borrowernumber, - to_json( - { - cardnumber_replaced => { - previous_cardnumber => $previous_cardnumber, - new_cardnumber => $self->cardnumber, - } - }, - { utf8 => 1, pretty => 1 } - ) - ); - } + # Actionlogs + if ( C4::Context->preference("BorrowersLog") ) { + my $info; + for my $key ( keys %{ $self_from_storage->unblessed } ) { + if ( $self_from_storage->$key ne $self->$key ) { + $info->{$key} = { + before => $self_from_storage->$key, + after => $self->$key + }; + } + } - logaction( "MEMBERS", "MODIFY", $self->borrowernumber, - "UPDATE (executed w/ arg: " . $self->borrowernumber . ")" ) - if $borrowers_log; + logaction( "MEMBERS", "MODIFY", $self->borrowernumber, + to_json( $info, { utf8 => 1, pretty => 1, canonical => 1 } ) ); + } + # Final store $self = $self->SUPER::store; } } -- 2.39.5