From 7d35052a14df66e9c5fe5d70378d36a6b1edb94d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 6 Aug 2019 10:17:28 -0500 Subject: [PATCH] Bug 23463: Move plugin hook From C4::Items to Koha::Item Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize --- C4/Items.pm | 34 ---------------------------------- Koha/Item.pm | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index a5d9d85534..7031f63f13 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2526,38 +2526,4 @@ sub ToggleNewStatus { return $report; } -=head2 _after_item_action_hooks - -Helper method that takes care of calling all plugin hooks - -=cut - -sub _after_item_action_hooks { - my ( $args ) = @_; - - my $item_id = $args->{item_id}; - my $action = $args->{action}; - - if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { - - my @plugins = Koha::Plugins->new->GetPlugins({ - method => 'after_item_action', - }); - - if (@plugins) { - - my $item = Koha::Items->find( $item_id ); - - foreach my $plugin ( @plugins ) { - try { - $plugin->after_item_action({ action => $action, item => $item, item_id => $item_id }); - } - catch { - warn "$_"; - }; - } - } - } -} - 1; diff --git a/Koha/Item.pm b/Koha/Item.pm index a38385e062..db79cb6100 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use List::MoreUtils qw(any); use Data::Dumper; +use Try::Tiny; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -38,6 +39,7 @@ use Koha::CirculationRules; use Koha::Item::Transfer::Limits; use Koha::Item::Transfers; use Koha::Patrons; +use Koha::Plugins; use Koha::Libraries; use Koha::StockRotationItem; use Koha::StockRotationRotas; @@ -145,7 +147,6 @@ sub store { logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper($self->unblessed) ) if $log_action && C4::Context->preference("CataloguingLog"); - } unless ( $self->dateaccessioned ) { @@ -655,6 +656,37 @@ sub to_api_mapping { =head2 Internal methods +=head3 _after_item_action_hooks + +Helper method that takes care of calling all plugin hooks + +=cut + +sub _after_item_action_hooks { + my ( $self, $params ) = @_; + + my $action = $params->{action}; + + if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { + + my @plugins = Koha::Plugins->new->GetPlugins({ + method => 'after_item_action', + }); + + if (@plugins) { + + foreach my $plugin ( @plugins ) { + try { + $plugin->after_item_action({ action => $action, item => $self, item_id => $self->itemnumber }); + } + catch { + warn "$_"; + }; + } + } + } +} + =head3 _type =cut -- 2.39.5