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

(-)a/Koha/Plugins.pm (-23 / +25 lines)
Lines 115-136 sub GetPlugins { Link Here
115
115
116
    my $method       = $params->{method};
116
    my $method       = $params->{method};
117
    my $req_metadata = $params->{metadata} // {};
117
    my $req_metadata = $params->{metadata} // {};
118
118
    my $all          = $params->{all} // 0;
119
    my $filter = ( $method ) ? { plugin_method => $method } : undef;
119
    my $nocache      = 0;
120
120
121
    my $plugin_classes = Koha::Plugins::Methods->search(
121
    my @plugin_classes;
122
        $filter,
122
    if ($all) {
123
        {   columns  => 'plugin_class',
123
        @plugin_classes = $self->plugins();
124
            distinct => 1
124
125
        }
125
        # Do not use Module::Load::Conditional cache if we want all plugins
126
    )->_resultset->get_column('plugin_class');
126
        # as $self->plugins can return uninstalled plugins
127
        $nocache = 1;
128
    } else {
129
        my $rs = Koha::Database->schema->resultset('PluginData');
130
        $rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 });
131
        @plugin_classes = $rs->get_column('plugin_class')->all();
132
    }
127
133
128
    my @plugins;
134
    my @plugins;
129
135
    foreach my $plugin_class (@plugin_classes) {
130
    # Loop through all plugins that implement at least a method
136
        if ( can_load( modules => { $plugin_class => undef }, nocache => $nocache ) ) {
131
    while ( my $plugin_class = $plugin_classes->next ) {
137
            next unless $plugin_class->isa('Koha::Plugins::Base');
132
138
            next if $method && !$plugin_class->can($method);
133
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
134
139
135
            my $plugin;
140
            my $plugin;
136
            my $failed_instantiation;
141
            my $failed_instantiation;
Lines 149-163 sub GetPlugins { Link Here
149
154
150
            next if $failed_instantiation;
155
            next if $failed_instantiation;
151
156
152
            next unless $plugin->is_enabled or
153
                        defined($params->{all}) && $params->{all};
154
155
            # filter the plugin out by metadata
157
            # filter the plugin out by metadata
156
            my $plugin_metadata = $plugin->get_metadata;
158
            if (%$req_metadata) {
157
            next
159
                my $plugin_metadata = $plugin->get_metadata;
158
                if $plugin_metadata
160
                next
159
                and %$req_metadata
161
                    if $plugin_metadata
160
                and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
162
                    and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata;
163
            }
161
164
162
            push @plugins, $plugin;
165
            push @plugins, $plugin;
163
        } elsif ( defined($params->{errors}) && $params->{errors} ){
166
        } elsif ( defined($params->{errors}) && $params->{errors} ){
164
- 

Return to bug 28172