From 255418fb48129147bf39ee44cb076be6cb1a5fea Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Tue, 30 Jul 2024 11:03:54 +0000 Subject: [PATCH] Bug 37522: Logging item modification should record the original version of the item When modifying bibliographic record, Koha records in the log the original version of the record. This allows one to see what has been changed in the record. However, in case of item modification Koha records in the log the the current version of the item (i.e. the version after the edit). This is inconsistent with the biblio modification behavior and makes it difficult or even impossible to trace changes (especially in case of the first modif since the initial version is not being recorded). This patch makes the item modification logging feature work similarly to logging modifications in bibliographic records. Test plan: ========== 1. With CataloguingLog enabled (default in ktd) make a modification of an item. 2. Check the Modification log. You should see as the recorded version the version of the item after the modification. 3. Apply the patch; restart_all. 4. Repeat p. 1. 5. In the Modification log you should see now the version of the item that existed before the recent modification. Sponsored-by: Ignatianum University in Cracow Signed-off-by: Roman Dolny Signed-off-by: Kyle M Hall --- C4/Log.pm | 2 +- Koha/Item.pm | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/C4/Log.pm b/C4/Log.pm index d7ad162c4cb..cf0fd34de78 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -88,7 +88,7 @@ sub logaction { local $Data::Dumper::Sortkeys = 1; if ( $infos->isa('Koha::Item') && $modulename eq 'CATALOGUING' && $actionname eq 'MODIFY' ) { - $infos = "item " . Dumper($updated); + $infos = "item " . Dumper( $original->unblessed ); } else { $infos = Dumper($updated); } diff --git a/Koha/Item.pm b/Koha/Item.pm index 05d65d1da3d..08f03791f10 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -215,11 +215,12 @@ sub store { } } + my $original = Koha::Items->find( $self->itemnumber ); # $original will be undef if $action eq 'create' my $result = $self->SUPER::store; if ( $log_action && C4::Context->preference("CataloguingLog") ) { $action eq 'create' - ? logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" ) - : logaction( "CATALOGUING", "MODIFY", $self->itemnumber, $self ); + ? logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" ) + : logaction( "CATALOGUING", "MODIFY", $self->itemnumber, $self, undef, $original ); } my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ) -- 2.39.3 (Apple Git-146)