From f6052fbb7c20b18d83c6af5ac12f757473db4a11 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 26 Jul 2024 10:48:17 -0400 Subject: [PATCH] Bug 37495: Add ability to use metadata to filter plugins to run for plugins_nightly.pl It would be nice to be able to filter the plugins run by plugins nightly for development and testing, and for added flexibility as to when to run cronjob_nightly for different plugins if need be. Test Plan: 1) Apply this patch 2) Check the metadata for an installed plugin, copy the name or another metadata value. 3) Run plugins_nightly.pl with a filter that does not match e.g. plugins_nightly.pl -m name="No plugin has this name" 4) Note no plugins cronjob methods are run 5) Run plugins_nightly.pl with a filter that *does* match e.g. plugins_nightly.pl -m name="Example Kitchen-Sink Plugin" 6) Not only the matching plugin runs! 7) Run plugins_nightly with no filter e.g. plugins_nightly.pl 8) Note all plugins with nightly cronjobs are run! Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- misc/cronjobs/plugins_nightly.pl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/misc/cronjobs/plugins_nightly.pl b/misc/cronjobs/plugins_nightly.pl index f30633ff07..8c8cce7eac 100755 --- a/misc/cronjobs/plugins_nightly.pl +++ b/misc/cronjobs/plugins_nightly.pl @@ -2,7 +2,9 @@ use Modern::Perl; -use Try::Tiny qw( catch try ); +use Getopt::Long qw( GetOptions ); +use Pod::Usage qw( pod2usage ); +use Try::Tiny qw( catch try ); use C4::Context; use C4::Log qw( cronlogaction ); @@ -10,14 +12,23 @@ use Koha::Logger; use Koha::Plugins; use Koha::Script -cron; -my $command_line_options = join(" ",@ARGV); -cronlogaction({ info => $command_line_options }); +my $command_line_options = join( " ", @ARGV ); +cronlogaction( { info => $command_line_options } ); + +my $metadata; +my $help; +GetOptions( + 'm|metadata=s%' => \$metadata, + 'h|help' => \$help, +) or pod2usage(2); +pod2usage(1) if $help; my $logger = Koha::Logger->get(); if ( C4::Context->config("enable_plugins") ) { my @plugins = Koha::Plugins->new->GetPlugins( { - method => 'cronjob_nightly', + method => 'cronjob_nightly', + metadata => $metadata, } ); @@ -27,8 +38,7 @@ if ( C4::Context->config("enable_plugins") ) { cronlogaction( { info => "$plugin_name" } ); $plugin->cronjob_nightly(); cronlogaction( { action => "End", info => "$plugin_name COMPLETED" } ); - } - catch { + } catch { cronlogaction( { action => "Error", info => "$plugin_name FAILED with error: $_" } ); warn "$_"; $logger->warn("$_"); @@ -36,7 +46,7 @@ if ( C4::Context->config("enable_plugins") ) { } } -cronlogaction({ action => 'End', info => "COMPLETED" }); +cronlogaction( { action => 'End', info => "COMPLETED" } ); =head1 NAME @@ -44,7 +54,11 @@ plugins_nightly.pl - Run nightly tasks specified by plugins =head1 SYNOPSIS -plugins_nightly.pl +plugins_nightly.pl [-m|--metadata key=value] + +-m --metadata, repeatable, specify a metadata key and value to run only plugins + with nightly_cronjob methods and matching metadata. + e.g. plugins_nightly.pl -m name="My Awesome Plugin" =head1 AUTHOR -- 2.39.5