From 4ec43ac10dcd669c606791ff321dd018f15a82bd Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 21 Apr 2026 17:15:50 +0100 Subject: [PATCH] Bug 42188: (follow-up) Skip JSON payload in info column on ADD The info column for CATALOGUING action logs is, by convention, the record state before modification -- MODIFY writes the pre-change JSON payload, DELETE writes the state at time of deletion, but ADD has no pre-change state. Writing the new record state into info on ADD duplicates the state that the subsequent MODIFY (if any) captures as its "before" snapshot, and conflicts with that convention. Skip the JSON payload on ADD so info degrades to the bare "biblio" prefix. The diff column already captures the full creation (every field "added" against an empty hashref), so no information is lost. Test plan: 1. prove t/db_dependent/Koha/Biblio.t 2. Observe that the "CataloguingLog MARC-in-JSON diff tests" subtest now also asserts: - ADD info == "biblio" - MODIFY info matches /^biblio \{/ - DELETE info matches /^biblio \{/ 3. Create / modify / delete a record via the staff UI with CataloguingLog on, then check action_logs: the ADD row's info column should read just "biblio". Signed-off-by: David Nind Signed-off-by: Lisette Scheer Signed-off-by: Lucas Gass --- C4/Log.pm | 5 ++++- t/db_dependent/Koha/Biblio.t | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/C4/Log.pm b/C4/Log.pm index 0c923d8cdd..1a0e400ab0 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -94,7 +94,10 @@ sub logaction { } } else { $updated = $infos; - if ( $modulename eq 'CATALOGUING' && ref $original eq 'HASH' ) { + if ( $modulename eq 'CATALOGUING' + && ref $original eq 'HASH' + && $actionname ne 'ADD' ) + { my $prefix = ref $infos eq 'HASH' ? 'biblio' : $infos; $infos = "$prefix " . to_json( $original, { utf8 => 1, pretty => 1 } ); } diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 5c5cd83e11..13822b0423 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -2471,7 +2471,7 @@ subtest '_unblessed_for_log() tests' => sub { subtest 'CataloguingLog MARC-in-JSON diff tests' => sub { - plan tests => 18; + plan tests => 21; $schema->storage->txn_begin; @@ -2489,6 +2489,10 @@ subtest 'CataloguingLog MARC-in-JSON diff tests' => sub { my $add_log = Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'ADD' } )->next; ok( defined $add_log->diff, 'ADD log populates the diff column' ); + is( + $add_log->info, 'biblio', + 'ADD log info column is the bare "biblio" prefix (no pre-change JSON payload)' + ); my $add_diff = from_json( $add_log->diff ); my $add_added = $add_diff->{D}{_marc}{A}; @@ -2516,6 +2520,10 @@ subtest 'CataloguingLog MARC-in-JSON diff tests' => sub { my $mod_log = Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'MODIFY' } )->next; ok( defined $mod_log->diff, 'MODIFY log populates the diff column' ); + like( + $mod_log->info, qr/^biblio \{/, + 'MODIFY log info column carries the pre-change JSON payload' + ); my $mod_diff = from_json( $mod_log->diff ); ok( exists $mod_diff->{D}{_marc}, 'MODIFY diff contains _marc key' ); @@ -2528,6 +2536,10 @@ subtest 'CataloguingLog MARC-in-JSON diff tests' => sub { my $del_log = Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'DELETE' } )->next; ok( defined $del_log->diff, 'DELETE log populates the diff column' ); + like( + $del_log->info, qr/^biblio \{/, + 'DELETE log info column carries the final-state JSON payload' + ); my $del_diff = from_json( $del_log->diff ); my $del_removed = $del_diff->{D}{_marc}{R};