Bug 38857: Update cronjobs to log run before processing parameters

A few notes:
- I grabbed this list by looking for things in misc/ that had cronlogaction
- I didn't touch scripts that aren't in the cronjobs directory, except
  fix_invalid_dates where I follow import_patrons and only log if confirmed
  since they aren't crons, I figure this seems reasonable
- purge_suggestions I moved the logggin up and changed the addition of
  effective days to a verbose message - this seems more consistent

To test:
 1 - Enable CronjobLog
 2 - On command line:
     perl misc/cronjobs/cleanup_database.pl --old_reservers 550
 3 - Error on command line
 4 - In staff client, go to Tools->Log viewer, check 'Cronjobs' and submit
 5 - No entries
 6 - Apply patch
 7 - Repeat and see run is logged with wrong parameter
 8 - Fix parameter and confirm
 9 - Spot check other files until you are satisfied
10 - Sign it off!

Signed-off-by: William Lavoie <william.lavoie@inLibro.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit ed04d5b0fa)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Nick Clemens 2025-01-09 20:46:40 +00:00 committed by Paul Derscheid
parent de8c20de12
commit 85e586af8d
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
35 changed files with 57 additions and 65 deletions

View File

@ -186,6 +186,7 @@ my $help = 0;
my $man = 0;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -217,7 +218,6 @@ END_WARN
unless ($confirm) {
pod2usage(1);
}
cronlogaction({ info => $command_line_options });
my %branches = ();
if (@branchcodes) {

View File

@ -12,6 +12,7 @@ use C4::Items;
use C4::Log qw( cronlogaction );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
# Getting options
my ( $verbose, $help, $confirm );
@ -30,7 +31,6 @@ my $rules = eval { JSON::from_json( $syspref_content ) };
pod2usage({ -message => "Unable to load the configuration : $@", -exitval => 1 })
if $@;
cronlogaction({ info => $command_line_options });
my $report = C4::Items::ToggleNewStatus( { rules => $rules, report_only => not $confirm } );

View File

@ -88,6 +88,7 @@ use Koha::Libraries;
use Koha::Patrons;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
my ( $help, $send_notices, $verbose, $confirm, $digest_per_branch );
GetOptions(
@ -130,8 +131,6 @@ To change this, edit the "EnhancedMessagingPreferences" syspref.
END_WARN
}
cronlogaction( { info => $command_line_options } );
$verbose = 1 unless $verbose or $confirm;
print "Test run only\n" unless $confirm;

View File

@ -44,6 +44,7 @@ USAGE
}
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
my ( $help, $days, $verbose );
@ -62,8 +63,6 @@ if ( !$days ) {
usage(1);
}
cronlogaction({ info => $command_line_options });
my $date = dt_from_string->subtract( days => $days );
print "Checkouts and holds before " . output_pref( { dt => $date, dateformat => 'iso', dateonly => 1 } ) . " will be anonymised.\n"

View File

@ -16,6 +16,7 @@ use C4::Log;
use Koha::Biblios;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
my ( $input_marc_file, $number) = ('',0);
my ($version, $confirm,$field,$batch,$max_digits,$cloud_tag);
@ -59,8 +60,6 @@ my $browser_subfield = $2;
warn "browser : $browser_tag / $browser_subfield" unless $batch;
die "no cloud or browser field/subfield defined : nothing to do !" unless $browser_tag or $cloud_tag;
cronlogaction({ info => $command_line_options });
my $dbh = C4::Context->dbh;
my $i=0;

View File

@ -38,6 +38,7 @@ use Getopt::Long qw( GetOptions );
my $hours = 0;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions( 'h|hours=s' => \$hours, );
@ -60,8 +61,6 @@ unless ($hours) {
die "ERROR: No --hours (-h) option defined";
}
cronlogaction({ info => $command_line_options });
my $query = "SELECT itemnumber FROM items WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($hours);

View File

