Bugzilla – Attachment 111345 Details for
Bug 25549
Broken plugins should not break Koha (Install plugin script/method should highlight broken plugins)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25549: Remove plugin methods for broken plugins
Bug-25549-Remove-plugin-methods-for-broken-plugins.patch (text/plain), 4.68 KB, created by
Martin Renvoize (ashimema)
on 2020-10-07 15:58:15 UTC
(
hide
)
Description:
Bug 25549: Remove plugin methods for broken plugins
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-10-07 15:58:15 UTC
Size:
4.68 KB
patch
obsolete
>From 8db7a7bb16ef2a644faeed42973828b4dd709adf Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 20 May 2020 11:12:12 +0000 >Subject: [PATCH] Bug 25549: Remove plugin methods for broken plugins > >To test: > 1 - Enable plugins in the koha-conf > 2 - Install the kitchen sink plugin > 3 - Your staff client should be orange now :-) > 4 - edit the plugin module > /var/lib/koha/kohadev/plugins/Koha/Plugin/Com/ByWaterSolutions/KitchenSink.pm > 5 - Add a line to break compilation, like: > this won't compile > 6 - Restart all > 7 - Your koha is now broken > 8 - kshell > 9 - perl misc/devel/install_plugins.pl >10 - Restart all >11 - Koha remains broken >12 - Apply patch >13 - kshell >14 - perl misc/devel/install_plugins.pl >15 - Koha now works! >16 - Koha is not orange because the plugin methods are removed > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Plugins.pm | 40 +++++++++++++++++++---------------- > misc/devel/install_plugins.pl | 10 ++++++--- > 2 files changed, 29 insertions(+), 21 deletions(-) > >diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm >index 092c5e01b7..77758fba68 100644 >--- a/Koha/Plugins.pm >+++ b/Koha/Plugins.pm >@@ -118,24 +118,27 @@ sub GetPlugins { > # Loop through all plugins that implement at least a method > while ( my $plugin_class = $plugin_classes->next ) { > >- load $plugin_class; >- my $plugin = $plugin_class->new({ >- enable_plugins => $self->{'enable_plugins'} >- # loads even if plugins are disabled >- # FIXME: is this for testing without bothering to mock config? >- }); >- >- next unless $plugin->is_enabled or >- defined($params->{all}) && $params->{all}; >- >- # filter the plugin out by metadata >- my $plugin_metadata = $plugin->get_metadata; >- next >- if $plugin_metadata >- and %$req_metadata >- and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; >+ if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { >+ my $plugin = $plugin_class->new({ >+ enable_plugins => $self->{'enable_plugins'} >+ # loads even if plugins are disabled >+ # FIXME: is this for testing without bothering to mock config? >+ }); >+ >+ next unless $plugin->is_enabled or >+ defined($params->{all}) && $params->{all}; >+ >+ # filter the plugin out by metadata >+ my $plugin_metadata = $plugin->get_metadata; >+ next >+ if $plugin_metadata >+ and %$req_metadata >+ and any { !$plugin_metadata->{$_} || $plugin_metadata->{$_} ne $req_metadata->{$_} } keys %$req_metadata; > >- push @plugins, $plugin; >+ push @plugins, $plugin; >+ } elsif ( defined($params->{errors}) && $params->{errors} ){ >+ push @plugins, { error => 'cannot_load', name => $plugin_class }; >+ } > > } > >@@ -161,13 +164,14 @@ sub InstallPlugins { > my @plugin_classes = $self->plugins(); > my @plugins; > >+ # If we can reload the plugin we will add the methods back, if not they should be removed >+ Koha::Plugins::Methods->search()->delete(); > foreach my $plugin_class (@plugin_classes) { > if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { > next unless $plugin_class->isa('Koha::Plugins::Base'); > > my $plugin = $plugin_class->new({ enable_plugins => $self->{'enable_plugins'} }); > >- Koha::Plugins::Methods->search({ plugin_class => $plugin_class })->delete(); > > foreach my $method ( @{ Class::Inspector->methods( $plugin_class, 'public' ) } ) { > Koha::Plugins::Method->new( >diff --git a/misc/devel/install_plugins.pl b/misc/devel/install_plugins.pl >index 073ddbbb1c..0177d733b4 100755 >--- a/misc/devel/install_plugins.pl >+++ b/misc/devel/install_plugins.pl >@@ -37,14 +37,18 @@ unless ( C4::Context->config("enable_plugins") ) { > exit 1; > } > >- > my @existing_plugins = Koha::Plugins->new()->GetPlugins({ > all => 1, >+ errors => 1, > }); > my $existing_plugins; > for my $existing_plugin (@existing_plugins) { >- $existing_plugins->{ $existing_plugin->{metadata}->{name} } = >- $existing_plugin->{metadata}->{version}; >+ if( defined $existing_plugin->{error} ){ >+ print "Could not load: ".$existing_plugin->{name}." any associated method will be removed\n"; >+ } else { >+ $existing_plugins->{ $existing_plugin->{metadata}->{name} } = >+ $existing_plugin->{metadata}->{version}; >+ } > } > > my @installed_plugins = Koha::Plugins->new()->InstallPlugins(); >-- >2.20.1
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 25549
:
105143
|
110896
|
111324
|
111335
|
111345
|
111346
|
111375
|
111376
|
111816
|
111817