From: Andrew Hunt Date: Sun, 26 Apr 2015 23:34:59 +0000 (-0400) Subject: CRM-13823 Status check for last cron run X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=aa96ce6245521f6e34bf61ff1e8361a521377587;p=civicrm-core.git CRM-13823 Status check for last cron run ---------------------------------------- * CRM-13823: Admin Status Page https://issues.civicrm.org/jira/browse/CRM-13823 --- diff --git a/CRM/Core/BAO/StatusPreference.php b/CRM/Core/BAO/StatusPreference.php index 09cf4abd7f..3b402b5c43 100644 --- a/CRM/Core/BAO/StatusPreference.php +++ b/CRM/Core/BAO/StatusPreference.php @@ -49,10 +49,8 @@ class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { $statusPreference = new CRM_Core_DAO_StatusPreference(); if (empty($params['id']) && CRM_Utils_Array::value('name', $params)) { - $searchParams = array( - 'domain_id' => CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()), - 'name' => $params['name'], - ); + $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); + $statusPreference->name = $params['name']; $statusPreference->find(TRUE); } diff --git a/CRM/Core/JobManager.php b/CRM/Core/JobManager.php index 732facc95c..38279bad65 100644 --- a/CRM/Core/JobManager.php +++ b/CRM/Core/JobManager.php @@ -85,6 +85,13 @@ class CRM_Core_JobManager { } } $this->logEntry('Finishing scheduled jobs execution.'); + + // Set last cron date for the status check + $statusPref = array( + 'name' => 'checkLastCron', + 'check_info' => gmdate('U'), + ); + CRM_Core_BAO_StatusPreference::create($statusPref); } /** diff --git a/CRM/Utils/Check/Env.php b/CRM/Utils/Check/Env.php index 4e82f05f8d..7d176ce1b8 100644 --- a/CRM/Utils/Check/Env.php +++ b/CRM/Utils/Check/Env.php @@ -45,7 +45,8 @@ class CRM_Utils_Check_Env { $this->checkDebug(), $this->checkOutboundMail(), $this->checkDomainNameEmail(), - $this->checkDefaultMailbox() + $this->checkDefaultMailbox(), + $this->checkLastCron() ); return $messages; } @@ -174,7 +175,7 @@ class CRM_Utils_Check_Env { ) { $message = new CRM_Utils_Check_Message( 'checkDefaultMailbox', - ts('Please configure a default mailbox for CiviMail.', + ts('Please configure a default mailbox for CiviMail.', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))), ts('Configure Default Mailbox'), \Psr\Log\LogLevel::WARNING @@ -185,4 +186,53 @@ class CRM_Utils_Check_Env { return $messages; } + + /** + * Checks if cron has run in a reasonable amount of time + * @return array + */ + + public function checkLastCron() { + $messages = array(); + + $statusPreference = new CRM_Core_DAO_StatusPreference(); + $statusPreference->domain_id = CRM_Core_Config::domainID(); + $statusPreference->name = 'checkLastCron'; + + $statusPreference->find(TRUE); + + $lastCron = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StatusPreference', $statusPreference->id, 'check_info'); + + $msg = ts('Last cron run at %1', array(1 => CRM_Utils_Date::customFormat(date('c', $lastCron)))); + if ($lastCron > gmdate('U') - 3600) { + $messages[] = new CRM_Utils_Check_Message( + 'checkLastCron', + $msg, + ts('Cron Running OK'), + \Psr\Log\LogLevel::INFO + ); + } + elseif ($lastCron > gmdate('U') - 86400) { + $message = new CRM_Utils_Check_Message( + 'checkLastCron', + $msg, + ts('Cron Not Running'), + \Psr\Log\LogLevel::WARNING + ); + $message->addHelp(ts('Learn more in the Administrator\'s Guide supplement', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/'))); + $messages[] = $message; + } + elseif ($lastCron <= gmdate('U') - 86400) { + $message = new CRM_Utils_Check_Message( + 'checkLastCron', + $msg, + ts('Cron Not Running'), + \Psr\Log\LogLevel::ERROR + ); + $message->addHelp(ts('Learn more in the Administrator\'s Guide supplement', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/'))); + $messages[] = $message; + } + + return $messages; + } }