From f68949f187687da5664fc812f7dc6b2bf8d4cbc6 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 | 21 +++++++++++-------- .../prog/en/modules/tools/viewlog.tt | 14 +++++++++++-- tools/viewlog.pl | 10 +++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index b174636cdd4..708dc1c33d7 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 ); } } @@ -1088,7 +1091,7 @@ sub set_password { module => 'members', letter_code => 'PASSWORD_CHANGE', branchcode => $self_from_storage->branchcode, - , + lang => $self_from_storage->lang || 'default', tables => { 'branches' => $self_from_storage->branchcode, 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 42634a034e8..884a3651993 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -337,7 +337,17 @@ [% END %] - [% IF ( loopro.module == 'CIRCULATION' && loopro.object_found ) %] + [% IF ( loopro.module == 'MEMBERS' && loopro.action == 'PATRON_MERGE' ) %] + [% IF ( loopro.json ) %] + [% 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 %]) + [% ELSE %] + [%# Merge message was not stored as JSON %] + [% loopro.info | 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 2ea2feb3592..fd073fd63c2 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -208,6 +208,16 @@ if ($do_it) { || $log->module eq "FINES" || $log->module eq "APIKEYS" ) { + 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