From c20e806352fb290b0c07db86eddb539e9e948573 Mon Sep 17 00:00:00 2001 From: Olivier Hubert Date: Mon, 24 Oct 2022 10:44:42 -0400 Subject: [PATCH] Bug 31074: Reload a plugin's module before installation When using Plack, memcached or another caching mechanism, a plugin's old version is retained in the cache, even when uninstalled. If the plugin is then reinstalled, the old version is used, no matter the version installed. To prevent this, the plugin's module is reloaded every time it is installed. To test: 1) Install a plugin, like the kitchen sink. https://github.com/bywatersolutions/dev-koha-plugin-kitchen-sink/releases 2) Modify the .kpz and in KitchenSink.pm, change MINIMUN_VERSION. 3) Uninstall the plugin. 4) Install the new version. 5) The Minimum Koha version column still lists the old version. 6) Apply patch. 7) Repeat steps 1 through 4. 8) Observe that the Minimum Koha version column lists the correct version. 9) Sign off. --- Koha/Plugins.pm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index f7b716638d..59a83b3c0e 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -33,6 +33,8 @@ use C4::Output; use Koha::Exceptions::Plugin; use Koha::Plugins::Methods; +use Module::Refresh; + BEGIN { my $pluginsdir = C4::Context->config("pluginsdir"); my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; @@ -187,11 +189,22 @@ sub InstallPlugins { my @plugin_classes = $self->plugins(); my @plugins; + my $refresher = Module::Refresh->new; foreach my $plugin_class (@plugin_classes) { if ( can_load( modules => { $plugin_class => undef }, nocache => 1 ) ) { next unless $plugin_class->isa('Koha::Plugins::Base'); + # If using Plack or memcached and reinstalling a Plugin that existed previously, the module needs to be refreshed. + my $module_name = ($plugin_class =~ s|::|/|gr) . '.pm'; + + try { + $refresher->refresh_module($module_name); + } + catch { + warn "$_"; + } + my $plugin; my $failed_instantiation; -- 2.34.1