Bugzilla – Attachment 160036 Details for
Bug 35603
Add plugin feature to allow plugins to warn if any external library modules needed are missing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35603: Add plugin feature to allow plugins to warn if any external library modules needed are missing
Bug-35603-Add-plugin-feature-to-allow-plugins-to-w.patch (text/plain), 5.02 KB, created by
Martin Renvoize (ashimema)
on 2023-12-19 16:30:25 UTC
(
hide
)
Description:
Bug 35603: Add plugin feature to allow plugins to warn if any external library modules needed are missing
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-12-19 16:30:25 UTC
Size:
5.02 KB
patch
obsolete
>From a2726b2bf1189fa4b4abc73aef75f19ae0776f9c Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 19 Dec 2023 09:22:31 -0500 >Subject: [PATCH] Bug 35603: Add plugin feature to allow plugins to warn if any > external library modules needed are missing > >Some plugins require extra modules not included with Koha, but there is no simple way to let a user know when installing a plugin. > >This patch allows a new metadata to be added that is a list of hashes >with the key module. The hash is used for future expansion to allow new >critera to be added such as minimum and maximum module version. > >Test Plan: >1) Install any plugin >2) In the plugin metadata, add the following key: >libs => [ { module => 'Business::Barcode::EAN13' } ], >3) Apply this patch >4) Restart all the things! >5) Browse to plugins-home.pl, note the error listing the missing module >6) Install Business::Barcode::EAN13 from cpan >7) Reload the page >8) Note the error is gone! > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Plugins.pm | 15 ++++++++++++++- > Koha/Plugins/Base.pm | 2 +- > .../prog/en/modules/plugins/plugins-home.tt | 16 ++++++++++++++-- > 3 files changed, 29 insertions(+), 4 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 4bbfc0c2dc9..d5972ae6b91 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -22,7 +22,7 @@ use Modern::Perl; > use Array::Utils qw( array_minus ); > use Class::Inspector; > use List::MoreUtils qw( any ); >-use Module::Load::Conditional qw( can_load ); >+use Module::Load::Conditional qw( can_load check_install ); > use Module::Load; > use Module::Pluggable search_path => ['Koha::Plugin'], except => qr/::Edifact(|::Line|::Message|::Order|::Segment|::Transport)$/; > use Try::Tiny; >@@ -225,6 +225,19 @@ sub GetPlugins { > next unless $plugin->is_enabled or > defined($params->{all}) && $params->{all}; > >+ # Check metadata for required perl modules >+ my $libs = $plugin->get_metadata->{libs}; >+ my @missing_libs; >+ foreach my $lib (@$libs) { >+ unless ( check_install( module => $lib->{module} ) ) { >+ push( @missing_libs, $lib ); >+ } >+ } >+ if (@missing_libs) { >+ push @plugins, { error => 'missing_libs', name => $plugin_class, libs => \@missing_libs }; >+ next; >+ } >+ > # filter the plugin out by metadata > my $plugin_metadata = $plugin->get_metadata; > next >diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm >index 8e547fba0d6..1b3d0f0c9ef 100644 >--- a/Koha/Plugins/Base.pm >+++ b/Koha/Plugins/Base.pm >@@ -196,7 +196,7 @@ sub get_metadata { > > #FIXME: Why another encoding issue? For metadata containing non latin characters. > my $metadata = $self->{metadata}; >- defined($metadata->{$_}) && utf8::decode($metadata->{$_}) for keys %$metadata; >+ defined($metadata->{$_}) && !ref $metadata->{$_} && utf8::decode($metadata->{$_}) for keys %$metadata; > return $metadata; > } > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >index ce9d9c5ce20..318de4571b9 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/plugins/plugins-home.tt >@@ -154,10 +154,22 @@ > <span class="label label-warning">ERRORS</span> > </td> > [% IF ( CAN_user_plugins_configure || CAN_user_plugins_manage || CAN_user_plugins_report || CAN_user_plugins_tool ) %] >- <td colspan="7">Error found whilst attempting to load plugin</td> >+ <td colspan="7"> > [% ELSE %] >- <td colspan="6">Error found whilst attempting to load plugin</td> >+ <td colspan="6"> > [% END %] >+ >+ [% IF plugin.error == 'missing_libs' %] >+ This plugin requires the following missing modules to be installed: >+ <ul> >+ [% FOREACH l IN plugin.libs %] >+ <li>[% l.module | html %]</li> >+ [% END %] >+ </ul> >+ [% ELSE %] >+ Error found whilst attempting to load plugin >+ [% END %] >+ </td> > </tr> > [% ELSE %] > <tr> >-- >2.43.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 35603
:
160008
|
160036
|
160037
|
165975