Bug 13889: Add information about cron jobs to system log

This patch adds information about cron jobs performed and make it viewable
under Home > Tools > Logs ("Browse system logs")

To test:

Apply patch
- Got to system preferences and set 'CronjobLog' to:  [Log] information from
  cron jobs.
- Run some cron jobs
- Go to Home > Tools > Logs
- Verify that you have a selection 'Cron jobs' in drop-down 'Module'. Select it
  with Action "All" and Submit.
- Output should show Date/time and info about Cron jobs

Rebased to work on top of Bug 6911 (conflict in viewlog.tt)  /MV

Rebased after applying patch for Bug 6911 /MV
Conflicts resolved:
misc/cronjobs/overdue_notices.pl
misc/cronjobs/cleanup_database.pl

Signed-off-by: Frederic Demians <f.demians@tamil.fr>
  - Merge both patches, and fix updatedatabase.pl
  - Works as described. Provide intersting feedback from cronjob scripts.

--
Modified version taking in account syspref CronJobLog. Handling simplified by introducing a convenience sub cronlogaction in C4/Log.pm /MV
Amended to take in account comments #11, #12, #13 /MV

http://bugs.koha-community.org/show_bug.cgi?id=13899

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Marc Véron 2015-03-22 13:55:00 +01:00 committed by Tomas Cohen Arazi
parent 8e0cb870d5
commit df87f507d9
30 changed files with 103 additions and 10 deletions

View file

@ -30,11 +30,11 @@ use C4::Dates qw(format_date);
use vars qw($VERSION @ISA @EXPORT); use vars qw($VERSION @ISA @EXPORT);
BEGIN { BEGIN {
# set the version for version checking # set the version for version checking
$VERSION = 3.07.00.049; $VERSION = 3.07.00.049;
require Exporter; require Exporter;
@ISA = qw(Exporter); @ISA = qw(Exporter);
@EXPORT = qw(&logaction &GetLogStatus &displaylog &GetLogs); @EXPORT = qw(&logaction &cronlogaction &GetLogStatus &displaylog &GetLogs);
} }
=head1 NAME =head1 NAME
@ -81,6 +81,20 @@ sub logaction {
$sth->finish; $sth->finish;
} }
=item cronlogaction
&cronlogaction();
Convenience routine to add a record into action_logs table from a cron job.
=cut
#'
sub cronlogaction {
logaction( 'CRONJOBS', 'Run', 0, (caller(0))[1] ) if C4::Context->preference('CronjobLog');
}
=item GetLogStatus =item GetLogStatus
$status = GetLogStatus; $status = GetLogStatus;

View file

@ -0,0 +1 @@
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo');

View file

@ -92,6 +92,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('CoceProviders', NULL, 'aws,gb,ol', 'Coce providers', 'multiple'), ('CoceProviders', NULL, 'aws,gb,ol', 'Coce providers', 'multiple'),
('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page. NOTE: this can slow down search response time significantly','YesNo'), ('COinSinOPACResults','1','','If ON, use COinS in OPAC search results page. NOTE: this can slow down search response time significantly','YesNo'),
('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'), ('ConfirmFutureHolds','0','','Number of days for confirming future holds','Integer'),
('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'),
('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: \'36000\' is displayed as \'360 000,00\' in \'FR\' or \'360,000.00\' in \'US\'.','Choice'), ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: \'36000\' is displayed as \'360 000,00\' in \'FR\' or \'360,000.00\' in \'US\'.','Choice'),
('dateformat','us','metric|us|iso','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd)','Choice'), ('dateformat','us','metric|us|iso','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd)','Choice'),
('DebugLevel','2','0|1|2','Define the level of debugging information sent to the browser when errors are encountered (set to 0 in production). 0=none, 1=some, 2=most','Choice'), ('DebugLevel','2','0|1|2','Define the level of debugging information sent to the browser when errors are encountered (set to 0 in production). 0=none, 1=some, 2=most','Choice'),

View file

@ -47,3 +47,9 @@ Logging:
on: Log on: Log
off: "Don't log" off: "Don't log"
- when serials are added, deleted or changed. - when serials are added, deleted or changed.
-
- pref: CronjobLog
choices:
on: Log
off: "Don't log"
- information from cron jobs.

