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

(-)a/Koha/Plugins.pm (-14 / +15 lines)
Lines 104-129 sub call { Link Here
104
104
105
Returns a list of enabled plugins.
105
Returns a list of enabled plugins.
106
106
107
    @plugins = Koha::Plugins->get_enabled_plugins();
107
    @plugins = Koha::Plugins->get_enabled_plugins( [ verbose => 1 ] );
108
108
109
=cut
109
=cut
110
110
111
sub get_enabled_plugins {
111
sub get_enabled_plugins {
112
    my ($class) = @_;
112
    my ( $class, $params ) = @_;
113
113
114
    return unless C4::Context->config('enable_plugins');
114
    return unless C4::Context->config('enable_plugins');
115
115
116
    my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache(ENABLED_PLUGINS_CACHE_KEY);
116
    my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache(ENABLED_PLUGINS_CACHE_KEY);
117
    unless ($enabled_plugins) {
117
    unless ($enabled_plugins) {
118
        my $verbose = $params->{verbose} // $class->_verbose;
118
        $enabled_plugins = [];
119
        $enabled_plugins = [];
119
        my $rs = Koha::Database->schema->resultset('PluginData');
120
        my $rs = Koha::Database->schema->resultset('PluginData');
120
        $rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 });
121
        $rs = $rs->search({ plugin_key => '__ENABLED__', plugin_value => 1 });
121
        my @plugin_classes = $rs->get_column('plugin_class')->all();
122
        my @plugin_classes = $rs->get_column('plugin_class')->all();
122
        foreach my $plugin_class (@plugin_classes) {
123
        foreach my $plugin_class (@plugin_classes) {
123
            unless (can_load(modules => { $plugin_class => undef }, nocache => 1)) {
124
            next unless can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 );
124
                warn "Failed to load $plugin_class: $Module::Load::Conditional::ERROR";
125
                next;
126
            }
127
125
128
            my $plugin = eval { $plugin_class->new() };
126
            my $plugin = eval { $plugin_class->new() };
129
            if ($@ || !$plugin) {
127
            if ($@ || !$plugin) {
Lines 139-144 sub get_enabled_plugins { Link Here
139
    return @$enabled_plugins;
137
    return @$enabled_plugins;
140
}
138
}
141
139
140
sub _verbose {
141
    my $class = shift;
142
    # Return false when running unit tests
143
    return exists $ENV{_} && $ENV{_} =~ /\/prove(\s|$)|\.t$/ ? 0 : 1;
144
}
142
145
143
=head2 feature_enabled
146
=head2 feature_enabled
144
147
Lines 171-176 method or metadata value. Link Here
171
    my @plugins = Koha::Plugins::GetPlugins({
174
    my @plugins = Koha::Plugins::GetPlugins({
172
        method => 'some_method',
175
        method => 'some_method',
173
        metadata => { some_key => 'some_value' },
176
        metadata => { some_key => 'some_value' },
177
        [ verbose => 1 ],
174
    });
178
    });
175
179
176
The method and metadata parameters are optional.
180
The method and metadata parameters are optional.
Lines 183-188 sub GetPlugins { Link Here
183
187
184
    my $method       = $params->{method};
188
    my $method       = $params->{method};
185
    my $req_metadata = $params->{metadata} // {};
189
    my $req_metadata = $params->{metadata} // {};
190
    my $verbose      = delete $params->{verbose} // $self->_verbose;
186
191
187
    my $filter = ( $method ) ? { plugin_method => $method } : undef;
192
    my $filter = ( $method ) ? { plugin_method => $method } : undef;
188
193
Lines 198-204 sub GetPlugins { Link Here
198
    # Loop through all plugins that implement at least a method
203
    # Loop through all plugins that implement at least a method
199
    while ( my $plugin_class = $plugin_classes->next ) {
204
    while ( my $plugin_class = $plugin_classes->next ) {
200
205
201
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
206
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
202
207
203
            my $plugin;
208
            my $plugin;
204
            my $failed_instantiation;
209
            my $failed_instantiation;
Lines 239-245 sub GetPlugins { Link Here
239
244
240
=head2 InstallPlugins
245
=head2 InstallPlugins
241
246
242
Koha::Plugins::InstallPlugins()
247
Koha::Plugins::InstallPlugins( [ verbose => 1 ] )
243
248
244
This method iterates through all plugins physically present on a system.
249
This method iterates through all plugins physically present on a system.
245
For each plugin module found, it will test that the plugin can be loaded,
250
For each plugin module found, it will test that the plugin can be loaded,
Lines 252-263 has removed a plugin directly from the system without using the UI Link Here
252
257
253
sub InstallPlugins {
258
sub InstallPlugins {
254
    my ( $self, $params ) = @_;
259
    my ( $self, $params ) = @_;
260
    my $verbose = $params->{verbose} // $self->_verbose;
255
261
256
    my @plugin_classes = $self->plugins();
262
    my @plugin_classes = $self->plugins();
257
    my @plugins;
263
    my @plugins;
258
264
259
    foreach my $plugin_class (@plugin_classes) {
265
    foreach my $plugin_class (@plugin_classes) {
260
        if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) {
266
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
261
            next unless $plugin_class->isa('Koha::Plugins::Base');
267
            next unless $plugin_class->isa('Koha::Plugins::Base');
262
268
263
            my $plugin;
269
            my $plugin;
Lines 285-294 sub InstallPlugins { Link Here
285
            }
291
            }
286
292
287
            push @plugins, $plugin;
293
            push @plugins, $plugin;
288
        } else {
289
            my $error = $Module::Load::Conditional::ERROR;
290
            # Do not warn the error if the plugin has been uninstalled
291
            warn $error unless $error =~ m|^Could not find or check module '$plugin_class'|;
292
        }
294
        }
293
    }
295
    }
294
296
295
- 

Return to bug 35507