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

(-)a/Koha/Plugins.pm (-6 / +16 lines)
Lines 295-300 Parameters: Link Here
295
295
296
=item B<exclude>: A list of class names to exclude from the process.
296
=item B<exclude>: A list of class names to exclude from the process.
297
297
298
=item B<from>: A staging directory path containing unpacked plugin files.
299
When provided, the method will first check plugin dependencies (from cpanfile
300
or META.json/META.yml) and only copy the files to the plugins directory if
301
all runtime requirements are met. Dies if dependencies are unmet or file
302
copying fails.
303
298
=item B<include>: A list of class names to limit the process to.
304
=item B<include>: A list of class names to limit the process to.
299
305
300
=item B<verbose>: Print useful information.
306
=item B<verbose>: Print useful information.
Lines 314-320 sub InstallPlugins { Link Here
314
320
315
        # We have "staged" plugin(s) passed in; check the dependencies,
321
        # We have "staged" plugin(s) passed in; check the dependencies,
316
        # copy to the regular location if we're happy
322
        # copy to the regular location if we're happy
317
        $self->_check_dependencies( $params->{from} );
323
        my $staging_dir = $params->{from};
324
        $staging_dir =~ s{/+$}{};    # Remove trailing slashes for clean path handling
325
326
        $self->_check_dependencies($staging_dir);
318
327
319
        my $plugins_dir = C4::Context->config("pluginsdir");
328
        my $plugins_dir = C4::Context->config("pluginsdir");
320
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
329
        $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir;
Lines 326-340 sub InstallPlugins { Link Here
326
                    return unless -f $_;
335
                    return unless -f $_;
327
                    my ($basename) = fileparse($_);
336
                    my ($basename) = fileparse($_);
328
                    return if $basename =~ /^(cpanfile|META\.(json|yml))$/;
337
                    return if $basename =~ /^(cpanfile|META\.(json|yml))$/;
329
                    my $destdir = $File::Find::dir =~ s/^\Q$params->{from}\E//r;
338
                    my $destdir = $File::Find::dir =~ s/^\Q$staging_dir\E//r;
330
                    $destdir = "$plugins_dir/$destdir";
339
                    $destdir = "$plugins_dir$destdir";
331
                    make_path($destdir);
340
                    make_path($destdir);
332
                    unless ( copy( $File::Find::name, $destdir ) ) {
341
                    unless ( copy( $File::Find::name, $destdir ) ) {
333
                        push @copy_errors, "Failed to copy $File::Find::name to $destdir: $!";
342
                        push @copy_errors, "Failed to copy $File::Find::name to $destdir: $!";
334
                    }
343
                    }
335
                },
344
                },
336
            },
345
            },
337
            $params->{from}
346
            $staging_dir
338
        );
347
        );
339
        die join( "\n", @copy_errors ) . "\n" if @copy_errors;
348
        die join( "\n", @copy_errors ) . "\n" if @copy_errors;
340
    }
349
    }
Lines 513-518 sub _check_dependencies { Link Here
513
        for (@metafiles) {
522
        for (@metafiles) {
514
            if ( -f "$path/$_" ) {
523
            if ( -f "$path/$_" ) {
515
                $prereqs = CPAN::Meta->load_file("$path/$_");
524
                $prereqs = CPAN::Meta->load_file("$path/$_");
525
                last;
516
            }
526
            }
517
        }
527
        }
518
    }
528
    }
Lines 520-526 sub _check_dependencies { Link Here
520
    return unless $prereqs;
530
    return unless $prereqs;
521
531
522
    # Good for both file variants: per the docs, "$meta should be a CPAN::Meta::Prereqs or CPAN::Meta object"
532
    # Good for both file variants: per the docs, "$meta should be a CPAN::Meta::Prereqs or CPAN::Meta object"
523
    die "$_\n" for verify_dependencies( $prereqs, 'runtime', 'requires' );
533
    my @unmet = verify_dependencies( $prereqs, 'runtime', 'requires' );
534
    die "Unmet dependencies:\n" . join( "\n", map { "  - $_" } @unmet ) . "\n" if @unmet;
524
}
535
}
525
536
526
1;
537
1;
527
- 

Return to bug 41651