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

(-)a/Koha/Plugins.pm (+51 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use Array::Utils qw( array_minus );
22
use Array::Utils qw( array_minus );
23
use Class::Inspector;
23
use Class::Inspector;
24
use CPAN::Meta;
25
use CPAN::Meta::Check qw( verify_dependencies );
26
use File::Basename qw( fileparse );
27
use File::Copy qw( copy );
28
use File::Find qw( find );
29
use File::Path qw( make_path );
24
use List::MoreUtils           qw( any none );
30
use List::MoreUtils           qw( any none );
31
use Module::CPANfile;
25
use Module::Load::Conditional qw( can_load );
32
use Module::Load::Conditional qw( can_load );
26
use Module::Load;
33
use Module::Load;
27
use Module::Pluggable search_path => ['Koha::Plugin'],
34
use Module::Pluggable search_path => ['Koha::Plugin'],
Lines 303-308 sub InstallPlugins { Link Here
303
    my ( $self, $params ) = @_;
310
    my ( $self, $params ) = @_;
304
    my $verbose = $params->{verbose} // $self->_verbose;
311
    my $verbose = $params->{verbose} // $self->_verbose;
305
312
313
    if ( $params->{from} ) {
314
        # We have "staged" plugin(s) passed in; check the dependencies,
315
        # copy to the regular location if we're happy
316
        $self->_check_dependencies($params->{from});
317
318
        my $plugins_dir = C4::Context->config("pluginsdir");
319
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
320
321
        find({
322
            wanted => sub {
323
                return unless -f $_;
324
                my ($basename) = fileparse($_);
325
                return if $basename =~ /^cpanfile|META/;
326
                my $destdir = $File::Find::dir =~ s/^$params->{from}//r;
327
                $destdir = "$plugins_dir/$destdir";
328
                make_path($destdir);
329
                copy($File::Find::name, $destdir);
330
            },
331
        }, $params->{from});
332
    }
333
306
    my @plugin_classes = $self->plugins();
334
    my @plugin_classes = $self->plugins();
307
    my @plugins;
335
    my @plugins;
308
336
Lines 464-469 sub get_valuebuilders_installed { Link Here
464
    return @valuebuilders;
492
    return @valuebuilders;
465
}
493
}
466
494
495
sub _check_dependencies {
496
    my ($self, $path) = @_;
497
498
    my $prereqs;
499
500
    if ( -f "$path/cpanfile" ) {
501
        my $cpanfile = Module::CPANfile->load("$path/cpanfile");
502
        $prereqs = $cpanfile->prereqs;
503
    } else {
504
        my @metafiles = qw( META.json META.yml );
505
        for (@metafiles) {
506
            if ( -f "$path/$_" ) {
507
                $prereqs = CPAN::Meta->load_file("$path/$_");
508
            }
509
        }
510
    }
511
512
    return unless $prereqs;
513
514
    # Good for both file variants: per the docs, "$meta should be a CPAN::Meta::Prereqs or CPAN::Meta object"
515
    die "$_\n" for verify_dependencies($prereqs, 'runtime', 'requires');
516
}
517
467
1;
518
1;
468
__END__
519
__END__
469
520
(-)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 (-3 / +10 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 118-124 if ( ( $op eq 'cud-Upload' ) && ( $uploadfile || $uploadlocation ) ) { Link Here
118
        }
119
        }
119
120
120
        my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
121
        my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' );
121
        unless ( $ae->extract( to => $plugins_dir ) ) {
122
        unless ( $ae->extract( to => $dirname ) ) {
122
            warn "ERROR: " . $ae->error;
123
            warn "ERROR: " . $ae->error;
123
            $errors{'UZIPFAIL'} = $uploadfilename;
124
            $errors{'UZIPFAIL'} = $uploadfilename;
124
            $template->param( ERRORS => [ \%errors ] );
125
            $template->param( ERRORS => [ \%errors ] );
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, from => $dirname } );
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