Drupal investigation

update.fetch.inc 1.8KB

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