From 8e1354bd3288b069b0e040b6fdd371fda1c09fc0 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index a3c47006b5..08eb6995e6 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -33,6 +33,7 @@ use C4::Output; use Koha::Cache::Memory::Lite; use Koha::Exceptions::Plugin; use Koha::Plugins::Methods; +use Module::Refresh; use constant ENABLED_PLUGINS_CACHE_KEY => 'enabled_plugins'; @@ -231,11 +232,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