View file

@ -26,6 +26,7 @@
[% CASE 'LETTER' %]Letter [% CASE 'LETTER' %]Letter
[% CASE 'FINES' %]Fines [% CASE 'FINES' %]Fines
[% CASE 'SYSTEMPREFERENCE' %]System prefs [% CASE 'SYSTEMPREFERENCE' %]System prefs
[% CASE 'CRONJOBS' %]Cron jobs
[% CASE %][% module %] [% CASE %][% module %]
[% END %] [% END %]
[% END %] [% END %]
@ -76,7 +77,7 @@
[% ELSE %] [% ELSE %]
<option value="">All</option> <option value="">All</option>
[% END %] [% END %]
[% FOREACH modx IN [ 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' ] %] [% FOREACH modx IN [ 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'CIRCULATION' 'LETTER' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS' ] %]
[% IF modules.grep(modx).size %] [% IF modules.grep(modx).size %]
<option value="[% modx %]" selected="selected">[% PROCESS translate_log_module module=modx %]</option> <option value="[% modx %]" selected="selected">[% PROCESS translate_log_module module=modx %]</option>
[% ELSE %] [% ELSE %]

View file

@ -56,6 +56,7 @@ use C4::Members;
use C4::Members::Messaging; use C4::Members::Messaging;
use C4::Overdues; use C4::Overdues;
use Koha::DateUtils; use Koha::DateUtils;
use C4::Log;
=head1 NAME =head1 NAME
@ -199,6 +200,9 @@ END_WARN
unless ($confirm) { unless ($confirm) {
pod2usage(1); pod2usage(1);
} }
cronlogaction();
# The fields that will be substituted into <<items.content>> # The fields that will be substituted into <<items.content>>
my @item_content_fields = split(/,/,$itemscontent); my @item_content_fields = split(/,/,$itemscontent);

View file

@ -44,6 +44,9 @@ use Modern::Perl;
use C4::Circulation; use C4::Circulation;
use C4::Context; use C4::Context;
use C4::Log;
cronlogaction();
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my ( $borrowernumber, $itemnumber, $branch, $ok, $error ); my ( $borrowernumber, $itemnumber, $branch, $ok, $error );

View file

@ -37,6 +37,7 @@ use Date::Calc qw(
Add_Delta_Days Add_Delta_Days
); );
use Getopt::Long; use Getopt::Long;
use C4::Log;
sub usage { sub usage {
print STDERR <<USAGE; print STDERR <<USAGE;
@ -66,6 +67,8 @@ if ( !$days ) {
usage(1); usage(1);
} }
cronlogaction();
my ($year,$month,$day) = Today(); my ($year,$month,$day) = Today();
my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days); my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days);
my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday; my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday;

View file

