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 <pedro.amorim@openfifth.co.uk>
This commit is contained in:
parent
1652191b7f
commit
ece2d64e76
|
|
@ -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<CronjobLog> 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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue