From 8ff362410aba25d5ffd20bf5d47c8a542fbb8cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Sun, 22 Mar 2015 13:55:00 +0100 Subject: [PATCH] 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 - Merge both patches, and fix updatedatabase.pl - Works as described. Provide intersting feedback from cronjob scripts. --- installer/data/mysql/sysprefs.sql | 3 ++- installer/data/mysql/updatedatabase.pl | 8 ++++++++ .../intranet-tmpl/prog/en/modules/admin/preferences/logs.pref | 6 ++++++ koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt | 3 ++- misc/cronjobs/advance_notices.pl | 4 ++++ misc/cronjobs/automatic_renewals.pl | 3 +++ misc/cronjobs/batch_anonymise.pl | 3 +++ misc/cronjobs/build_browser_and_cloud.pl | 4 ++++ misc/cronjobs/cart_to_shelf.pl | 3 +++ misc/cronjobs/cleanup_database.pl | 5 +++-- misc/cronjobs/cloud-kw.pl | 3 ++- misc/cronjobs/delete_expired_opac_registrations.pl | 3 +++ misc/cronjobs/delete_patrons.pl | 3 +++ misc/cronjobs/delete_unverified_opac_registrations.pl | 3 +++ misc/cronjobs/fines.pl | 3 +++ misc/cronjobs/gather_print_notices.pl | 3 +++ misc/cronjobs/holds/auto_unsuspend_holds.pl | 3 +++ misc/cronjobs/holds/build_holds_queue.pl | 3 +++ misc/cronjobs/holds/cancel_expired_holds.pl | 3 +++ misc/cronjobs/j2a.pl | 3 +++ misc/cronjobs/longoverdue.pl | 3 +++ misc/cronjobs/overdue_notices.pl | 5 +++-- misc/cronjobs/process_message_queue.pl | 3 +++ misc/cronjobs/purge_suggestions.pl | 2 ++ misc/cronjobs/runreport.pl | 3 +++ misc/cronjobs/serialsUpdate.pl | 3 +++ misc/cronjobs/share_usage_with_koha_community.pl | 3 +++ misc/cronjobs/staticfines.pl | 3 +++ misc/cronjobs/update_totalissues.pl | 3 +++ 29 files changed, 93 insertions(+), 7 deletions(-) diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 1e07e3c..2569763 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -474,5 +474,6 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'), ('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'), ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), -('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo') +('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), +('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo') ; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 78e79d3..9c354bb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9978,6 +9978,14 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = '3.19.00.XXX'; +if ( CheckVersion($DBversion) ) { + $dbh->do("INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo');"); + print "Upgrade to $DBversion done (Add CronjobLog syspref)\n"; + SetVersion ($DBversion); +} + + # DEVELOPER PROCESS, search for anything to execute in the db_update directory # SEE bug 13068 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref index b6f22d0..73f76c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref @@ -47,3 +47,9 @@ Logging: on: Log off: "Don't log" - when serials are added, deleted or changed. + - + - pref: CronjobLog + choices: + on: Log + off: "Don't log" + - information from cron jobs. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index 634092f..9a3caac 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -25,6 +25,7 @@ [% CASE 'LETTER' %]Letter [% CASE 'FINES' %]Fines [% CASE 'SYSTEMPREFERENCE' %]System prefs +[% CASE 'CRONJOBS' %]Cron jobs [% CASE %][% module %] [% END %] [% END %] @@ -75,7 +76,7 @@ [% ELSE %] [% 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 %] [% ELSE %] diff --git a/misc/cronjobs/advance_notices.pl b/misc/cronjobs/advance_notices.pl index 3bf0a9e..959bbe3 100755 --- a/misc/cronjobs/advance_notices.pl +++ b/misc/cronjobs/advance_notices.pl @@ -56,6 +56,7 @@ use C4::Members; use C4::Members::Messaging; use C4::Overdues; use Koha::DateUtils; +use C4::Log; =head1 NAME @@ -199,6 +200,9 @@ END_WARN unless ($confirm) { pod2usage(1); } + +logaction("CRONJOBS", 'Run', '', 'advance_notices.pl'); + # The fields that will be substituted into <> my @item_content_fields = split(/,/,$itemscontent); diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index f96e00c..5b99d45 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -44,6 +44,9 @@ use Modern::Perl; use C4::Circulation; use C4::Context; +use C4::Log; + +logaction("CRONJOBS", 'Run', '', 'automatic_renewals.pl'); my $dbh = C4::Context->dbh; my ( $borrowernumber, $itemnumber, $branch, $ok, $error ); diff --git a/misc/cronjobs/batch_anonymise.pl b/misc/cronjobs/batch_anonymise.pl index 48a58c6..572fe90 100755 --- a/misc/cronjobs/batch_anonymise.pl +++ b/misc/cronjobs/batch_anonymise.pl @@ -37,6 +37,7 @@ use Date::Calc qw( Add_Delta_Days ); use Getopt::Long; +use C4::Log; sub usage { print STDERR <dbh; my $i=0; diff --git a/misc/cronjobs/cart_to_shelf.pl b/misc/cronjobs/cart_to_shelf.pl index d190ca4..0616910 100755 --- a/misc/cronjobs/cart_to_shelf.pl +++ b/misc/cronjobs/cart_to_shelf.pl @@ -29,6 +29,7 @@ use strict; use warnings; use C4::Items qw/ CartToShelf /; +use C4::Log; BEGIN { @@ -63,6 +64,8 @@ unless ($hours) { die "ERROR: No --hours (-h) option defined"; } +logaction("CRONJOBS", 'Run', '', 'cart_to_shelf.pl with '. $hours . ' hours'); + 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); diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 2dc3f2e..9a401c7 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -36,10 +36,9 @@ BEGIN { use C4::Context; use C4::Dates; - use C4::Search; - use Getopt::Long; +use C4::Log; sub usage { print STDERR <dbh(); my $sth; my $sth2; diff --git a/misc/cronjobs/cloud-kw.pl b/misc/cronjobs/cloud-kw.pl index 11aaf88..9458a5c 100755 --- a/misc/cronjobs/cloud-kw.pl +++ b/misc/cronjobs/cloud-kw.pl @@ -26,7 +26,7 @@ use YAML::Syck; use Pod::Usage; use Getopt::Long; use C4::Context; - +use C4::Log; my $verbose = 0; my $help = 0; @@ -44,6 +44,7 @@ sub usage { usage() if $help || !$conf; +logaction("CRONJOBS", 'Run', '', 'cloud-kw.pl'); my @clouds; print "Reading configuration file: $conf\n" if $verbose; diff --git a/misc/cronjobs/delete_expired_opac_registrations.pl b/misc/cronjobs/delete_expired_opac_registrations.pl index b88b9b6..b532ed7 100755 --- a/misc/cronjobs/delete_expired_opac_registrations.pl +++ b/misc/cronjobs/delete_expired_opac_registrations.pl @@ -30,6 +30,7 @@ BEGIN { use C4::Context; use C4::Members qw/ DelMember /; +use C4::Log; my $help; my $confirm; @@ -63,6 +64,8 @@ if ( $help || !$confirm ) { exit; } +logaction("CRONJOBS", 'Run', '', 'delete_expired_opac_registrations.pl'); + # Delete accounts that haven't been upgraded from the 'temporary' category code my $delay = C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay'); diff --git a/misc/cronjobs/delete_patrons.pl b/misc/cronjobs/delete_patrons.pl index a1463b1..2773f08 100755 --- a/misc/cronjobs/delete_patrons.pl +++ b/misc/cronjobs/delete_patrons.pl @@ -8,6 +8,7 @@ use Getopt::Long; use C4::Members; use C4::VirtualShelves; use Koha::DateUtils; +use C4::Log; my ( $help, $verbose, $not_borrowed_since, $expired_before, $category_code, $branchcode, $confirm ); @@ -36,6 +37,8 @@ unless ( $not_borrowed_since or $expired_before or $category_code or $branchcode exit; } +logaction("CRONJOBS", 'Run', '', 'delete_patrons.pl'); + my $members = GetBorrowersToExpunge( { not_borrowered_since => $not_borrowed_since, diff --git a/misc/cronjobs/delete_unverified_opac_registrations.pl b/misc/cronjobs/delete_unverified_opac_registrations.pl index 6909c70..cd70bad 100755 --- a/misc/cronjobs/delete_unverified_opac_registrations.pl +++ b/misc/cronjobs/delete_unverified_opac_registrations.pl @@ -30,6 +30,7 @@ BEGIN { use C4::Context; use C4::Members qw/ DelMember /; +use C4::Log; my $help; my $confirm; @@ -59,6 +60,8 @@ if ( $help || !$confirm ) { exit; } +logaction("CRONJOBS", 'Run', '', 'delete_unverified_opac_registrations.pl with '.$hours.' hours'); + my $dbh = C4::Context->dbh; $dbh->do( " diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 38c344a..be8fb5b 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -38,6 +38,7 @@ use File::Spec; use Koha::Calendar; use Koha::DateUtils; +use C4::Log; my $help; my $verbose; @@ -70,6 +71,8 @@ if ($help) { exit; } +logaction("CRONJOBS", 'Run', '', 'fines.pl'); + my @borrower_fields = qw(cardnumber categorycode surname firstname email phone address citystate); my @item_fields = qw(itemnumber barcode date_due); diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index 5903659..0475f7e 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -36,6 +36,7 @@ use C4::Letters; use C4::Templates; use File::Spec; use Getopt::Long; +use C4::Log; sub usage { print STDERR <new(); my @all_messages = @{ GetPrintMessages() }; exit unless (@all_messages); diff --git a/misc/cronjobs/holds/auto_unsuspend_holds.pl b/misc/cronjobs/holds/auto_unsuspend_holds.pl index 375c5e7..5adf701 100755 --- a/misc/cronjobs/holds/auto_unsuspend_holds.pl +++ b/misc/cronjobs/holds/auto_unsuspend_holds.pl @@ -30,5 +30,8 @@ BEGIN { # cancel all expired hold requests use C4::Reserves; +use C4::Log; + +logaction("CRONJOBS", 'Run', '', 'auto_unsuspend_holds.pl'); AutoUnsuspendReserves(); diff --git a/misc/cronjobs/holds/build_holds_queue.pl b/misc/cronjobs/holds/build_holds_queue.pl index 9ec9825..dceee1e 100755 --- a/misc/cronjobs/holds/build_holds_queue.pl +++ b/misc/cronjobs/holds/build_holds_queue.pl @@ -16,6 +16,9 @@ BEGIN { } use C4::HoldsQueue qw(CreateQueue); +use C4::Log; + +logaction("CRONJOBS", 'Run', '', 'build_holds_queue.pl'); CreateQueue(); diff --git a/misc/cronjobs/holds/cancel_expired_holds.pl b/misc/cronjobs/holds/cancel_expired_holds.pl index 70a2f59..f2e34e7 100755 --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ b/misc/cronjobs/holds/cancel_expired_holds.pl @@ -30,5 +30,8 @@ BEGIN { # cancel all expired hold requests use C4::Reserves; +use C4::Log; + +logaction("CRONJOBS", 'Run', '', 'cancel_expired_holds.pl'); CancelExpiredReserves(); diff --git a/misc/cronjobs/j2a.pl b/misc/cronjobs/j2a.pl index 75d4da1..fc9e515 100755 --- a/misc/cronjobs/j2a.pl +++ b/misc/cronjobs/j2a.pl @@ -32,6 +32,7 @@ use C4::Context; use C4::Members; use Getopt::Long; use Pod::Usage; +use C4::Log; =head1 NAME @@ -126,6 +127,8 @@ if(not $fromcat && $tocat) { #make sure we've specified the info we need. exit; } +logaction("CRONJOBS", 'Run', '', 'j2a.pl'); + my $dbh=C4::Context->dbh; my @branches = C4::Branch::GetBranches(); #get today's date, format it and subtract upperagelimit diff --git a/misc/cronjobs/longoverdue.pl b/misc/cronjobs/longoverdue.pl index 193aaaf..5d6e64f 100755 --- a/misc/cronjobs/longoverdue.pl +++ b/misc/cronjobs/longoverdue.pl @@ -37,6 +37,7 @@ use C4::Context; use C4::Items; use C4::Circulation qw/LostItem/; use Getopt::Long; +use C4::Log; my $lost; # key=lost value, value=num days. my ($charge, $verbose, $confirm, $quiet); @@ -129,6 +130,8 @@ unless ($confirm) { print "### TEST MODE -- NO ACTIONS TAKEN ###\n"; } +logaction("CRONJOBS", 'Run', '', 'longoverdue.pl'); + # 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)"); diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index e46b3f0..059c201 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -43,11 +43,10 @@ use C4::Debug; use C4::Letters; use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); use C4::Budgets qw(GetCurrency); -use Koha::DateUtils; - use Koha::Borrower::Debarments qw(AddUniqueDebarment); use Koha::DateUtils; use Koha::Calendar; +use C4::Log; =head1 NAME @@ -316,6 +315,8 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; +logaction("CRONJOBS", 'Run', '', 'overdue_notices.pl'); + if ( defined $csvfilename && $csvfilename =~ /^-/ ) { warn qq(using "$csvfilename" as filename, that seems odd); } diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl index c79fea8..e2410ac 100755 --- a/misc/cronjobs/process_message_queue.pl +++ b/misc/cronjobs/process_message_queue.pl @@ -26,6 +26,7 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } use C4::Letters; +use C4::Log; use Getopt::Long; my $username = undef; @@ -60,5 +61,7 @@ ENDUSAGE die $usage if $help; +logaction("CRONJOBS", 'Run', '', 'process_message_queue.pl'); + C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); diff --git a/misc/cronjobs/purge_suggestions.pl b/misc/cronjobs/purge_suggestions.pl index d38a7bf..b0ca13e 100755 --- a/misc/cronjobs/purge_suggestions.pl +++ b/misc/cronjobs/purge_suggestions.pl @@ -32,6 +32,7 @@ BEGIN { use Getopt::Long; use Pod::Usage; use C4::Suggestions; +use C4::Log; my ($help, $days); @@ -55,6 +56,7 @@ EOF } if($days){ + logaction("CRONJOBS", 'Run', '', 'purge_suggestions.pl with '. $days . ' days'); DelSuggestionsOlderThan($days); } diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index 9dc6c58..159a5fa 100755 --- a/misc/cronjobs/runreport.pl +++ b/misc/cronjobs/runreport.pl @@ -24,6 +24,7 @@ use warnings; use C4::Reports::Guided; # 0.12 use C4::Context; use Koha::Email; +use C4::Log; use Getopt::Long qw(:config auto_help auto_version); use Pod::Usage; @@ -189,6 +190,8 @@ pod2usage( -verbose => 2 ) if ($man); pod2usage( -verbose => 2 ) if ($help and $verbose); pod2usage(1) if $help; +logaction("CRONJOBS", 'Run', '', 'runreport.pl'); + unless ($format) { $verbose and print STDERR "No format specified, assuming 'text'\n"; $format = 'text'; diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index 6ac5558..48cc8fc 100755 --- a/misc/cronjobs/serialsUpdate.pl +++ b/misc/cronjobs/serialsUpdate.pl @@ -32,6 +32,7 @@ use C4::Context; use C4::Dates qw/format_date format_date_in_iso/; use C4::Debug; use C4::Serials; +use C4::Log; use Date::Calc qw/Date_to_Days check_date/; use Getopt::Long; @@ -77,6 +78,8 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; +logaction("CRONJOBS", 'Run', '', 'serialsUpdate.pl'); + $verbose and !$confirm and print "### Database will not be modified ###\n"; if ( $note && $nonote ) { diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl index b26300b..4e2184d 100755 --- a/misc/cronjobs/share_usage_with_koha_community.pl +++ b/misc/cronjobs/share_usage_with_koha_community.pl @@ -7,6 +7,7 @@ use Getopt::Long; use C4::Context; use C4::UsageStats; +use C4::Log; use POSIX qw(strftime); my ( $help, $verbose, $force ); @@ -30,6 +31,8 @@ If your library wants to share their usage statistics with the Koha community, y exit 1; } +logaction("CRONJOBS", 'Run', '', 'share_usage_with_koha_community.pl'); + my $need_update = ($force ? 1 : C4::UsageStats::NeedUpdate() ); if ($need_update) { diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index d8d406d..272084a 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -43,6 +43,7 @@ use C4::Overdues; use C4::Calendar qw(); # don't need any exports from Calendar use C4::Biblio; use C4::Debug; # supplying $debug and $cgi_debug +use C4::Log; use Getopt::Long; use List::MoreUtils qw/none/; use Koha::DateUtils; @@ -90,6 +91,8 @@ This script has the following parameters : ENDUSAGE die $usage if $help; +logaction("CRONJOBS", 'Run', '', 'staticfines.pl'); + my $dbh = C4::Context->dbh; # Processing categories diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index ba29225..7bdc207 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -32,6 +32,7 @@ use Getopt::Long; use Pod::Usage; use C4::Context; use C4::Biblio; +use C4::Log; use DateTime; use DateTime::Format::MySQL; use Time::HiRes qw/time/; @@ -94,6 +95,8 @@ if ( not $result or $want_help ) { usage(); } +logaction("CRONJOBS", 'Run', '', 'update_totalissues.pl'); + my $dbh = C4::Context->dbh; $dbh->{AutoCommit} = 0; -- 2.3.5