From a080ffdf76bf3056f0c422d632f87bb2b8a92d92 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 2 May 2019 13:15:49 -0300 Subject: [PATCH] Bug 21073: Restore filtering by metadata This patch restores filtering the plugins by metadata. That got lost on rebase at some point. Regression tests are added on a prior patch. To test: - Have the 'regression tests for GetPlugins' patch applied - Run: $ kshell k$ prove t/db_dependent/Plugins.t => FAIL: Tests fail! - Apply this patch - Run: k$ prove t/db_dependent/Plugins.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Agustin Moyano Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- Koha/Plugins.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 9d6d827a45..301ae65201 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -20,6 +20,7 @@ package Koha::Plugins; use Modern::Perl; use Class::Inspector; +use List::MoreUtils qw(any); use Module::Load::Conditional qw(can_load); use Module::Load qw(load); use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; @@ -76,8 +77,14 @@ sub GetPlugins { my $plugin_classes = $dbh->selectcol_arrayref('SELECT DISTINCT(plugin_class) FROM plugin_methods'); my @plugins; + # Loop through all plugins that implement at least a method foreach my $plugin_class (@$plugin_classes) { - next if $method && !Koha::Plugins::Methods->search({ plugin_class => $plugin_class, plugin_method => $method })->count; + # filter the plugin out by method + next + if $method + && !Koha::Plugins::Methods->search( + { plugin_class => $plugin_class, plugin_method => $method } )->count; + load $plugin_class; my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); @@ -91,8 +98,17 @@ sub GetPlugins { next unless $plugin_enabled; + # filter the plugin out by metadata + my $plugin_metadata = $plugin->get_metadata; + next + if $plugin_metadata + and %$req_metadata + and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; + push @plugins, $plugin; + } + return @plugins; } -- 2.39.5