function UpdateCronHooks::notify

Same name and namespace in other branches
  1. main core/modules/update/src/Hook/UpdateCronHooks.php \Drupal\update\Hook\UpdateCronHooks::notify()

Performs 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.

Return value

bool TRUE if any notifications were sent, otherwise FALSE.

See also

Drupal\update\Hook\UpdateRequirements::runtime()

1 call to UpdateCronHooks::notify()
UpdateCronHooks::cron in core/modules/update/src/Hook/UpdateCronHooks.php
Implements hook_cron().

File

core/modules/update/src/Hook/UpdateCronHooks.php, line 92

Class

UpdateCronHooks
Hook implementations for update.

Namespace

Drupal\update\Hook

Code

protected function notify() : bool {
  $update_config = $this->configFactory
    ->get('update.settings');
  $notify_all = $update_config->get('notification.threshold') == 'all';
  $recipients = $update_config->get('notification.emails');
  if (empty($recipients)) {
    return FALSE;
  }
  $status = $this->moduleHandler
    ->invoke('update', 'runtime_requirements');
  $items = [];
  foreach ([
    'core',
    'contrib',
  ] as $report_type) {
    $type = 'update_' . $report_type;
    if (isset($status[$type]['severity']) && ($status[$type]['severity'] == RequirementSeverity::Error || $notify_all && $status[$type]['reason'] == UpdateManagerInterface::NOT_CURRENT)) {
      $items[$report_type] = $status[$type]['reason'];
    }
  }
  if (empty($items)) {
    return FALSE;
  }
  return ($this->mailHandler)()
    ->sendUpdateNotifications($recipients, $items);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.