From 68e4d2a3878fc3b7097311194e2b34763387e5bc Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 26 Jun 2023 15:46:56 +0000 Subject: [PATCH] Bug 34121: Filter enabled plugins for the given method --- Koha/Plugins.pm | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index a3c47006b5..e2e923f8bc 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -80,7 +80,7 @@ sub call { return unless C4::Context->config('enable_plugins'); my @responses; - my @plugins = $class->get_enabled_plugins(); + my @plugins = $class->get_enabled_plugins($method); @plugins = grep { $_->can($method) } @plugins; # TODO: Remove warn when after_hold_create is removed from the codebase @@ -104,12 +104,12 @@ sub call { Returns a list of enabled plugins. - @plugins = Koha::Plugins->get_enabled_plugins(); + @plugins = Koha::Plugins->get_enabled_plugins([$method]); =cut sub get_enabled_plugins { - my ($class) = @_; + my ( $class, $method ) = @_; return unless C4::Context->config('enable_plugins'); @@ -119,6 +119,21 @@ sub get_enabled_plugins { my $rs = Koha::Database->schema->resultset('PluginData'); $rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 }); my @plugin_classes = $rs->get_column('plugin_class')->all(); + + # Filter any enabled plugins that don't have the given method if one was passed in + if ($method) { + my @plugin_classes_with_method = Koha::Plugins::Methods->search( + { method => $method }, + { + columns => 'plugin_class', + distinct => 1 + } + )->as_list; + + my %seen = map { $_ => 1 } @plugin_classes; + my @plugin_classes = grep { $seen{$_} } @plugin_classes_with_method; + } + foreach my $plugin_class (@plugin_classes) { unless (can_load(modules => { $plugin_class => undef }, nocache => 1)) { warn "Failed to load $plugin_class: $Module::Load::Conditional::ERROR"; -- 2.30.2