From: Eileen McNaughton Date: Mon, 13 Jul 2020 20:58:23 +0000 (+1200) Subject: Merge pull request #17800 from colemanw/cronCheck X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=499c92f6bb9dbcae93d62246eb0d837f38aee101;p=civicrm-core.git Merge pull request #17800 from colemanw/cronCheck CheckEnv - Give new installs a grace period before 'Cron Not Running' msg --- 499c92f6bb9dbcae93d62246eb0d837f38aee101 diff --cc CRM/Utils/Check/Component/Env.php index 132ecca536,4ca5c9ea43..eddcfad66d --- a/CRM/Utils/Check/Component/Env.php +++ b/CRM/Utils/Check/Component/Env.php @@@ -280,34 -265,43 +281,48 @@@ class CRM_Utils_Check_Component_Env ext public function checkLastCron() { $messages = []; + // Cron doesn't work in non-production environments; skip. + if (CRM_Core_Config::environment() != 'Production') { + return $messages; + } + $statusPreference = new CRM_Core_DAO_StatusPreference(); $statusPreference->domain_id = CRM_Core_Config::domainID(); - $statusPreference->name = 'checkLastCron'; + $statusPreference->name = __FUNCTION__; + $level = \Psr\Log\LogLevel::INFO; + $now = gmdate('U'); + + // Get timestamp of last cron run if ($statusPreference->find(TRUE) && !empty($statusPreference->check_info)) { - $lastCron = $statusPreference->check_info; - $msg = ts('Last cron run at %1.', [1 => CRM_Utils_Date::customFormat(date('c', $lastCron))]); + $msg = ts('Last cron run at %1.', [1 => CRM_Utils_Date::customFormat(date('c', $statusPreference->check_info))]); } + // If cron record doesn't exist, this is a new install. Make a placeholder record (prefs='new'). else { - $lastCron = 0; - $msg = ts('No cron runs have been recorded.'); + $statusPreference = CRM_Core_BAO_StatusPreference::create([ + 'name' => __FUNCTION__, + 'check_info' => $now, + 'prefs' => 'new', + ]); } + $lastCron = $statusPreference->check_info; - if ($lastCron > gmdate('U') - 3600) { - $messages[] = new CRM_Utils_Check_Message( - __FUNCTION__, - $msg, - ts('Cron Running OK'), - \Psr\Log\LogLevel::INFO, - 'fa-clock-o' - ); + if ($statusPreference->prefs !== 'new' && $lastCron > $now - 3600) { + $title = ts('Cron Running OK'); } else { + // If placeholder record found, give one day "grace period" for admin to set-up cron + if ($statusPreference->prefs === 'new') { + $title = ts('Set-up Cron'); + $msg = ts('No cron runs have been recorded.'); + // After 1 day (86400 seconds) increase the error level + $level = ($lastCron > $now - 86400) ? \Psr\Log\LogLevel::NOTICE : \Psr\Log\LogLevel::WARNING; + } + else { + $title = ts('Cron Not Running'); + // After 1 day (86400 seconds) increase the error level + $level = ($lastCron > $now - 86400) ? \Psr\Log\LogLevel::WARNING : \Psr\Log\LogLevel::ERROR; + } $cronLink = 'target="_blank" href="' . htmlentities(CRM_Utils_System::docURL2('sysadmin/setup/jobs/', TRUE)) . '""'; $msg .= '

' . ts('To enable scheduling support, please set up the cron job.', [ 1 => $cronLink,