+ my ( $self, $params ) = @_;
+
+ my $method = $params->{method};
+ my $req_metadata = $params->{metadata} // {};
+
+ my $filter = ( $method ) ? { plugin_method => $method } : undef;
+
+ my $plugin_classes = Koha::Plugins::Methods->search(
+ $filter,
+ { columns => 'plugin_class',
+ distinct => 1
+ }
+ )->_resultset->get_column('plugin_class');
+
+ my @plugins;
+
+ # Loop through all plugins that implement at least a method
+ while ( my $plugin_class = $plugin_classes->next ) {
+
+ if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
+ my $plugin = $plugin_class->new({
+ enable_plugins => $self->{'enable_plugins'}
+ # loads even if plugins are disabled
+ # FIXME: is this for testing without bothering to mock config?
+ });
+
+ next unless $plugin->is_enabled or
+ defined($params->{all}) && $params->{all};
+
+ # 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;
+ } elsif ( defined($params->{errors}) && $params->{errors} ){
+ push @plugins, { error => 'cannot_load', name => $plugin_class };
+ }
+
+ }
+
+ return @plugins;
+}
+
+=head2 InstallPlugins
+
+Koha::Plugins::InstallPlugins()
+
+This method iterates through all plugins physically present on a system.
+For each plugin module found, it will test that the plugin can be loaded,
+and if it can, will store its available methods in the plugin_methods table.
+
+NOTE: We re-load all plugins here as a protective measure in case someone
+has removed a plugin directly from the system without using the UI
+
+=cut
+
+sub InstallPlugins {
+ my ( $self, $params ) = @_;