annotate core/modules/update/update.fetch.inc @ 19:fa3358dc1485 tip

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