View | Details | Raw Unified | Return to bug 25549
Collapse All | Expand All

(-)a/Koha/Plugins.pm (-18 / +22 lines)
Lines 118-141 sub GetPlugins { Link Here
118
    # Loop through all plugins that implement at least a method
118
    # Loop through all plugins that implement at least a method
119
    while ( my $plugin_class = $plugin_classes->next ) {
119
    while ( my $plugin_class = $plugin_classes->next ) {
120
120
121
        load $plugin_class;
121
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
122
        my $plugin = $plugin_class->new({
122
            my $plugin = $plugin_class->new({
123
            enable_plugins => $self->{'enable_plugins'}
123
                enable_plugins => $self->{'enable_plugins'}
124
                # loads even if plugins are disabled
124
                    # loads even if plugins are disabled
125
                # FIXME: is this for testing without bothering to mock config?
125
                    # FIXME: is this for testing without bothering to mock config?
126
        });
126
            });
127
127
128
        next unless $plugin->is_enabled or
128
            next unless $plugin->is_enabled or
129
                    defined($params->{all}) && $params->{all};
129
                        defined($params->{all}) && $params->{all};
130
130
131
        # filter the plugin out by metadata
131
            # filter the plugin out by metadata
132
        my $plugin_metadata = $plugin->get_metadata;
132
            my $plugin_metadata = $plugin->get_metadata;
133
        next
133
            next
134
            if $plugin_metadata
134
                if $plugin_metadata
135
            and %$req_metadata
135
                and %$req_metadata
136
            and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
136
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
137
137
138
        push @plugins, $plugin;
138
            push @plugins, $plugin;
139
        } elsif ( defined($params->{errors}) && $params->{errors} ){
140
            push @plugins, { error => 'cannot_load', name => $plugin_class };
141
        }
139
142
140
    }
143
    }
141
144
Lines 161-173 sub InstallPlugins { Link Here
161
    my @plugin_classes = $self->plugins();
164
    my @plugin_classes = $self->plugins();
162
    my @plugins;
165
    my @plugins;
163
166
167
    # If we can reload the plugin we will add the methods back, if not they should be removed
168
    Koha::Plugins::Methods->search()->delete();
164
    foreach my $plugin_class (@plugin_classes) {
169
    foreach my $plugin_class (@plugin_classes) {
165
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
170
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
166
            next unless $plugin_class->isa('Koha::Plugins::Base');
171
            next unless $plugin_class->isa('Koha::Plugins::Base');
167
172
168
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
173
            my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} });
169
174
170
            Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete();
171
175
172
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
176
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
173
                Koha::Plugins::Method->new(
177
                Koha::Plugins::Method->new(
(-)a/misc/devel/install_plugins.pl (-4 / +7 lines)
Lines 37-50 unless ( C4::Context->config("enable_plugins") ) { Link Here
37
    exit 1;
37
    exit 1;
38
}
38
}
39
39
40
41
my @existing_plugins = Koha::Plugins->new()->GetPlugins({
40
my @existing_plugins = Koha::Plugins->new()->GetPlugins({
42
    all    => 1,
41
    all    => 1,
42
    errors => 1,
43
});
43
});
44
my $existing_plugins;
44
my $existing_plugins;
45
for my $existing_plugin (@existing_plugins) {
45
for my $existing_plugin (@existing_plugins) {
46
    $existing_plugins->{ $existing_plugin->{metadata}->{name} } =
46
    if( defined $existing_plugin->{error} ){
47
      $existing_plugin->{metadata}->{version};
47
        print "Could not load: ".$existing_plugin->{name}." any associated method will be removed\n";
48
    } else {
49
        $existing_plugins->{ $existing_plugin->{metadata}->{name} } =
50
          $existing_plugin->{metadata}->{version};
51
    }
48
}
52
}
49
53
50
my @installed_plugins = Koha::Plugins->new()->InstallPlugins();
54
my @installed_plugins = Koha::Plugins->new()->InstallPlugins();
51
- 

Return to bug 25549