diff --git a/CRM/Utils/Check/Component/Env.php b/CRM/Utils/Check/Component/Env.php index c1d7b767944f..3ee6ef1ec148 100644 --- a/CRM/Utils/Check/Component/Env.php +++ b/CRM/Utils/Check/Component/Env.php @@ -688,6 +688,54 @@ public function checkExtensions() { return $messages; } + /** + * @return CRM_Utils_Check_Message[] + */ + public function checkScheduledJobLogErrors() { + $jobs = civicrm_api3('Job', 'get', [ + 'sequential' => 1, + 'return' => ["id", "name", "last_run"], + 'is_active' => 1, + 'options' => ['limit' => 0], + ]); + $html = ''; + foreach ($jobs['values'] as $job) { + $lastExecutionMessage = civicrm_api3('JobLog', 'get', [ + 'sequential' => 1, + 'return' => ["description"], + 'job_id' => $job['id'], + 'options' => ['sort' => "id desc", 'limit' => 1], + ])['values'][0]['description'] ?? NULL; + if (!empty($lastExecutionMessage) && strpos($lastExecutionMessage, 'Failure') !== FALSE) { + $viewLogURL = CRM_Utils_System::url('civicrm/admin/joblog', "jid={$job['id']}&reset=1"); + $html .= ' + ' . $job['name'] . ' + ' . $lastExecutionMessage . ' + ' . $job['last_run'] . ' + ' . ts('View Job Log') . ' + '; + } + } + if (empty($html)) { + return []; + } + + $message = '

' . ts('The following scheduled jobs failed on the last run:') . '

+

+ ' . $html . ' +
' . ts('Job') . '' . ts('Message') . '' . ts('Last Run') . '

'; + + $msg = new CRM_Utils_Check_Message( + __FUNCTION__, + $message, + ts('Scheduled Job Failures'), + \Psr\Log\LogLevel::WARNING, + 'fa-server' + ); + $messages[] = $msg; + return $messages; + } + /** * Checks if there are pending extension upgrades. *