From 6c15656fc0b7d7ccb5817946e0be783a5e1bcd7a 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! --- misc/cronjobs/plugins_nightly.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/plugins_nightly.pl b/misc/cronjobs/plugins_nightly.pl index f30633ff074..088b284ecc8 100755 --- a/misc/cronjobs/plugins_nightly.pl +++ b/misc/cronjobs/plugins_nightly.pl @@ -2,6 +2,8 @@ use Modern::Perl; +use Getopt::Long qw( GetOptions ); +use Pod::Usage qw( pod2usage ); use Try::Tiny qw( catch try ); use C4::Context; @@ -13,11 +15,20 @@ use Koha::Script -cron; 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, } ); @@ -44,7 +55,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.30.2