CRM-13823 Status check for last cron run
authorAndrew Hunt <andrew@aghstrategies.com>
Sun, 26 Apr 2015 23:34:59 +0000 (19:34 -0400)
committerJon goldberg <jon@palantetech.coop>
Tue, 21 Jul 2015 20:37:37 +0000 (16:37 -0400)
----------------------------------------
* CRM-13823: Admin Status Page
  https://issues.civicrm.org/jira/browse/CRM-13823

CRM/Core/BAO/StatusPreference.php
CRM/Core/JobManager.php
CRM/Utils/Check/Env.php

index 09cf4abd7f3cc3dc396d23d7f41f64d8bbec6ae1..3b402b5c43d2ff676f9a65ecb10726daff8c6ff4 100644 (file)
@@ -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);
     }
index 732facc95cc759f8782a68cd66616c7c16f62a99..38279bad6525fdc8177945dfe3e23fc3d6e3c282 100644 (file)
@@ -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);
   }
 
   /**
index 4e82f05f8d19e3390d2bf0677ebc46af9415ee85..7d176ce1b85fba42245ea8854ebe91284fc5dc4e 100644 (file)
@@ -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 <a href="%1">default mailbox</a> 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 <a href="%1">Administrator\'s Guide supplement</a>', 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 <a href="%1">Administrator\'s Guide supplement</a>', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/')));
+      $messages[] = $message;
+    }
+
+    return $messages;
+  }
 }