Browse Source

Bug 23463: Move plugin hook

From C4::Items to Koha::Item

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Jonathan Druart 5 years ago
committed by Martin Renvoize
parent
commit
7d35052a14
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 34
      C4/Items.pm
  2. 34
      Koha/Item.pm

34
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;

34
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

Loading…
Cancel
Save