From 4b3657b3d6762d148b57324c7211ede743c15c5b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 15 Sep 2020 16:23:05 -0300 Subject: [PATCH] Bug 26470: Store the item before calling the after action hook This patch makes Koha::Item->store call $self->SUPER::store before calling the hook, so things like the itemnumber (AUTO_INCREMENT field) are available to the plugin hook. It does so by storing the output on a temporary variable, to keep the current behaviour of just returning the output from SUPER::store. To test: 1. Apply the regression tests patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t \ t/db_dependent/Koha/Item.t \ t/db_dependent/Koha/Items.t => FAIL: the hooks tests fail. Item.t hasn't been altered so should pass 3. Apply this patch 4. Repeat 2. => SUCCESS: Tests pass! Item.t as well! (i.e. no behaviour change) 5. Sign off :-D Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- Koha/Item.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 8dffac4db5..8b7a12653f 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -88,7 +88,9 @@ sub store { $self->itype($self->biblio->biblioitem->itemtype); } - my $today = dt_from_string; + my $today = dt_from_string; + my $plugin_action = 'create'; + unless ( $self->in_storage ) { #AddItem unless ( $self->permanent_location ) { $self->permanent_location($self->location); @@ -117,10 +119,10 @@ sub store { logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" ) if $log_action && C4::Context->preference("CataloguingLog"); - $self->_after_item_action_hooks({ action => 'create' }); - } else { # ModItem + $plugin_action = 'modify'; + my %updated_columns = $self->_result->get_dirty_columns; return $self->SUPER::store unless %updated_columns; @@ -190,8 +192,6 @@ sub store { C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" ) unless $params->{skip_modzebra_update}; - $self->_after_item_action_hooks({ action => 'modify' }); - logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper($self->unblessed) ) if $log_action && C4::Context->preference("CataloguingLog"); } @@ -200,7 +200,10 @@ sub store { $self->dateaccessioned($today); } - return $self->SUPER::store; + my $result = $self->SUPER::store; + $self->get_from_storage->_after_item_action_hooks({ action => $plugin_action }); + + return $result; } =head3 delete -- 2.39.5