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 <david@davidnind.com>
Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-04-21 17:15:50 +01:00 committed by Lucas Gass
parent 1846433ffb
commit 4ec43ac10d
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
2 changed files with 17 additions and 2 deletions

View File

@ -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 } );
}

View File

@ -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};