Bug 23916: (follow-up) Don't anonymise issuer and don't update action_logs on upgrade
[koha-ffzg.git] / Koha / Plugins.pm
index 8d6957a..36e6090 100644 (file)
@@ -19,6 +19,7 @@ package Koha::Plugins;
 
 use Modern::Perl;
 
+use Array::Utils qw(array_minus);
 use Class::Inspector;
 use List::MoreUtils qw(any);
 use Module::Load::Conditional qw(can_load);
@@ -32,7 +33,7 @@ use Koha::Plugins::Methods;
 BEGIN {
     my $pluginsdir = C4::Context->config("pluginsdir");
     my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir;
-    push( @INC, @pluginsdir );
+    push @INC, array_minus(@pluginsdir, @INC) ;
     pop @INC if $INC[-1] eq '.';
 }
 
@@ -117,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;
+        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;
+            push @plugins, $plugin;
+        } elsif ( defined($params->{errors}) && $params->{errors} ){
+            push @plugins, { error => 'cannot_load', name => $plugin_class };
+        }
 
     }