From 2dea127eb851e76d4280061799866fb8f4115bcb 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 Signed-off-by: Martin Renvoize --- C4/Letters.pm | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 26d866d7f04..1db40371776 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -214,8 +214,8 @@ sub GetLettersAvailableForALibrary { } return [ - map { $letters{$_} } - sort { $letters{$a}->{name} cmp $letters{$b}->{name} } + map { $letters{$_} } + sort { $letters{$a}->{name} cmp $letters{$b}->{name} } keys %letters ]; @@ -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; + }; } } @@ -1211,7 +1206,7 @@ sub GetQueuedMessages { my $params = shift; my $dbh = C4::Context->dbh(); - my $statement = << 'ENDSQL'; + my $statement = <<'ENDSQL'; SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, updated_on, failure_code, from_address, to_address, cc_address FROM message_queue ENDSQL -- 2.52.0