Bug 29672: Clear cache of enabled plugins when a plugin's state change
authorJulian Maurice <julian.maurice@biblibre.com>
Mon, 6 Jun 2022 07:14:59 +0000 (09:14 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 3 Nov 2022 14:28:16 +0000 (11:28 -0300)
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Plugins.pm
Koha/Plugins/Base.pm

index 997d4a4..883b6c4 100644 (file)
@@ -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;
 }
 
index 487a3dc..8e547fb 100644 (file)
@@ -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