Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/update/update.fetch.inc @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Code required only when fetching information about available updates. | |
6 */ | |
7 | |
8 /** | |
9 * Performs any notifications that should be done once cron fetches new data. | |
10 * | |
11 * This method checks the status of the site using the new data and, depending | |
12 * on the configuration of the site, notifies administrators via email if there | |
13 * are new releases or missing security updates. | |
14 * | |
15 * @see update_requirements() | |
16 */ | |
17 function _update_cron_notify() { | |
18 $update_config = \Drupal::config('update.settings'); | |
19 module_load_install('update'); | |
20 $status = update_requirements('runtime'); | |
21 $params = []; | |
22 $notify_all = ($update_config->get('notification.threshold') == 'all'); | |
23 foreach (['core', 'contrib'] as $report_type) { | |
24 $type = 'update_' . $report_type; | |
25 if (isset($status[$type]['severity']) | |
26 && ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) { | |
27 $params[$report_type] = $status[$type]['reason']; | |
28 } | |
29 } | |
30 if (!empty($params)) { | |
31 $notify_list = $update_config->get('notification.emails'); | |
32 if (!empty($notify_list)) { | |
33 $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); | |
34 foreach ($notify_list as $target) { | |
35 if ($target_user = user_load_by_mail($target)) { | |
36 $target_langcode = $target_user->getPreferredLangcode(); | |
37 } | |
38 else { | |
39 $target_langcode = $default_langcode; | |
40 } | |
41 $message = \Drupal::service('plugin.manager.mail')->mail('update', 'status_notify', $target, $target_langcode, $params); | |
42 // Track when the last mail was successfully sent to avoid sending | |
43 // too many emails. | |
44 if ($message['result']) { | |
45 \Drupal::state()->set('update.last_email_notification', REQUEST_TIME); | |
46 } | |
47 } | |
48 } | |
49 } | |
50 } |