From 75a0ef78d67431812758ac77b5c19002850ccbd1 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 6 Jan 2026 14:08:39 -0500 Subject: [PATCH] Bug 41425: Log entries for merging patrons are untranslatable This patch changes the way information is logged during patron merges. Instead of building an English sentence to be stored in the log now it stores JSON containing information about the patron record and the record which it is being merged with. To test, apply the patch and restart_services. - If necessary, go to Administration -> System preferences -> Logs and enable BorrowersLog. - Perform a patron search which will return more than one result. - Check the box next to two or more results and click "Merge selected patrons" in the toolbar. - Select one of the patron records to be merged with and click "Merge patrons." - Go to Tools -> Log viewer and perform a search limited to the patron module with "Display from" and "Display to" set to today. - You should see an entry for the patron merge you performed, with the updated patron linked in the "Object" column and information about the merge in the "Info" column, e.g. "John Smith (12345) merged with John Smith (45678). Sponsored-by: Athens County Public Libraries --- Koha/Patron.pm | 19 +++++++++++-------- .../prog/en/modules/tools/viewlog.tt | 11 +++++++++-- tools/viewlog.pl | 10 ++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 7b8b69315b8..5a9128d9330 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -764,14 +764,17 @@ sub merge_with { $patron->delete(); if ( C4::Context->preference("BorrowersLog") ) { - my $info = - ( $patron->firstname // "" ) . " " - . ( $patron->surname // "" ) . " (" - . ( $patron->cardnumber // "" ) . ")" - . " has been merged into " - . ( $self->firstname // "" ) . " " - . ( $self->surname // "" ) . " (" - . ( $self->cardnumber // "" ) . ")"; + my $info = to_json( + { + patron_firstname => $patron->firstname || "", + patron_surname => $patron->surname || "", + patron_cardnumber => $patron->cardnumber || "", + merged_firstname => $self->firstname || "", + merged_surname => $self->surname || "", + merged_cardnumber => $self->cardnumber || "", + }, + { pretty => 1, canonical => 1 } + ); logaction( "MEMBERS", "PATRON_MERGE", $self->id, $info ); } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 6e434a5c67f..67a4836ab35 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -327,7 +327,14 @@ [% END %] - [% IF ( loopro.module == 'CIRCULATION' && loopro.object_found ) %] + [% IF ( loopro.module == 'MEMBERS' ) %] + [% IF ( loopro.action == 'PATRON_MERGE') %] + [% loopro.json.patron_firstname | html %] + [% loopro.json.patron_surname | html %] + ([% loopro.json.patron_cardnumber | html %]) [% tp("[patron] merged into [patron]", "merged into") | html %] [% loopro.json.merged_firstname | html %] [% loopro.json.merged_surname | html %] + ([% loopro.json.merged_cardnumber | html %]) + [% END %] + [% ELSIF ( loopro.module == 'CIRCULATION' && loopro.object_found ) %]
Hold [% loopro.json.hold | html %] on biblio [% loopro.json.biblionumber | html %]Hold [% loopro.json.hold | html %] on bibliographic record [% loopro.json.biblionumber | html %] [% IF loopro.json.itemnumber %] - diff --git a/tools/viewlog.pl b/tools/viewlog.pl index 73d35670c78..02a501e5406 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -205,6 +205,16 @@ if ($do_it) { #add firstname and surname for borrower, when using the CIRCULATION, MEMBERS, FINES if ( $log->module eq "CIRCULATION" || $log->module eq "MEMBERS" || $log->module eq "FINES" ) { + my $info = $log->info; + my $decoded; + my $is_json = eval { + $decoded = decode_json($info); + 1; + }; + if ( $is_json && ref($decoded) ) { + $result->{'json_found'} = 1; + $result->{'json'} = $decoded; + } if ( $log->object ) { my $patron = Koha::Patrons->find( $log->object ); if ( $patron && $output eq 'screen' ) { -- 2.39.5