@ -174,6 +174,7 @@ my $reports;
my $edifact_msg_days;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
GetOptions(
'h|help' => \$help,
@ -297,7 +298,6 @@ if ( $pDebarments && $allDebarments ) {
say "Confirm flag not passed, running in dry-run mode..." unless $confirm;
cronlogaction( { info => $command_line_options } );
my $dbh = C4::Context->dbh();
my $sth;

View File

@ -35,6 +35,7 @@ my $help = 0;
my $conf = '';
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'verbose' => \$verbose,
@ -49,8 +50,6 @@ sub usage {
usage() if $help || !$conf;
cronlogaction({ info => $command_line_options });
my @clouds;
print "Reading configuration file: $conf\n" if $verbose;
eval {

View File

@ -76,6 +76,9 @@ use Koha::Patron::Debarments;
use C4::Log qw( cronlogaction );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
my ( $amount, $help, $confirm, $message, $expiration, $file, $verbose );
GetOptions(
'a|amount:i' => \$amount,
@ -89,7 +92,6 @@ GetOptions(
pod2usage(1) if $help;
pod2usage(1) unless $message || $file;
cronlogaction();
my $patrons = Koha::Patrons->filter_by_amount_owed( { more_than => $amount // 0 } );
$message = getMessageContent();
@ -126,6 +128,8 @@ my $verb = $confirm ? 'Debarred' : 'Found';
print "debar_patrons_with_fines: $verb $count_patrons patrons";
print( $errors ? ", had $errors failures\n" : "\n" );
cronlogaction({ action => 'End', info => "COMPLETED" });
sub getMessageContent {
return $message if ($message);
open( my $FH, "<:encoding(UTF-8)", $file ) or die "Could not open $file: $!\n";

View File

@ -15,6 +15,7 @@ my ( $help, $verbose, $not_borrowed_since, $expired_before, $last_seen,
@category_code, $branchcode, $file, $confirm );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'h|help' => \$help,
@ -46,8 +47,6 @@ unless ( $not_borrowed_since or $expired_before or $last_seen or @category_code
pod2usage(q{At least one filter is mandatory});
}
cronlogaction({ info => $command_line_options });
my @file_members;
if ($file) {
open(my $fh, '<:encoding(UTF-8)', $file) or die "Could not open file $file' $!";

View File

@ -100,6 +100,7 @@ C<erm_run_harvester.pl --begin-date 2000-01-01 --end-date 2024-01-01 --debug --d
=cut
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
# Command line option values
my $help = 0;
@ -131,8 +132,6 @@ unless ($begin_date) {
pod2usage(1);
}
cronlogaction( { info => $command_line_options } );
debug_msg("Dry run: Harvests will not be enqueued") if $dry_run;
while ( my $udprovider = $udproviders->next ) {
debug_msg(

View File

@ -51,6 +51,7 @@ my $maxdays;
my $verify_issue;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'h|help' => \$help,
@ -96,8 +97,6 @@ catch {
exit;
};
cronlogaction({ info => $command_line_options });
my @borrower_fields =
qw(cardnumber categorycode surname firstname email phone address citystate);
my @item_fields = qw(itemnumber barcode date_due);

View File

@ -30,6 +30,7 @@ my (
);
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
$send = 1;
GetOptions(
@ -74,8 +75,6 @@ if ( $ods and @letter_codes != 1 ) {
$delimiter ||= q|,|;
cronlogaction({ info => $command_line_options });
my $today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ) ;
my $today_syspref = output_pref( { dt => dt_from_string, dateonly => 1 } );

View File

@ -29,6 +29,7 @@ use C4::Log qw( cronlogaction );
use Try::Tiny qw( catch try );
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
my ( $help, $verbose, $id, $days, $list, $force );
@ -99,8 +100,6 @@ try {
exit;
};
cronlogaction( { info => $command_line_options } );
my $harvester =
Koha::OAI::Client::Harvester->new( { server => $server, days => $days, force => $force, logger => \&logFunction } );
$harvester->init();

View File

@ -65,6 +65,7 @@ my $force = 0;
my $unallocated = 0;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
GetOptions(
'h|help' => \$help,
@ -83,8 +84,6 @@ if ( $rthq && !$force ) {
exit(1);
}
cronlogaction( { info => $command_line_options } );
my $loops = C4::Context->preference('HoldsQueueParallelLoopsCount');
CreateQueue( { loops => $loops, unallocated => $unallocated } );

View File

@ -66,6 +66,7 @@ my $help = 0;
my $reason;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -73,8 +74,6 @@ GetOptions(
) or pod2usage(1);
pod2usage(1) if $help;
cronlogaction({ info => $command_line_options });
C4::Reserves::CancelExpiredReserves($reason);
cronlogaction({ action => 'End', info => "COMPLETED" });

View File

@ -86,6 +86,7 @@ my $confirm = 0;
my $reason;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'h|help|?' => \$help,
@ -108,8 +109,6 @@ qq{\nError: You must specify a value for days waiting to cancel holds.\n},
);
}
cronlogaction({ info => $command_line_options });
warn "Running in test mode, no actions will be taken" unless ($confirm);
$verbose and warn "Looking for unfilled holds placed $days or more days ago\n";

View File

@ -177,6 +177,7 @@ my $opt_out = 0;
my @mtts;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -196,8 +197,6 @@ pod2usage( -verbose => 2 ) if $man;
$lettercode ||= 'HOLD_REMINDER';
cronlogaction({ info => $command_line_options });
# Unless a delay is specified by the user we target all waiting holds
unless (defined $days) {
$days=0;

View File

@ -56,6 +56,7 @@ my $list_itemtypes = 0;
my @skip_lost_values;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'l|lost=s%' => \$lost,
@ -320,8 +321,6 @@ unless ($confirm) {
print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
}
cronlogaction({ info => $command_line_options });
# In my opinion, this line is safe SQL to have outside the API. --atz
our $bounds_sth = C4::Context->dbh->prepare("SELECT DATE_SUB(CURDATE(), INTERVAL ? DAY)");

View File

@ -67,6 +67,7 @@ use Koha::MarcOrderAccounts;
use C4::Log qw( cronlogaction );
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
my ( $help, $verbose, $confirm, $delete );
GetOptions(
@ -78,8 +79,6 @@ GetOptions(
pod2usage(0) if $help;
cronlogaction( { info => $command_line_options } );
$verbose = 1 unless $verbose or $confirm;
print "Test run only\n" unless $confirm;

View File

@ -179,6 +179,7 @@ my $letter_expiry;
my $letter_renew;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -226,8 +227,6 @@ if ( !C4::Context->preference('TrackLastPatronActivityTriggers')
);
}
cronlogaction({ info => $command_line_options });
my $expdays = C4::Context->preference('MembershipExpiryDaysNotice');
if( !$expdays ) {
#If the pref is not set, we will exit

View File

@ -312,6 +312,7 @@ my @myborcatout;
my ( $date_input, $today );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -335,7 +336,6 @@ GetOptions(
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man;
cronlogaction({ info => $command_line_options });
if ( defined $csvfilename && $csvfilename =~ /^-/ ) {
warn qq(using "$csvfilename" as filename, that seems odd);

View File

@ -118,6 +118,7 @@ my $error_msgs = {
};
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -133,8 +134,6 @@ GetOptions(
pod2usage(1) if $help;
pod2usage(1) unless $report_id && $notice && $module;
cronlogaction({ info => $command_line_options });
my ( $emails, $errors ) = C4::Reports::Guided::EmailReport({
email => $email,
from => $from,

View File

@ -38,6 +38,7 @@ my @letter_code;
my $exit_on_plugin_failure = 0;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
GetOptions(
'u|username:s' => \$username,
@ -86,8 +87,6 @@ try {
exit;
};
cronlogaction( { info => $command_line_options } );
# Remove empty elements, see bug 37075
@letter_code = grep { $_ ne q{} } @letter_code;

View File

@ -26,14 +26,16 @@ use C4::Suggestions;
use C4::Log qw( cronlogaction );
use C4::Context;
my ( $help, $days, $confirm );
my ( $help, $days, $confirm, $verbose );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
'days:i' => \$days,
'confirm'=> \$confirm,
'help|?' => \$help,
'days:i' => \$days,
'confirm' => \$confirm,
'v|verbose' => \$verbose,
);
my $usage = << 'ENDUSAGE';
@ -42,6 +44,7 @@ Parameters:
-help|? This message
-days TTT to define the age of suggestions to delete
-confirm flag needed to confirm purge operation
-verbose flag to increase feedback
The days parameter falls back to the value of system preference
PurgeSuggestionsOlderThan. Suggestions are deleted only for a positive
@ -59,8 +62,7 @@ if( !$confirm || $help || !defined($days) ) {
print "No confirm parameter passed!\n\n" if !$confirm && !$help;
print $usage;
} elsif( $days and $days > 0 ) {
$command_line_options .= " ( effective days = $days )";
cronlogaction({ info => $command_line_options });
print "Purging suggestions older than $days days\n" if $verbose;
DelSuggestionsOlderThan($days);
} else {
warn "This script requires a positive number of days. Aborted.\n";

View File

@ -65,6 +65,7 @@ my $help = 0;
my $verbose = 0;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help' => \$help,
@ -72,7 +73,6 @@ GetOptions(
) or pod2usage(2);
pod2usage(1) if $help;
cronlogaction({ info => $command_line_options });
my @patron_ids = Koha::Account::Lines->search(
{

View File

@ -28,6 +28,9 @@ use Koha::Patrons;
use C4::Letters;
use Koha::Notice::Message;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
# Getting options
my ( $help, $verbose, $confirm );
GetOptions(
@ -47,7 +50,6 @@ Exiting cronjob
END_WARN
}
cronlogaction();
my @failed_notices = Koha::Notice::Messages->get_failed_notices( { days => 7 } )->as_list;

View File

@ -205,6 +205,7 @@ my $password = undef;
my $method = 'LOGIN';
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
@ -231,8 +232,6 @@ pod2usage( -verbose => 2 ) if ($man);
pod2usage( -verbose => 2 ) if ($help and $verbose);
pod2usage(1) if $help;
cronlogaction({ info => $command_line_options });
unless ($format) {
$verbose and print STDERR "No format specified, assuming 'text'\n";
$format = 'text';

View File

@ -60,6 +60,7 @@ my $note = '';
my $nonote = 0;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|h|?' => \$help,
@ -73,8 +74,6 @@ GetOptions(
pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man;
cronlogaction({ info => $command_line_options });
$verbose and !$confirm and print "### Database will not be modified ###\n";
if ( $note && $nonote ) {

View File

@ -127,6 +127,7 @@ my $status_email_message = undef;
my $sftp_status = undef;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
GetOptions(
'help|?' => \$help,
@ -144,8 +145,6 @@ pod2usage( -verbose => 2 ) if ($man);
pod2usage( -verbose => 2 ) if ( $help and $verbose );
pod2usage(1) if $help;
cronlogaction( { info => $command_line_options } );
# Check we have all the SFTP details we need
if ( !$user || !$pass || !$host || !$upload_dir ) {
pod2usage(q|Please provide details for sftp username, password, upload directory, and host|);

View File

@ -12,6 +12,7 @@ use C4::Log qw( cronlogaction );
use POSIX qw( strftime );
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
my ( $help, $verbose, $force, $quiet );
GetOptions(
@ -38,8 +39,6 @@ Setting the quiet flag will silence this message.
exit 1;
}
cronlogaction({ info => $command_line_options });
my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() );
if ($need_update) {

View File

@ -53,6 +53,7 @@ my $debug = 0;
my $bigdebug = 0;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'h|help' => \$help,
@ -83,8 +84,6 @@ This script has the following parameters :
ENDUSAGE
die $usage if $help;
cronlogaction({ info => $command_line_options });
my $dbh = C4::Context->dbh;
# Processing categories

View File

@ -170,6 +170,9 @@ my $branch_lim;
my %fields;
my @where;
my $command_line_options = join(" ",@ARGV);
cronlogaction({ info => $command_line_options });
GetOptions(
'help|?' => \$help,
'man' => \$man,
@ -202,8 +205,6 @@ if ( not $fromcat && $tocat ) { #make sure we've specified the info we need.
$verbose and print "Will update patrons from $fromcat to $tocat with conditions below (if any)\n";
cronlogaction();
my %params;
if ( $reg_bef || $reg_aft ) {

View File

@ -53,6 +53,7 @@ my $progress = 100;
my $unit;
my $command_line_options = join( " ", @ARGV );
cronlogaction( { info => $command_line_options } );
my $result = GetOptions(
'v|verbose' => \$verbose,
@ -89,8 +90,6 @@ unless ( $usestats || $useitems ) {
usage() if $want_help;
cronlogaction( { info => $command_line_options } );
my $dbh = C4::Context->dbh;
my $num_bibs_processed = 0;

View File

@ -40,11 +40,19 @@ This script fixes any date fields in the database that have '0000-00-00' values
my $verbose = 0;
my $doit = 0;
my $command_line_options = join( " ", @ARGV );
GetOptions(
'v|verbose' => \$verbose,
'c|confirm' => \$doit,
);
if ($doit) {
cronlogaction( { action => 'Run', info => $command_line_options } );
} else {
warn "Running in dry-run mode, provide --confirm to apply the changes\n";
}
my $schema = Koha::Database->new->schema;
# Loop over all the DBIx::Class classes