Commit 0d680aae authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3316611 by phenaproxima, tedbow: If unattended updates are enabled,...

Issue #3316611 by phenaproxima, tedbow: If unattended updates are enabled, send an email when status checks start failing
parent cb11dd23
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

use Drupal\automatic_updates\BatchProcessor;
use Drupal\automatic_updates\CronUpdater;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\automatic_updates\Validation\AdminStatusCheckMessages;
use Drupal\Core\Url;
@@ -95,6 +96,16 @@ function automatic_updates_mail(string $key, array &$message, array $params): vo
      }
    }
  }
  elseif ($key === 'status_check_failed') {
    $message['subject'] = t('Automatic updates readiness checks failed', [], $options);

    $url = Url::fromRoute('system.status')
      ->setAbsolute()
      ->toString();
    $message['body'][] = t('Your site has failed some readiness checks for automatic updates and may not be able to receive automatic updates until further action is taken. Please visit @url for more information.', [
      '@url' => $url,
    ], $options);
  }

  // If this email was related to an unattended update, explicitly state that
  // this isn't supported yet.
@@ -153,7 +164,9 @@ function automatic_updates_module_implements_alter(&$implementations, $hook) {
 * Implements hook_cron().
 */
function automatic_updates_cron() {
  \Drupal::service('automatic_updates.cron_updater')->handleCron();
  /** @var \Drupal\automatic_updates\CronUpdater $updater */
  $updater = \Drupal::service('automatic_updates.cron_updater');
  $updater->handleCron();

  /** @var \Drupal\automatic_updates\Validation\StatusChecker $status_checker */
  $status_checker = \Drupal::service('automatic_updates.status_checker');
@@ -165,6 +178,11 @@ function automatic_updates_cron() {
    $status_checker->run();
  }

  // Only try to send failure notifications if unattended updates are enabled.
  if ($updater->getMode() !== CronUpdater::DISABLED) {
    \Drupal::service('automatic_updates.status_check_mailer')
      ->sendFailureNotifications($last_results, $status_checker->getResults());
  }
}

/**
+18 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains post-update hooks for Automatic Updates.
 */

use Drupal\automatic_updates\StatusCheckMailer;

/**
 * Creates the automatic_updates.settings:status_check_mail config.
 */
function automatic_updates_post_update_create_status_check_mail_config(): void {
  \Drupal::configFactory()
    ->getEditable('automatic_updates.settings')
    ->set('status_check_mail', StatusCheckMailer::ERRORS_ONLY)
    ->save();
}
+7 −1
Original line number Diff line number Diff line
@@ -14,6 +14,12 @@ services:
      - 24
    tags:
      - { name: event_subscriber }
  automatic_updates.status_check_mailer:
    class: Drupal\automatic_updates\StatusCheckMailer
    arguments:
      - '@config.factory'
      - '@plugin.manager.mail'
      - '@language_manager'
  automatic_updates.readiness_validation_manager:
    class: Drupal\automatic_updates\Validation\ReadinessValidationManager
    arguments:
@@ -41,7 +47,7 @@ services:
      - '@automatic_updates.release_chooser'
      - '@logger.factory'
      - '@plugin.manager.mail'
      - '@language_manager'
      - '@automatic_updates.status_check_mailer'
      - '@state'
      - '@config.factory'
      - '@package_manager.path_locator'
+1 −0
Original line number Diff line number Diff line
cron: security
allow_core_minor_updates: false
status_check_mail: errors_only
+3 −0
Original line number Diff line number Diff line
@@ -11,3 +11,6 @@ automatic_updates.settings:
    allow_core_minor_updates:
      type: boolean
      label: 'Allow minor level Drupal core updates'
    status_check_mail:
      type: string
      label: 'Whether to send status check failure e-mail notifications during cron'
Loading