2007-07-11 15:15:40 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Code required only when fetching information about available updates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-06-06 15:33:53 +00:00
|
|
|
* Performs any notifications that should be done once cron fetches new data.
|
2007-07-11 15:15:40 +00:00
|
|
|
*
|
2012-06-06 15:33:53 +00:00
|
|
|
* This method checks the status of the site using the new data and, depending
|
2014-06-09 21:47:53 +00:00
|
|
|
* on the configuration of the site, notifies administrators via email if there
|
2007-07-11 15:15:40 +00:00
|
|
|
* are new releases or missing security updates.
|
|
|
|
*
|
|
|
|
* @see update_requirements()
|
|
|
|
*/
|
|
|
|
function _update_cron_notify() {
|
2013-09-16 03:58:06 +00:00
|
|
|
$update_config = \Drupal::config('update.settings');
|
2009-12-29 07:21:34 +00:00
|
|
|
module_load_install('update');
|
2007-07-11 15:15:40 +00:00
|
|
|
$status = update_requirements('runtime');
|
2017-03-04 01:20:24 +00:00
|
|
|
$params = [];
|
2012-08-03 16:52:07 +00:00
|
|
|
$notify_all = ($update_config->get('notification.threshold') == 'all');
|
2017-03-04 01:20:24 +00:00
|
|
|
foreach (['core', 'contrib'] as $report_type) {
|
2008-04-14 17:48:46 +00:00
|
|
|
$type = 'update_' . $report_type;
|
2007-07-11 15:15:40 +00:00
|
|
|
if (isset($status[$type]['severity'])
|
2009-04-29 03:57:21 +00:00
|
|
|
&& ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) {
|
2007-07-11 15:15:40 +00:00
|
|
|
$params[$report_type] = $status[$type]['reason'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($params)) {
|
2012-08-03 16:52:07 +00:00
|
|
|
$notify_list = $update_config->get('notification.emails');
|
2007-07-11 15:15:40 +00:00
|
|
|
if (!empty($notify_list)) {
|
2014-10-13 09:10:32 +00:00
|
|
|
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
|
2007-07-11 15:15:40 +00:00
|
|
|
foreach ($notify_list as $target) {
|
2009-03-14 23:01:38 +00:00
|
|
|
if ($target_user = user_load_by_mail($target)) {
|
2013-07-09 13:46:44 +00:00
|
|
|
$target_langcode = $target_user->getPreferredLangcode();
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-09-13 08:48:24 +00:00
|
|
|
$target_langcode = $default_langcode;
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
2014-12-11 17:08:56 +00:00
|
|
|
$message = \Drupal::service('plugin.manager.mail')->mail('update', 'status_notify', $target, $target_langcode, $params);
|
2012-06-14 04:58:22 +00:00
|
|
|
// Track when the last mail was successfully sent to avoid sending
|
2014-06-09 21:47:53 +00:00
|
|
|
// too many emails.
|
2012-06-14 04:58:22 +00:00
|
|
|
if ($message['result']) {
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::state()->set('update.last_email_notification', REQUEST_TIME);
|
2012-06-14 04:58:22 +00:00
|
|
|
}
|
2007-07-11 15:15:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|