@ -18,6 +18,8 @@ use Time::HiRes qw(gettimeofday);
use ZOOM; use ZOOM;
use MARC::File::USMARC; use MARC::File::USMARC;
use Getopt::Long; use Getopt::Long;
use C4::Log;
my ( $input_marc_file, $number) = ('',0); my ( $input_marc_file, $number) = ('',0);
my ($version, $confirm,$test_parameter,$field,$batch,$max_digits,$cloud_tag); my ($version, $confirm,$test_parameter,$field,$batch,$max_digits,$cloud_tag);
GetOptions( GetOptions(
@ -60,6 +62,8 @@ my $browser_subfield = $2;
warn "browser : $browser_tag / $browser_subfield" unless $batch; 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; die "no cloud or browser field/subfield defined : nothing to do !" unless $browser_tag or $cloud_tag;
cronlogaction();
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $i=0; my $i=0;

View file

@ -29,6 +29,7 @@ use strict;
use warnings; use warnings;
use C4::Items qw/ CartToShelf /; use C4::Items qw/ CartToShelf /;
use C4::Log;
BEGIN { BEGIN {
@ -63,6 +64,8 @@ unless ($hours) {
die "ERROR: No --hours (-h) option defined"; die "ERROR: No --hours (-h) option defined";
} }
cronlogaction();
my $query = "SELECT itemnumber FROM items WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?"; my $query = "SELECT itemnumber FROM items WHERE location = 'CART' AND TIMESTAMPDIFF(HOUR, items.timestamp, NOW() ) > ?";
my $sth = C4::Context->dbh->prepare($query); my $sth = C4::Context->dbh->prepare($query);
$sth->execute($hours); $sth->execute($hours);

View file

@ -36,10 +36,9 @@ BEGIN {
use C4::Context; use C4::Context;
use C4::Dates; use C4::Dates;
use C4::Search; use C4::Search;
use Getopt::Long; use Getopt::Long;
use C4::Log;
sub usage { sub usage {
print STDERR <<USAGE; print STDERR <<USAGE;
@ -132,6 +131,8 @@ if ($pDebarments && $allDebarments) {
usage(1); usage(1);
} }
cronlogaction();
my $dbh = C4::Context->dbh(); my $dbh = C4::Context->dbh();
my $sth; my $sth;
my $sth2; my $sth2;

View file

@ -26,7 +26,7 @@ use YAML::Syck;
use Pod::Usage; use Pod::Usage;
use Getopt::Long; use Getopt::Long;
use C4::Context; use C4::Context;
use C4::Log;
my $verbose = 0; my $verbose = 0;
my $help = 0; my $help = 0;
@ -44,6 +44,7 @@ sub usage {
usage() if $help || !$conf; usage() if $help || !$conf;
cronlogaction();
my @clouds; my @clouds;
print "Reading configuration file: $conf\n" if $verbose; print "Reading configuration file: $conf\n" if $verbose;

View file

@ -30,6 +30,7 @@ BEGIN {
use C4::Context; use C4::Context;
use C4::Members qw/ DelMember /; use C4::Members qw/ DelMember /;
use C4::Log;
my $help; my $help;
my $confirm; my $confirm;
@ -63,6 +64,8 @@ if ( $help || !$confirm ) {
exit; exit;
} }
cronlogaction();
# Delete accounts that haven't been upgraded from the 'temporary' category code # Delete accounts that haven't been upgraded from the 'temporary' category code
my $delay = my $delay =
C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay'); C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');

View file

@ -8,6 +8,7 @@ use Getopt::Long;
use C4::Members; use C4::Members;
use C4::VirtualShelves; use C4::VirtualShelves;
use Koha::DateUtils; use Koha::DateUtils;
use C4::Log;
my ( $help, $verbose, $not_borrowed_since, $expired_before, $category_code, my ( $help, $verbose, $not_borrowed_since, $expired_before, $category_code,
$branchcode, $confirm ); $branchcode, $confirm );
@ -36,6 +37,8 @@ unless ( $not_borrowed_since or $expired_before or $category_code or $branchcode
exit; exit;
} }
cronlogaction();
my $members = GetBorrowersToExpunge( my $members = GetBorrowersToExpunge(
{ {
not_borrowered_since => $not_borrowed_since, not_borrowered_since => $not_borrowed_since,

View file

@ -30,6 +30,7 @@ BEGIN {
use C4::Context; use C4::Context;
use C4::Members qw/ DelMember /; use C4::Members qw/ DelMember /;
use C4::Log;
my $help; my $help;
my $confirm; my $confirm;
@ -59,6 +60,8 @@ if ( $help || !$confirm ) {
exit; exit;
} }
cronlogaction();
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
$dbh->do( " $dbh->do( "

View file

@ -38,6 +38,7 @@ use File::Spec;
use Koha::Calendar; use Koha::Calendar;
use Koha::DateUtils; use Koha::DateUtils;
use C4::Log;
my $help; my $help;
my $verbose; my $verbose;
@ -70,6 +71,8 @@ if ($help) {
exit; exit;
} }
cronlogaction();
my @borrower_fields = my @borrower_fields =
qw(cardnumber categorycode surname firstname email phone address citystate); qw(cardnumber categorycode surname firstname email phone address citystate);
my @item_fields = qw(itemnumber barcode date_due); my @item_fields = qw(itemnumber barcode date_due);

View file

@ -36,6 +36,7 @@ use C4::Letters;
use C4::Templates; use C4::Templates;
use File::Spec; use File::Spec;
use Getopt::Long; use Getopt::Long;
use C4::Log;
sub usage { sub usage {
print STDERR <<USAGE; print STDERR <<USAGE;
@ -65,6 +66,8 @@ if ( !$output_directory || !-d $output_directory || !-w $output_directory ) {
usage(1); usage(1);
} }
cronlogaction();
my $today = C4::Dates->new(); my $today = C4::Dates->new();
my @all_messages = @{ GetPrintMessages() }; my @all_messages = @{ GetPrintMessages() };
exit unless (@all_messages); exit unless (@all_messages);

View file

@ -30,5 +30,8 @@ BEGIN {
# cancel all expired hold requests # cancel all expired hold requests
use C4::Reserves; use C4::Reserves;
use C4::Log;
cronlogaction();
AutoUnsuspendReserves(); AutoUnsuspendReserves();

View file

@ -16,6 +16,9 @@ BEGIN {
} }
use C4::HoldsQueue qw(CreateQueue); use C4::HoldsQueue qw(CreateQueue);
use C4::Log;
cronlogaction();
CreateQueue(); CreateQueue();

View file

@ -30,5 +30,8 @@ BEGIN {
# cancel all expired hold requests # cancel all expired hold requests
use C4::Reserves; use C4::Reserves;
use C4::Log;
cronlogaction();
CancelExpiredReserves(); CancelExpiredReserves();

View file

@ -32,6 +32,7 @@ use C4::Context;
use C4::Members; use C4::Members;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
use C4::Log;
=head1 NAME =head1 NAME
@ -126,6 +127,8 @@ if(not $fromcat && $tocat) { #make sure we've specified the info we need.
exit; exit;
} }
cronlogaction();
my $dbh=C4::Context->dbh; my $dbh=C4::Context->dbh;
my @branches = C4::Branch::GetBranches(); my @branches = C4::Branch::GetBranches();
#get today's date, format it and subtract upperagelimit #get today's date, format it and subtract upperagelimit

View file

@ -37,6 +37,7 @@ use C4::Context;
use C4::Items; use C4::Items;
use C4::Circulation qw/LostItem/; use C4::Circulation qw/LostItem/;
use Getopt::Long; use Getopt::Long;
use C4::Log;
my $lost; # key=lost value, value=num days. my $lost; # key=lost value, value=num days.
my ($charge, $verbose, $confirm, $quiet); my ($charge, $verbose, $confirm, $quiet);
@ -129,6 +130,8 @@ unless ($confirm) {
print "### TEST MODE -- NO ACTIONS TAKEN ###\n"; print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
} }
cronlogaction();
# In my opinion, this line is safe SQL to have outside the API. --atz # 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)"); our $bounds_sth = C4::Context->dbh->prepare("SELECT DATE_SUB(CURDATE(), INTERVAL ? DAY)");

View file

@ -43,11 +43,10 @@ use C4::Debug;
use C4::Letters; use C4::Letters;
use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes);
use C4::Budgets qw(GetCurrency); use C4::Budgets qw(GetCurrency);
use Koha::DateUtils;
use Koha::Borrower::Debarments qw(AddUniqueDebarment); use Koha::Borrower::Debarments qw(AddUniqueDebarment);
use Koha::DateUtils; use Koha::DateUtils;
use Koha::Calendar; use Koha::Calendar;
use C4::Log;
=head1 NAME =head1 NAME
@ -316,6 +315,8 @@ GetOptions(
pod2usage(1) if $help; pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man; pod2usage( -verbose => 2 ) if $man;
cronlogaction();
if ( defined $csvfilename && $csvfilename =~ /^-/ ) { if ( defined $csvfilename && $csvfilename =~ /^-/ ) {
warn qq(using "$csvfilename" as filename, that seems odd); warn qq(using "$csvfilename" as filename, that seems odd);
} }

View file

@ -26,6 +26,7 @@ BEGIN {
eval { require "$FindBin::Bin/../kohalib.pl" }; eval { require "$FindBin::Bin/../kohalib.pl" };
} }
use C4::Letters; use C4::Letters;
use C4::Log;
use Getopt::Long; use Getopt::Long;
my $username = undef; my $username = undef;
@ -60,5 +61,7 @@ ENDUSAGE
die $usage if $help; die $usage if $help;
cronlogaction();
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } );

View file

@ -32,6 +32,7 @@ BEGIN {
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
use C4::Suggestions; use C4::Suggestions;
use C4::Log;
my ($help, $days); my ($help, $days);
@ -55,6 +56,7 @@ EOF
} }
if($days){ if($days){
cronlogaction();
DelSuggestionsOlderThan($days); DelSuggestionsOlderThan($days);
} }

View file

@ -24,6 +24,7 @@ use warnings;
use C4::Reports::Guided; # 0.12 use C4::Reports::Guided; # 0.12
use C4::Context; use C4::Context;
use Koha::Email; use Koha::Email;
use C4::Log;
use Getopt::Long qw(:config auto_help auto_version); use Getopt::Long qw(:config auto_help auto_version);
use Pod::Usage; use Pod::Usage;
@ -189,6 +190,8 @@ pod2usage( -verbose => 2 ) if ($man);
pod2usage( -verbose => 2 ) if ($help and $verbose); pod2usage( -verbose => 2 ) if ($help and $verbose);
pod2usage(1) if $help; pod2usage(1) if $help;
cronlogaction();
unless ($format) { unless ($format) {
$verbose and print STDERR "No format specified, assuming 'text'\n"; $verbose and print STDERR "No format specified, assuming 'text'\n";
$format = 'text'; $format = 'text';

View file

@ -32,6 +32,7 @@ use C4::Context;
use C4::Dates qw/format_date format_date_in_iso/; use C4::Dates qw/format_date format_date_in_iso/;
use C4::Debug; use C4::Debug;
use C4::Serials; use C4::Serials;
use C4::Log;
use Date::Calc qw/Date_to_Days check_date/; use Date::Calc qw/Date_to_Days check_date/;
use Getopt::Long; use Getopt::Long;
@ -77,6 +78,8 @@ GetOptions(
pod2usage(1) if $help; pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man; pod2usage( -verbose => 2 ) if $man;
cronlogaction();
$verbose and !$confirm and print "### Database will not be modified ###\n"; $verbose and !$confirm and print "### Database will not be modified ###\n";
if ( $note && $nonote ) { if ( $note && $nonote ) {

View file

@ -7,6 +7,7 @@ use Getopt::Long;
use C4::Context; use C4::Context;
use C4::UsageStats; use C4::UsageStats;
use C4::Log;
use POSIX qw(strftime); use POSIX qw(strftime);
my ( $help, $verbose, $force ); my ( $help, $verbose, $force );
@ -30,6 +31,8 @@ If your library wants to share their usage statistics with the Koha community, y
exit 1; exit 1;
} }
cronlogaction();
my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() ); my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() );
if ($need_update) { if ($need_update) {

View file

@ -43,6 +43,7 @@ use C4::Overdues;
use C4::Calendar qw(); # don't need any exports from Calendar use C4::Calendar qw(); # don't need any exports from Calendar
use C4::Biblio; use C4::Biblio;
use C4::Debug; # supplying $debug and $cgi_debug use C4::Debug; # supplying $debug and $cgi_debug
use C4::Log;
use Getopt::Long; use Getopt::Long;
use List::MoreUtils qw/none/; use List::MoreUtils qw/none/;
use Koha::DateUtils; use Koha::DateUtils;
@ -90,6 +91,8 @@ This script has the following parameters :
ENDUSAGE ENDUSAGE
die $usage if $help; die $usage if $help;
cronlogaction();
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
# Processing categories # Processing categories

View file

@ -32,6 +32,7 @@ use Getopt::Long;
use Pod::Usage; use Pod::Usage;
use C4::Context; use C4::Context;
use C4::Biblio; use C4::Biblio;
use C4::Log;
use DateTime; use DateTime;
use DateTime::Format::MySQL; use DateTime::Format::MySQL;
use Time::HiRes qw/time/; use Time::HiRes qw/time/;
@ -94,6 +95,8 @@ if ( not $result or $want_help ) {
usage(); usage();
} }
cronlogaction();
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0; $dbh->{AutoCommit} = 0;