Bug 21111: Add --exclude-indexes to koha-run-backups
[koha-ffzg.git] / Koha / Plugins.pm
index 092c5e0..36e6090 100644 (file)
@@ -118,24 +118,27 @@ sub GetPlugins {
     # Loop through all plugins that implement at least a method
     while ( my $plugin_class = $plugin_classes->next ) {
 
-        load $plugin_class;
-        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;
+        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 };
+        }
 
     }