From 61b5da5678f35c7032fcd39f6ba3cec38f43e2a0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 29 Jul 2020 15:11:24 +0200 Subject: [PATCH] Bug 26063: Use Koha::Plugins->call for some other hooks --- C4/Biblio.pm | 27 ++++++++------------------- Koha/Item.pm | 24 +++++++----------------- opac/opac-detail.pl | 32 ++++++++++---------------------- opac/opac-search.pl | 30 +++++++++--------------------- 4 files changed, 34 insertions(+), 79 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 41bdcc504a..f62798db08 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -3446,26 +3446,15 @@ sub _after_biblio_action_hooks { my $biblio_id = $args->{biblio_id}; my $action = $args->{action}; - if ( C4::Context->config("enable_plugins") ) { - - my @plugins = Koha::Plugins->new->GetPlugins({ - method => 'after_biblio_action', - }); - - if (@plugins) { - - my $biblio = Koha::Biblios->find( $biblio_id ); - - foreach my $plugin ( @plugins ) { - try { - $plugin->after_biblio_action({ action => $action, biblio => $biblio, biblio_id => $biblio_id }); - } - catch { - warn "$_"; - }; - } + my $biblio = Koha::Biblios->find( $biblio_id ); + Koha::Plugins->call( + 'after_biblio_action', + { + action => $action, + biblio => $biblio, + biblio_id => $biblio_id, } - } + ); } __END__ diff --git a/Koha/Item.pm b/Koha/Item.pm index 9560a567cb..29406b551d 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -832,24 +832,14 @@ sub _after_item_action_hooks { my $action = $params->{action}; - if ( 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 "$_"; - }; - } + Koha::Plugins->call( + 'after_item_action', + { + action => $action, + item => $self, + item_id => $self->itemnumber, } - } + ); } =head3 _type diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 66a12d8ccb..94a935f0c8 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -185,29 +185,17 @@ if ( $xslfile ) { anonymous_session => ($borrowernumber) ? 0 : 1 }; - if ( C4::Context->config("enable_plugins") ) { - - my @plugins = Koha::Plugins->new->GetPlugins({ - method => 'opac_detail_xslt_variables', - }); - - if (@plugins) { - foreach my $plugin ( @plugins ) { - try { - my $plugin_variables = $plugin->opac_detail_xslt_variables( - { - biblio_id => $biblionumber, - lang => $lang, - patron_id => $borrowernumber - } - ); - $variables = { %$variables, %$plugin_variables }; - } - catch { - warn "$_"; - }; - } + my @plugin_responses = Koha::Plugins->call( + 'opac_detail_xslt_variables', + { + biblio_id => $biblionumber, + lang => $lang, + patron_id => $borrowernumber + } + ); + for my $plugin_variables ( @plugin_responses ) { + $variables = { %$variables, %$plugin_variables }; } $template->param( diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 3a512f830b..70e140bc0c 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -649,28 +649,16 @@ if (C4::Context->preference('OpacHiddenItemsExceptions')){ } my $variables = { anonymous_session => ($borrowernumber) ? 0 : 1 }; -if ( C4::Context->config("enable_plugins") ) { - - my @plugins = Koha::Plugins->new->GetPlugins({ - method => 'opac_results_xslt_variables', - }); - - if (@plugins) { - foreach my $plugin ( @plugins ) { - try { - my $plugin_variables = $plugin->opac_results_xslt_variables( - { - lang => $lang, - patron_id => $borrowernumber - } - ); - $variables = { %$variables, %$plugin_variables }; - } - catch { - warn "$_"; - }; - } + +my @plugin_responses = Koha::Plugins->call( + 'opac_results_xslt_variables', + { + lang => $lang, + patron_id => $borrowernumber } +); +for my $plugin_variables ( @plugin_responses ) { + $variables = { %$variables, %$plugin_variables }; } for (my $i=0;$i<@servers;$i++) { -- 2.20.1