From ecd056b21d7ee70e048b396f189d4e2c586c57fd Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 28 May 2026 17:19:59 +0000 Subject: [PATCH] Bug 42714: Add automatic cronlogaction logging to Koha::Script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add INIT and END blocks to Koha::Script that automatically call cronlogaction on script start (with command line options) and completion. This removes the need for scripts to manually handle cron log entries. This will mean that any script importing Koha::Script will be logged, but I think the addition is beneficial. To test: 1 - Ensure CronjobLog is enabled 2 - perl misc/cronjobs/fines.pl --test 3 - Confirm start and end are logged in action logs: http://localhost:8081/cgi-bin/koha/tools/viewlog.pl?src=&user=&modules=CRONJOBS&actions=&object=&info=&interfaces=&from=&to=&output=screen&basename=Export&report_name=&do_it=1 4 - Apply patch 5 - Repeat 2 6 - Reload the logs, confirm the new logs look the same 7 - Sign off Signed-off-by: Tomás Cohen Arazi Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- Koha/Script.pm | 19 +++++++++++++++++++ misc/cronjobs/fines.pl | 4 ---- misc/link_bibs_to_authorities.pl | 2 -- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Koha/Script.pm b/Koha/Script.pm index 0d46156d53..347824d61f 100644 --- a/Koha/Script.pm +++ b/Koha/Script.pm @@ -39,9 +39,28 @@ use File::Basename qw( fileparse ); use Fcntl qw( LOCK_EX LOCK_NB ); use C4::Context; +use C4::Log qw( cronlogaction ); use Koha::Exceptions; use Koha::Exception; +INIT { + my $command_line_options = join( " ", @ARGV ); + cronlogaction( { info => $command_line_options } ); +} + +END { + cronlogaction( { action => 'End', info => "COMPLETED" } ); +} + +=head2 import + + use Koha::Script; + use Koha::Script -cron; + +Sets the interface and userenv appropriately based on the flags passed. + +=cut + sub import { my $class = shift; my @flags = @_; diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 4765eff3cd..e3232f24dd 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -50,8 +50,6 @@ my $log; my $maxdays; my $verify_issue; -my $command_line_options = join( " ", @ARGV ); -cronlogaction( { info => $command_line_options } ); GetOptions( 'h|help' => \$help, @@ -212,8 +210,6 @@ Number of Overdue Items: EOM } -cronlogaction( { action => 'End', info => "COMPLETED" } ); - sub set_holiday { my ( $branch, $dt ) = @_; diff --git a/misc/link_bibs_to_authorities.pl b/misc/link_bibs_to_authorities.pl index c9d5aa308c..89f2e02e50 100755 --- a/misc/link_bibs_to_authorities.pl +++ b/misc/link_bibs_to_authorities.pl @@ -72,8 +72,6 @@ if ( not $result or $want_help ) { usage(); } -cronlogaction( { info => $command_line_options } ); - my $linker_module = "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' ); unless ( can_load( modules => { $linker_module => undef } ) ) { $linker_module = 'C4::Linker::Default';