Bug 42098: EDIFACT edi_cron.pl runs disabled plugins due to bug in Koha::Plugins::Handler::run

It appears that edi_cron.pl will run disabled EDI plugins. It uses Koha::Plugins::Handler::run that does not check if the plugins is gets are disabled.

Koha::Plugins::Handler::run needs to be fixed to not run disabled plugins.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/Koha/Plugins/Plugins.t

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
(cherry picked from commit 42472f6b34)
Signed-off-by: Chloé Zermatten <chloe.zermatten@openfifth.co.uk>
This commit is contained in:
Kyle M Hall 2026-03-16 08:05:49 -04:00 committed by Chloé Zermatten
parent b958646dac
commit 6512e40bb7
No known key found for this signature in database
2 changed files with 47 additions and 3 deletions

View File

@ -19,8 +19,9 @@ package Koha::Plugins::Handler;
use Modern::Perl;
use Array::Utils qw( array_minus );
use File::Path qw( remove_tree );
use Array::Utils qw( array_minus );
use File::Path qw( remove_tree );
use List::MoreUtils qw( any );
use Module::Load qw( load );
@ -69,6 +70,10 @@ sub run {
if ($has_method) {
load $plugin_class;
my $plugin = $plugin_class->new( { cgi => $cgi, enable_plugins => $args->{'enable_plugins'} } );
my @management_methods = qw( enable disable install uninstall upgrade configure );
return unless ( $plugin->is_enabled || any { $plugin_method eq $_ } @management_methods );
return $plugin->$plugin_method($params);
} else {
warn "Plugin does not have method $plugin_method";

View File

@ -26,7 +26,7 @@ use List::MoreUtils qw(none);
use Module::Load::Conditional qw(can_load);
use Test::MockModule;
use Test::NoWarnings;
use Test::More tests => 20;
use Test::More tests => 21;
use Test::Warn;
use Test::Exception;
@ -414,6 +414,45 @@ subtest 'Koha::Plugin::Test' => sub {
$schema->storage->txn_rollback;
};
subtest 'Handler::run() skips disabled plugins' => sub {
plan tests => 5;
$schema->storage->txn_begin;
# Temporarily remove any installed plugins data
Koha::Plugins->RemovePlugins( { destructive => 1 } );
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
my $plugins = Koha::Plugins->new( { enable_plugins => 1 } );
my @plugins;
warning_is { @plugins = $plugins->InstallPlugins; } undef;
# Enabled plugin runs successfully
my $plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
$plugin->enable;
is(
Koha::Plugins::Handler->run( { class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 } ),
"Koha::Plugin::Test::report", 'Handler::run() executes enabled plugin'
);
# Disabled plugin is skipped
$plugin->disable;
is(
Koha::Plugins::Handler->run( { class => "Koha::Plugin::Test", method => 'report', enable_plugins => 1 } ),
undef, 'Handler::run() returns undef for disabled plugin'
);
# Management methods still work on disabled plugins
$plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
ok( !$plugin->is_enabled, 'Plugin is still disabled after Handler::run skipped it' );
Koha::Plugins::Handler->run( { class => "Koha::Plugin::Test", method => 'enable', enable_plugins => 1 } );
$plugin = Koha::Plugin::Test->new( { enable_plugins => 1, cgi => CGI->new } );
ok( $plugin->is_enabled, 'Handler::run() allows enable method on disabled plugin' );
$schema->storage->txn_rollback;
};
subtest 'RemovePlugins' => sub {
plan tests => 3;