From 17fd09361a5f3da10e71ed74e73e6c20efadab73 Mon Sep 17 00:00:00 2001 From: Nick Clemens 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 --- Koha/Plugins.pm | 3 ++- misc/devel/install_plugins.pl | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 092c5e01b7..27fb40867f 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -161,13 +161,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..2b7ec3b233 100755 --- a/misc/devel/install_plugins.pl +++ b/misc/devel/install_plugins.pl @@ -37,16 +37,6 @@ unless ( C4::Context->config("enable_plugins") ) { exit 1; } - -my @existing_plugins = Koha::Plugins->new()->GetPlugins({ - all => 1, -}); -my $existing_plugins; -for my $existing_plugin (@existing_plugins) { - $existing_plugins->{ $existing_plugin->{metadata}->{name} } = - $existing_plugin->{metadata}->{version}; -} - my @installed_plugins = Koha::Plugins->new()->InstallPlugins(); unless (@installed_plugins) { my $plugins_dir = C4::Context->config("pluginsdir"); @@ -60,6 +50,16 @@ unless (@installed_plugins) { exit 0; } + +my @existing_plugins = Koha::Plugins->new()->GetPlugins({ + all => 1, +}); +my $existing_plugins; +for my $existing_plugin (@existing_plugins) { + $existing_plugins->{ $existing_plugin->{metadata}->{name} } = + $existing_plugin->{metadata}->{version}; +} + for my $installed_plugin (@installed_plugins) { if ( !exists( $existing_plugins->{ $installed_plugin->{metadata}->{name} } ) ) -- 2.11.0