Bugzilla – Attachment 195183 Details for
Bug 40135
Record diff in action logs when modifying a bibliographic record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40135: (follow-up) Strip undef and empty fields from biblio log data
570daed.patch (text/plain), 3.79 KB, created by
Martin Renvoize (ashimema)
on 2026-03-12 12:47:31 UTC
(
hide
)
Description:
Bug 40135: (follow-up) Strip undef and empty fields from biblio log data
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2026-03-12 12:47:31 UTC
Size:
3.79 KB
patch
obsolete
>From 570daed5a4854e04eca5bc28ad5b55866ee3628b Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Thu, 12 Mar 2026 10:48:13 +0000 >Subject: [PATCH] Bug 40135: (follow-up) Strip undef and empty fields from > biblio log data > >Add _unblessed_for_log to Koha::Biblio, mirroring the same method in >Koha::Patron (bug 40136). It excludes undef/empty-string columns and the >auto-updated timestamp field so that biblio diffs only contain meaningful >values. > >Update AddBiblio, ModBiblio and DelBiblio in C4/Biblio.pm to use >_unblessed_for_log instead of raw unblessed when building the hashrefs >passed to logaction, eliminating noise from null columns in ADD/MODIFY/DELETE >diffs. >--- > C4/Biblio.pm | 8 ++++---- > Koha/Biblio.pm | 24 ++++++++++++++++++++++++ > 2 files changed, 28 insertions(+), 4 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index d52ac44ab3c..d1578d9a62b 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -315,7 +315,7 @@ sub AddBiblio { > my $marc_for_log = eval { $new_biblio->metadata->record_strip_nonxml }; > logaction( > "CATALOGUING", "ADD", $biblionumber, "biblio", undef, >- { %{ $new_biblio->unblessed }, _marc => _marc_record_to_diffable($marc_for_log) } >+ { %{ $new_biblio->_unblessed_for_log }, _marc => _marc_record_to_diffable($marc_for_log) } > ); > } > >@@ -405,7 +405,7 @@ sub ModBiblio { > my ( $original, $original_marc ); > if ( C4::Context->preference("CataloguingLog") ) { > my $pre_biblio = Koha::Biblios->find($biblionumber); >- $original = $pre_biblio->unblessed; >+ $original = $pre_biblio->_unblessed_for_log; > $original_marc = eval { $pre_biblio->metadata->record_strip_nonxml }; > } > >@@ -474,7 +474,7 @@ sub ModBiblio { > my $updated_marc_log = eval { $updated_biblio->metadata->record_strip_nonxml }; > logaction( > "CATALOGUING", "MODIFY", $biblionumber, >- { %{ $updated_biblio->unblessed }, _marc => _marc_record_to_diffable($updated_marc_log) }, >+ { %{ $updated_biblio->_unblessed_for_log }, _marc => _marc_record_to_diffable($updated_marc_log) }, > undef, > { %{$original}, _marc => _marc_record_to_diffable($original_marc) } > ); >@@ -627,7 +627,7 @@ sub DelBiblio { > > logaction( > "CATALOGUING", "DELETE", $biblionumber, "biblio", undef, >- { %{ $biblio->unblessed }, _marc => _marc_record_to_diffable($biblio_marc) } >+ { %{ $biblio->_unblessed_for_log }, _marc => _marc_record_to_diffable($biblio_marc) } > ) if C4::Context->preference("CataloguingLog"); > > Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [$biblionumber] } ) >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 1f3f0b45e13..7e8dfeb706d 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -20,6 +20,7 @@ package Koha::Biblio; > use Modern::Perl; > > use List::MoreUtils qw( any ); >+use Scalar::Util qw( blessed ); > use URI; > use URI::Escape qw( uri_escape_utf8 ); > use Try::Tiny; >@@ -2402,6 +2403,29 @@ sub merge_with { > > =head2 Internal methods > >+=head3 _unblessed_for_log >+ >+Returns a plain hashref of biblio column values safe for JSON serialisation >+and action log diffing. Timestamp is excluded as it changes on every write, >+and undef/empty-string fields are removed so that genuinely unset columns >+do not produce noise in diffs. >+ >+=cut >+ >+sub _unblessed_for_log { >+ my ($self) = @_; >+ my $data = $self->unblessed; >+ delete $data->{timestamp}; >+ for my $key ( keys %$data ) { >+ if ( defined $data->{$key} && $data->{$key} ne '' ) { >+ $data->{$key} = "$data->{$key}" if blessed( $data->{$key} ); >+ } else { >+ delete $data->{$key}; >+ } >+ } >+ return $data; >+} >+ > =head3 type > > =cut >-- >2.53.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40135
:
194785
|
194941
|
195009
|
195010
|
195033
|
195034
|
195035
|
195183
|
195184
|
195195
|
195196
|
195197
|
195198
|
195199