From ece2d64e76ffa7770b7e835b4d0c26da16a273bb Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 3 Jun 2026 16:15:25 +0100 Subject: [PATCH] Bug 42714: (QA follow-up) Limit auto-logging to -cron scripts The INIT/END blocks in Koha::Script fire for every consumer of the module, including non-cron admin and migration tools. Logging those as CRONJOBS when CronjobLog is enabled would pollute the action log with entries for tools that are not scheduled jobs. Introduce a package-level $_cron flag that is set by import() when the -cron argument is passed (import() runs at compile time, before INIT blocks execute, so the flag is in the correct state when INIT fires). Guard both the INIT and END blocks behind this flag so only scripts that explicitly declare themselves as cron scripts receive automatic logging. Also update the import() POD to document the auto-logging behaviour. Signed-off-by: Pedro Amorim --- Koha/Script.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Koha/Script.pm b/Koha/Script.pm index 347824d61f..ce4346e0b0 100644 --- a/Koha/Script.pm +++ b/Koha/Script.pm @@ -43,13 +43,17 @@ use C4::Log qw( cronlogaction ); use Koha::Exceptions; use Koha::Exception; +our $_cron = 0; + INIT { - my $command_line_options = join( " ", @ARGV ); - cronlogaction( { info => $command_line_options } ); + if ($_cron) { + my $command_line_options = join( " ", @ARGV ); + cronlogaction( { info => $command_line_options } ); + } } END { - cronlogaction( { action => 'End', info => "COMPLETED" } ); + cronlogaction( { action => 'End', info => "COMPLETED" } ) if $_cron; } =head2 import @@ -58,6 +62,9 @@ END { use Koha::Script -cron; Sets the interface and userenv appropriately based on the flags passed. +When the C<-cron> flag is used the script is also automatically logged to +the CRONJOBS action log (start and end) when the C system +preference is enabled. =cut @@ -66,6 +73,7 @@ sub import { my @flags = @_; if ( ( $flags[0] || '' ) eq '-cron' ) { + $_cron = 1; # Set userenv C4::Context->set_userenv(