From 176cddeaadb255e52440c22701f77e109f267b94 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 --- 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 c7ef0c028b..8ae38a30eb 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -2520,38 +2520,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 286e49187a..56104e111d 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 ); @@ -36,6 +37,7 @@ use Koha::IssuingRules; use Koha::Item::Transfer::Limits; use Koha::Item::Transfers; use Koha::Patrons; +use Koha::Plugins; use Koha::Libraries; use Koha::StockRotationItem; use Koha::StockRotationRotas; @@ -143,7 +145,6 @@ sub store { logaction( "CATALOGUING", "MODIFY", $self->itemnumber, "item " . Dumper($self->unblessed) ) if $log_action && C4::Context->preference("CataloguingLog"); - } unless ( $self->dateaccessioned ) { @@ -592,6 +593,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.11.0