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

(-)a/Koha/Plugins.pm (-2 / +30 lines)
Lines 28-33 use Module::Pluggable search_path => ['Koha::Plugin'], Link Here
28
    except                        => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
28
    except                        => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/;
29
use Try::Tiny;
29
use Try::Tiny;
30
use POSIX qw(getpid);
30
use POSIX qw(getpid);
31
use version 0.77 qw(is_lax);
31
32
32
use C4::Context;
33
use C4::Context;
33
use C4::Output;
34
use C4::Output;
Lines 306-311 sub InstallPlugins { Link Here
306
    my @plugin_classes = $self->plugins();
307
    my @plugin_classes = $self->plugins();
307
    my @plugins;
308
    my @plugins;
308
309
310
    my $fail = sub {
311
        my $message = shift;
312
        if ( $params->{fatal} ) {
313
            die $message;
314
        } else {
315
            warn $message;
316
        }
317
    };
318
309
    Koha::Exceptions::BadParameter->throw("Only one of 'include' and 'exclude' can be passed")
319
    Koha::Exceptions::BadParameter->throw("Only one of 'include' and 'exclude' can be passed")
310
        if ( $params->{exclude} && $params->{include} );
320
        if ( $params->{exclude} && $params->{include} );
311
321
Lines 336-342 sub InstallPlugins { Link Here
336
        }
346
        }
337
    }
347
    }
338
348
339
    foreach my $plugin_class (@plugin_classes) {
349
    PLUGINS: foreach my $plugin_class (@plugin_classes) {
340
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
350
        if ( can_load( modules => { $plugin_class => undef }, verbose => $verbose, nocache => 1 ) ) {
341
            next unless $plugin_class->isa('Koha::Plugins::Base');
351
            next unless $plugin_class->isa('Koha::Plugins::Base');
342
352
Lines 346-357 sub InstallPlugins { Link Here
346
            try {
356
            try {
347
                $plugin = $plugin_class->new( { enable_plugins => $self->{'enable_plugins'} } );
357
                $plugin = $plugin_class->new( { enable_plugins => $self->{'enable_plugins'} } );
348
            } catch {
358
            } catch {
349
                warn "$_";
359
                $fail->("$_");
350
                $failed_instantiation = 1;
360
                $failed_instantiation = 1;
351
            };
361
            };
352
362
353
            next if $failed_instantiation;
363
            next if $failed_instantiation;
354
364
365
            my $dependencies = $plugin->get_metadata->{requires};
366
            for my $module (keys %$dependencies) {
367
                my $version_requirement = $dependencies->{$module};
368
                unless (is_lax($version_requirement)) {
369
                    $fail->("The dependency of $plugin_class, $module has an invalid version requirement: " .
370
                         "$version_requirement. Skipping");
371
                    next PLUGINS;
372
                }
373
374
                # https://metacpan.org/pod/CPAN::Meta::Spec#Comparing-Version-Numbers
375
                unless ( eval "use $module $version_requirement (); 1" ) { ## no critic 'ProhibitStringyEval'
376
                    # empty string for '0' (any version)
377
                    my $version_description = $version_requirement ? " version $version_requirement" : '';
378
                    $fail->("Dependency of $plugin_class, $module$version_description is not installed. Skipping");
379
                    next PLUGINS;
380
                }
381
            }
382
355
            Koha::Plugins::Methods->search( { plugin_class => $plugin_class } )->delete();
383
            Koha::Plugins::Methods->search( { plugin_class => $plugin_class } )->delete();
356
384
357
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
385
            foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) {
(-)a/Koha/Plugins/Base.pm (-2 / +6 lines)
Lines 206-214 Missing POD for get_metadata. Link Here
206
sub get_metadata {
206
sub get_metadata {
207
    my ( $self, $args ) = @_;
207
    my ( $self, $args ) = @_;
208
208
209
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
210
    my $metadata = $self->{metadata};
209
    my $metadata = $self->{metadata};
211
    defined( $metadata->{$_} ) && utf8::decode( $metadata->{$_} ) for keys %$metadata;
210
    #FIXME: Why another encoding issue? For metadata containing non latin characters.
211
    for (keys %$metadata) {
212
        if (defined( $metadata->{$_} ) && ref $metadata->{$_} eq '') {
213
            utf8::decode( $metadata->{$_} );
214
        }
215
    }
212
    return $metadata;
216
    return $metadata;
213
}
217
}
214
218
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt (+4 lines)
Lines 55-60 Link Here
55
                            <li
55
                            <li
56
                                ><strong>Cannot install plugin from unknown source whilst plugins_restricted is enabled.<br /></strong
56
                                ><strong>Cannot install plugin from unknown source whilst plugins_restricted is enabled.<br /></strong
57
                            ></li>
57
                            ></li>
58
                        [% ELSIF ( ERROR.INSTALLFAIL ) %]
59
                            <li
60
                                ><strong>Plugin installation failed:<br />[% ERROR.INSTALLFAIL | html %]</strong
61
                            ></li>
58
                        [% ELSE %]
62
                        [% ELSE %]
59
                            <li
63
                            <li
60
                                ><strong>[% ERROR.CORERR | html %] An unknown error has occurred.<br />Please review the error log for more details.</strong></li
64
                                ><strong>[% ERROR.CORERR | html %] An unknown error has occurred.<br />Please review the error log for more details.</strong></li
(-)a/plugins/plugins-upload.pl (-2 / +9 lines)
Lines 23-28 use CGI qw ( -utf8 ); Link Here
23
use List::Util qw( any );
23
use List::Util qw( any );
24
use Mojo::UserAgent;
24
use Mojo::UserAgent;
25
use File::Temp;
25
use File::Temp;
26
use Try::Tiny;
26
27
27
use C4::Context;
28
use C4::Context;
28
use C4::Auth   qw( get_template_and_user );
29
use C4::Auth   qw( get_template_and_user );
Lines 129-135 if ( ( $op eq 'cud-Upload' ) && ( $uploadfile || $uploadlocation ) ) { Link Here
129
        # Install plugins; verbose not needed, we redirect to plugins-home.
130
        # Install plugins; verbose not needed, we redirect to plugins-home.
130
        # FIXME There is no good way to verify the install below; we need an
131
        # FIXME There is no good way to verify the install below; we need an
131
        # individual plugin install.
132
        # individual plugin install.
132
        Koha::Plugins->new->InstallPlugins( { verbose => 0 } );
133
        try {
134
            Koha::Plugins->new->InstallPlugins( { verbose => 0, fatal => 1 } );
135
        } catch {
136
            $errors{'INSTALLFAIL'} = $_;
137
            $template->param( ERRORS => [ \%errors ] );
138
            output_html_with_http_headers $input, $cookie, $template->output;
139
            exit;
140
        };
133
    }
141
    }
134
} elsif ( ( $op eq 'cud-Upload' ) && !$uploadfile && !$uploadlocation ) {
142
} elsif ( ( $op eq 'cud-Upload' ) && !$uploadfile && !$uploadlocation ) {
135
    warn "Problem uploading file or no file uploaded.";
143
    warn "Problem uploading file or no file uploaded.";
136
- 

Return to bug 41651