From c9c1199fbc269209823068fe544bb167e1b1e061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Thu, 22 Jan 2026 16:16:42 -0300 Subject: [PATCH] Bug 41684: Make `notices_content` hook be used with `get_enabled_plugins()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch makes the plugin hook load plugins using `get_enabled_plugins()`. This has the immediate effect of using the already cached plugin objects without reinstantiating them. This way transactions don't get broken for schema reloads. Also, only enabled plugins are loaded/attempted to be loaded. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Plugins/Notices_content_hook.t => SUCCESS: Tests pass 2. Apply this patch 3. Repeat 1 => SUCCESS: Tests still pass: fundamental behavior remains unchanged. 4. Sign off :-D Signed-off-by: Tomás Cohen Arazi Signed-off-by: David Nind --- C4/Letters.pm | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 26d866d7f0..6f171d3802 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -620,24 +620,19 @@ sub GetPreparedLetter { } # add plugin-generated objects - if ( C4::Context->config("enable_plugins") ) { - my @plugins = Koha::Plugins->new->GetPlugins( - { - method => 'notices_content', - } - ); + my @plugins = Koha::Plugins->get_enabled_plugins(); + @plugins = grep { $_->can('notices_content') } @plugins; - foreach my $plugin (@plugins) { - my $namespace = $plugin->get_metadata()->{namespace}; - if ($namespace) { - try { - if ( my $content = $plugin->notices_content( \%params ) ) { - $objects->{plugin_content}->{$namespace} = $content; - } - } catch { - next; - }; - } + foreach my $plugin (@plugins) { + my $namespace = $plugin->get_metadata()->{namespace}; + if ($namespace) { + try { + if ( my $content = $plugin->notices_content( \%params ) ) { + $objects->{plugin_content}->{$namespace} = $content; + } + } catch { + next; + }; } } -- 2.39.5