Bug 42032 - Add diff support to AUTHORITIES action logs
Summary: Add diff support to AUTHORITIES action logs
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Transaction logs (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Martin Renvoize (ashimema)
QA Contact: Testopia
URL:
Keywords:
Depends on: 40135
Blocks: 37940
  Show dependency treegraph
 
Reported: 2026-03-09 15:36 UTC by Martin Renvoize (ashimema)
Modified: 2026-03-09 19:25 UTC (History)
1 user (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This enhancement adds a 'diff' to the action logs when modifying an authority record (creating, modifying, and deleting). Previously, no diff was recorded (although some information was recorded in the Info column).
Version(s) released in:
Circulation function:


Attachments
Bug 42032: Include MARC field changes in AUTHORITIES diff logs (9.31 KB, patch)
2026-03-09 18:03 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 42032: Include MARC field changes in AUTHORITIES diff logs (9.35 KB, patch)
2026-03-09 19:23 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Renvoize (ashimema) 2026-03-09 15:36:43 UTC
The action logging in C4/AuthoritiesMarc.pm for authority record changes currently passes unstructured text (or the literal string 'authority') to logaction(). No structured diff is generated in the action_logs.diff column.

Affected calls in C4/AuthoritiesMarc.pm:
- AUTHORITIES/ADD    (~line 688): logaction( "AUTHORITIES", "ADD",    $authid, "authority" )
- AUTHORITIES/DELETE (~line 755): logaction( "AUTHORITIES", "DELETE", $authid, "authority" )
- AUTHORITIES/MODIFY (~line 792): logaction( "AUTHORITIES", "MODIFY", $authid, "authority BEFORE=>" . $oldrecord->as_formatted )

This bug covers updating these calls to pass structured data. A Koha::Authority object (or its unblessed hashref) should be passed as $infos and $original so that the structured diff mechanism can generate a proper before/after comparison. The MODIFY case already captures the old record; this should be passed as $original in the new structured format.
Comment 1 Martin Renvoize (ashimema) 2026-03-09 18:03:25 UTC
Created attachment 195021 [details] [review]
Bug 42032: Include MARC field changes in AUTHORITIES diff logs

The AUTHORITIES action log entries for authority operations previously
stored minimal data: ADD and DELETE logged just the string "authority",
while MODIFY logged a raw MARC-formatted dump of the pre-change record
as a plain text string ("authority BEFORE=>..."). None of these populated
the diff column.

This patch updates AddAuthority, ModAuthority and DelAuthority in
C4/AuthoritiesMarc.pm to follow the same pattern introduced for biblios
in bug 40135: passing combined hashrefs to logaction so that the diff
column is automatically populated with Struct::Diff JSON.

The combined hashref contains the auth_header table columns (authtypecode,
heading, origincode, etc. — excluding the raw marcxml blob) plus a _marc
key built by the new _marc_record_to_diffable helper, which converts a
MARC::Record into a tag => array-of-formatted-strings structure readable
by the existing diff viewer.

A new _authority_log_data helper packages the authority unblessed data
and MARC record into the combined hashref, keeping the three call sites
concise.

For ADD, the logaction is now emitted after the authority record has been
fully stored (after _after_authority_action_hooks), so the diff captures
the complete saved state. For MODIFY, the before-state is captured from
Koha::Authorities before calling AddAuthority, and the after-state is
read back once AddAuthority has committed the new data. For DELETE, the
MARC is captured before the authority is removed.

The diff column for MODIFY will now show both authority table column
changes (e.g. heading) and MARC field-level changes (e.g. _marc.151.0)
in the existing diff viewer table in the log viewer.

Tests are added to verify that ADD, MODIFY, and DELETE all populate the
diff column and that _marc content is captured correctly.
Comment 2 David Nind 2026-03-09 19:23:54 UTC
Created attachment 195024 [details] [review]
Bug 42032: Include MARC field changes in AUTHORITIES diff logs

The AUTHORITIES action log entries for authority operations previously
stored minimal data: ADD and DELETE logged just the string "authority",
while MODIFY logged a raw MARC-formatted dump of the pre-change record
as a plain text string ("authority BEFORE=>..."). None of these populated
the diff column.

This patch updates AddAuthority, ModAuthority and DelAuthority in
C4/AuthoritiesMarc.pm to follow the same pattern introduced for biblios
in bug 40135: passing combined hashrefs to logaction so that the diff
column is automatically populated with Struct::Diff JSON.

The combined hashref contains the auth_header table columns (authtypecode,
heading, origincode, etc. — excluding the raw marcxml blob) plus a _marc
key built by the new _marc_record_to_diffable helper, which converts a
MARC::Record into a tag => array-of-formatted-strings structure readable
by the existing diff viewer.

A new _authority_log_data helper packages the authority unblessed data
and MARC record into the combined hashref, keeping the three call sites
concise.

For ADD, the logaction is now emitted after the authority record has been
fully stored (after _after_authority_action_hooks), so the diff captures
the complete saved state. For MODIFY, the before-state is captured from
Koha::Authorities before calling AddAuthority, and the after-state is
read back once AddAuthority has committed the new data. For DELETE, the
MARC is captured before the authority is removed.

The diff column for MODIFY will now show both authority table column
changes (e.g. heading) and MARC field-level changes (e.g. _marc.151.0)
in the existing diff viewer table in the log viewer.

Tests are added to verify that ADD, MODIFY, and DELETE all populate the
diff column and that _marc content is captured correctly.

Signed-off-by: David Nind <david@davidnind.com>