Bugzilla – Attachment 191651 Details for
Bug 41651
Allow plugins to specify additional dependencies
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41651: Allow plugins do specify dependencies, abort installation if unmet
Bug-41651-Allow-plugins-do-specify-dependencies-ab.patch (text/plain), 5.67 KB, created by
HKS3 Tadeusz Sośnierz
on 2026-01-19 14:47:18 UTC
(
hide
)
Description:
Bug 41651: Allow plugins do specify dependencies, abort installation if unmet
Filename:
MIME Type:
Creator:
HKS3 Tadeusz Sośnierz
Created:
2026-01-19 14:47:18 UTC
Size:
5.67 KB
patch
obsolete
>From 5194b061b1238c5953ac938b495aba7915e5d899 Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= > <tadeusz@sosnierz.com> >Date: Mon, 19 Jan 2026 15:39:38 +0100 >Subject: [PATCH] Bug 41651: Allow plugins do specify dependencies, abort > installation if unmet > >This unpacks uploaded plugin into a temporary directory where we check >the prerequisites/conflicts in standard CPAN ways, and only continue >with the installation if all the runtime requirements are met. >--- > Koha/Plugins.pm | 51 +++++++++++++++++++ > .../prog/en/modules/plugins/plugins-upload.tt | 4 ++ > plugins/plugins-upload.pl | 12 ++++- > 3 files changed, 65 insertions(+), 2 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index ee5ddde144..f3a9e849f2 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -21,7 +21,14 @@ use Modern::Perl; > > use Array::Utils qw( array_minus ); > use Class::Inspector; >+use CPAN::Meta; >+use CPAN::Meta::Check qw( verify_dependencies ); >+use File::Basename qw( fileparse ); >+use File::Copy qw( copy ); >+use File::Find qw( find ); >+use File::Path qw( make_path ); > use List::MoreUtils qw( any none ); >+use Module::CPANfile; > use Module::Load::Conditional qw( can_load ); > use Module::Load; > use Module::Pluggable search_path => ['Koha::Plugin'], >@@ -303,6 +310,27 @@ sub InstallPlugins { > my ( $self, $params ) = @_; > my $verbose = $params->{verbose} // $self->_verbose; > >+ if ( $params->{from} ) { >+ # We have "staged" plugin(s) passed in; check the dependencies, >+ # copy to the regular location if we're happy >+ $self->_check_dependencies($params->{from}); >+ >+ my $plugins_dir = C4::Context->config("pluginsdir"); >+ $plugins_dir = ref($plugins_dir) eq 'ARRAY' ? $plugins_dir->[0] : $plugins_dir; >+ >+ find({ >+ wanted => sub { >+ return unless -f $_; >+ my ($basename) = fileparse($_); >+ return if $basename =~ /^cpanfile|META/; >+ my $destdir = $File::Find::dir =~ s/^$params->{from}//r; >+ $destdir = "$plugins_dir/$destdir"; >+ make_path($destdir); >+ copy($File::Find::name, $destdir); >+ }, >+ }, $params->{from}); >+ } >+ > my @plugin_classes = $self->plugins(); > my @plugins; > >@@ -464,6 +492,29 @@ sub get_valuebuilders_installed { > return @valuebuilders; > } > >+sub _check_dependencies { >+ my ($self, $path) = @_; >+ >+ my $prereqs; >+ >+ if ( -f "$path/cpanfile" ) { >+ my $cpanfile = Module::CPANfile->load("$path/cpanfile"); >+ $prereqs = $cpanfile->prereqs; >+ } else { >+ my @metafiles = qw( META.json META.yml ); >+ for (@metafiles) { >+ if ( -f "$path/$_" ) { >+ $prereqs = CPAN::Meta->load_file("$path/$_"); >+ } >+ } >+ } >+ >+ return unless $prereqs; >+ >+ # Good for both file variants: per the docs, "$meta should be a CPAN::Meta::Prereqs or CPAN::Meta object" >+ die "$_\n" for verify_dependencies($prereqs, 'runtime', 'requires'); >+} >+ > 1; > __END__ > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt >index 63916b2d6f..5170463c32 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-upload.tt >@@ -55,6 +55,10 @@ > <li > ><strong>Cannot install plugin from unknown source whilst plugins_restricted is enabled.<br /></strong > ></li> >+ [% ELSIF ( ERROR.INSTALLFAIL ) %] >+ <li >+ ><strong>Plugin installation failed:<br />[% ERROR.INSTALLFAIL | html %]</strong >+ ></li> > [% ELSE %] > <li > ><strong>[% ERROR.CORERR | html %] An unknown error has occurred.<br />Please review the error log for more details.</strong></li >diff --git a/plugins/plugins-upload.pl b/plugins/plugins-upload.pl >index 8dd96030d8..3aaf6b3ee2 100755 >--- a/plugins/plugins-upload.pl >+++ b/plugins/plugins-upload.pl >@@ -23,6 +23,7 @@ use CGI qw ( -utf8 ); > use List::Util qw( any ); > use Mojo::UserAgent; > use File::Temp; >+use Try::Tiny; > > use C4::Context; > use C4::Auth qw( get_template_and_user ); >@@ -118,7 +119,7 @@ if ( ( $op eq 'cud-Upload' ) && ( $uploadfile || $uploadlocation ) ) { > } > > my $ae = Archive::Extract->new( archive => $tempfile, type => 'zip' ); >- unless ( $ae->extract( to => $plugins_dir ) ) { >+ unless ( $ae->extract( to => $dirname ) ) { > warn "ERROR: " . $ae->error; > $errors{'UZIPFAIL'} = $uploadfilename; > $template->param( ERRORS => [ \%errors ] ); >@@ -129,7 +130,14 @@ if ( ( $op eq 'cud-Upload' ) && ( $uploadfile || $uploadlocation ) ) { > # Install plugins; verbose not needed, we redirect to plugins-home. > # FIXME There is no good way to verify the install below; we need an > # individual plugin install. >- Koha::Plugins->new->InstallPlugins( { verbose => 0 } ); >+ try { >+ Koha::Plugins->new->InstallPlugins( { verbose => 0, from => $dirname } ); >+ } catch { >+ $errors{'INSTALLFAIL'} = $_; >+ $template->param( ERRORS => [ \%errors ] ); >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; >+ }; > } > } elsif ( ( $op eq 'cud-Upload' ) && !$uploadfile && !$uploadlocation ) { > warn "Problem uploading file or no file uploaded."; >-- >2.51.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41651
:
191567
|
191651
|
192087
|
192088
|
192089
|
192090