You are here

function _update_status_cron_notify in Update Status 5.2

Perform any notifications that should be done once cron fetches new data.

This method checks the status of the site using the new data and depending on the configuration of the site, notifies administrators via email if there are new releases or missing security updates.

See also

update_status_requirements()

1 call to _update_status_cron_notify()
update_status_cron in ./update_status.module
Implementation of hook_cron().

File

./update_status.module, line 536

Code

function _update_status_cron_notify() {
  $status = update_status_requirements('runtime');
  $notify_all = variable_get('update_status_notification_threshold', 'all') == 'all';
  $body = array();
  foreach (array(
    'core',
    'contrib',
  ) as $report_type) {
    $type = 'update_status_' . $report_type;
    if (isset($status[$type]['severity']) && ($status[$type]['severity'] == REQUIREMENT_ERROR || $notify_all && $status[$type]['reason'] == UPDATE_STATUS_NOT_CURRENT)) {
      $body[] = wordwrap(_update_status_message_text($report_type, $status[$type]['reason'], FALSE));
    }
  }
  if (!empty($body)) {
    $notify_list = variable_get('update_status_notify_emails', '');
    if (!empty($notify_list)) {
      $body[] = t('See the available updates page for more information:') . "\n" . url('admin/logs/updates', NULL, NULL, TRUE) . "\n\n";
      $subject = t('New release(s) available for !site_name', array(
        '!site_name' => variable_get('site_name', 'Drupal'),
      ));
      $body_text = implode("\n\n", $body);
      foreach ($notify_list as $target) {
        drupal_mail('update-status', $target, $subject, $body_text);
      }
    }
  }
}