From 562383504cd92e7ef81fc69564c2b4017cdc239f 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 --- Koha/Plugins.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index ad75c3e560..05011ac72b 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,12 +77,28 @@ 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'} }); + + # 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.21.0