From ff13ae5906ddcdd3b016f4edbf8590b8fd157af2 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Tue, 8 Jan 2019 12:14:57 +0000 Subject: [PATCH] MDL-64454 Admin: Configuration option for cron frequency warning This change makes the warning time (default 200 seconds) configurable in config.php. --- admin/index.php | 3 ++- admin/renderer.php | 5 ++++- config-dist.php | 6 ++++++ lang/en/admin.php | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/admin/index.php b/admin/index.php index c9ce18a9496..c34a437d9c6 100644 --- a/admin/index.php +++ b/admin/index.php @@ -826,7 +826,8 @@ $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); $lastcron = get_config('tool_task', 'lastcronstart'); $cronoverdue = ($lastcron < time() - 3600 * 24); $lastcroninterval = get_config('tool_task', 'lastcroninterval'); -$croninfrequent = !$cronoverdue && ($lastcroninterval > 200 || $lastcron < time() - 200); +$expectedfrequency = $CFG->expectedcronfrequency ?? 200; +$croninfrequent = !$cronoverdue && ($lastcroninterval > $expectedfrequency || $lastcron < time() - $expectedfrequency); $dbproblems = $DB->diagnose(); $maintenancemode = !empty($CFG->maintenance_enabled); diff --git a/admin/renderer.php b/admin/renderer.php index 8f5ea38332e..57eaa0efc07 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -623,11 +623,14 @@ class core_admin_renderer extends plugin_renderer_base { * @return string HTML to output. */ public function cron_infrequent_warning(bool $croninfrequent) : string { + global $CFG; + if (!$croninfrequent) { return ''; } - return $this->warning(get_string('croninfrequent', 'admin') . ' ' . + $expectedfrequency = $CFG->expectedcronfrequency ?? 200; + return $this->warning(get_string('croninfrequent', 'admin', $expectedfrequency) . ' ' . $this->help_icon('cron', 'admin')); } diff --git a/config-dist.php b/config-dist.php index 18cbe311524..8cf7998ba68 100644 --- a/config-dist.php +++ b/config-dist.php @@ -599,6 +599,12 @@ $CFG->admin = 'admin'; // // $CFG->disablelogintoken = true; // +// Moodle 3.7+ checks that cron is running frequently. If the time between cron runs +// is greater than this value (in seconds), you get a warning on the admin page. (This +// setting only controls whether or not the warning appears, it has no other effect.) +// +// $CFG->expectedcronfrequency = 200; +// //========================================================================= // 7. SETTINGS FOR DEVELOPMENT SERVERS - not intended for production use!!! //========================================================================= diff --git a/lang/en/admin.php b/lang/en/admin.php index f552fcc4334..98040a5cd69 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -416,10 +416,10 @@ $string['cron_link'] = 'admin/cron'; $string['cronclionly'] = 'Cron execution via command line only'; $string['cronerrorclionly'] = 'Sorry, internet access to this page has been disabled by the administrator.'; $string['cronerrorpassword'] = 'Sorry, you have not provided a valid password to access this page'; +$string['croninfrequent'] = 'The time between the last two runs of the cron maintenance script was over {$a} seconds. We recommend configuring it to run more frequently.'; $string['cronremotepassword'] = 'Cron password for remote access'; $string['cronwarning'] = 'The cron.php maintenance script has not been run for at least 24 hours.'; $string['cronwarningcli'] = 'The cli/cron.php maintenance script has not been run for at least 24 hours.'; -$string['croninfrequent'] = 'The time between the last two runs of the cron maintenance script was over 3 minutes. We recommend configuring it to run more frequently.'; $string['ctyperequired'] = 'The ctype PHP extension is now required by Moodle, in order to improve site performance and to offer multilingual compatibility.'; $string['curlsecurityallowedport'] = 'cURL allowed ports list'; $string['curlsecurityallowedportsyntax'] = 'List of port numbers that cURL can connect to. Valid entries are integer numbers only. Put each entry on a new line. If left empty, then all ports are allowed. If set, in almost all cases, both 443 and 80 should be specified for cURL to connect to standard HTTPS and HTTP ports.';