From 4297841b98c7f992ef18c400fae2d7d77ae84b9e Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 11 May 2017 00:44:12 +0000 Subject: [PATCH] Bug 18626: Add ability to track cardnumber changes for patrons MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some libraries want to keep a history of cardnumber changes for a patron. This is a feature that another ILS has. Test Plan: 1) Apply this patch 2) Enable the BorrowersLog 3) Modify a patron, update his or her cardnumber 4) Notice the entry in the action log containing the old and new cardnumbers 5) Edit a patron, leave the cardnumber the same 6) Note there is no cardnumber change entry in the action logs 7) Disable BorrowersLog, modify a patron cardnumber 8) Note there is no cardnumber change entry in teh action logs Followed test plan, works as expected Signed-off-by: Marc Véron Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Members.pm | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/C4/Members.pm b/C4/Members.pm index 6e9429bb8b..53e131ac3e 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -27,6 +27,7 @@ use String::Random qw( random_string ); use Scalar::Util qw( looks_like_number ); use Date::Calc qw/Today check_date Date_to_Days/; use List::MoreUtils qw( uniq ); +use JSON qw(to_json); use C4::Log; # logaction use C4::Overdues; use C4::Reserves; @@ -324,6 +325,25 @@ sub ModMember { my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} ); + my $borrowers_log = C4::Context->preference("BorrowersLog"); + if ( $borrowers_log && $patron->cardnumber ne $new_borrower->{cardnumber} ) + { + logaction( + "MEMBERS", + "MODIFY", + $data{'borrowernumber'}, + to_json( + { + cardnumber_replaced => { + previous_cardnumber => $patron->cardnumber, + new_cardnumber => $new_borrower->{cardnumber}, + } + }, + { utf8 => 1, pretty => 1 } + ) + ); + } + delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid}; my $execute_success = $patron->store if $patron->set($new_borrower); @@ -355,7 +375,7 @@ sub ModMember { Koha::NorwegianPatronDB::NLSync({ 'borrowernumber' => $data{'borrowernumber'} }); } - logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if C4::Context->preference("BorrowersLog"); + logaction("MEMBERS", "MODIFY", $data{'borrowernumber'}, "UPDATE (executed w/ arg: $data{'borrowernumber'})") if $borrowers_log; } return $execute_success; } -- 2.39.5