From 9319c8879fdd796d7293beca8f5017a4024bdbd9 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 22 May 2020 12:29:11 +0200 Subject: [PATCH] Bug 24031: Add safety checks in Koha::Plugins::call - Check that the plugin has the method before calling it - Call the method in an eval block to prevent fatal errors Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Plugins.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Koha/Plugins.pm b/Koha/Plugins.pm index ae2f2c5c22..41974e54ac 100644 --- a/Koha/Plugins.pm +++ b/Koha/Plugins.pm @@ -66,8 +66,14 @@ sub call { if (C4::Context->config('enable_plugins')) { my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method }); my @responses; + @plugins = grep { $_->can($method) } @plugins; foreach my $plugin (@plugins) { - my $response = $plugin->$method(@args); + my $response = eval { $plugin->$method(@args) }; + if ($@) { + warn sprintf("Plugin error (%s): %s", $plugin->get_metadata->{name}, $@); + next; + } + push @responses, $response; } -- 2.39.5