From a509c33801ec4ed977f07c1388927e1336142f35 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 6 Jun 2022 09:14:59 +0200 Subject: [PATCH] Bug 29672: Clear cache of enabled plugins when a plugin's state change Signed-off-by: David Nind --- Koha/Plugins.pm | 10 +++++++--- Koha/Plugins/Base.pm | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index 997d4a48b7..883b6c4f29 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -34,6 +34,8 @@ use Koha::Cache::Memory::Lite; use Koha::Exceptions::Plugin; use Koha::Plugins::Methods; +use constant ENABLED_PLUGINS_CACHE_KEY => 'enabled_plugins'; + BEGIN { my $pluginsdir = C4::Context->config("pluginsdir"); my @pluginsdir = ref($pluginsdir) eq 'ARRAY' ? @$pluginsdir : $pluginsdir; @@ -103,8 +105,7 @@ sub get_enabled_plugins { return unless C4::Context->config('enable_plugins'); - my $cache_key = 'enabled_plugins'; - my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache($cache_key); + my $enabled_plugins = Koha::Cache::Memory::Lite->get_from_cache(ENABLED_PLUGINS_CACHE_KEY); unless ($enabled_plugins) { $enabled_plugins = []; my $rs = Koha::Database->schema->resultset('PluginData'); @@ -124,7 +125,7 @@ sub get_enabled_plugins { push @$enabled_plugins, $plugin; } - Koha::Cache::Memory::Lite->set_in_cache($cache_key, $enabled_plugins); + Koha::Cache::Memory::Lite->set_in_cache(ENABLED_PLUGINS_CACHE_KEY, $enabled_plugins); } return @$enabled_plugins; @@ -258,6 +259,9 @@ sub InstallPlugins { warn $error unless $error =~ m|^Could not find or check module '$plugin_class'|; } } + + Koha::Cache::Memory::Lite->clear_from_cache(ENABLED_PLUGINS_CACHE_KEY); + return @plugins; } diff --git a/Koha/Plugins/Base.pm b/Koha/Plugins/Base.pm index 487a3dc5e2..8e547fba0d 100644 --- a/Koha/Plugins/Base.pm +++ b/Koha/Plugins/Base.pm @@ -29,6 +29,7 @@ use C4::Context; use C4::Output qw( output_with_http_headers ); use Koha::Exceptions::Plugin; +use Koha::Cache::Memory::Lite; =head1 NAME @@ -104,6 +105,10 @@ sub store_data { foreach my $key ( keys %$data ) { $sth->execute( $self->{'class'}, $key, $data->{$key} ); } + + if (exists $data->{__ENABLED__}) { + Koha::Cache::Memory::Lite->clear_from_cache(Koha::Plugins->ENABLED_PLUGINS_CACHE_KEY); + } } =head2 retrieve_data -- 2.30.2