diff --git a/core/modules/automatic_updates/automatic_updates.install b/core/modules/automatic_updates/automatic_updates.install index c16b2fb3c0..5ec81868c2 100644 --- a/core/modules/automatic_updates/automatic_updates.install +++ b/core/modules/automatic_updates/automatic_updates.install @@ -14,32 +14,21 @@ */ function automatic_updates_requirements($phase) { if ($phase !== 'runtime') { - return NULL; + return []; } $requirements = []; - _automatic_updates_checker_requirements($requirements); - return $requirements; -} - -/** - * Display requirements from results of readiness checker. - * - * @param array $requirements - * The requirements array. - */ -function _automatic_updates_checker_requirements(array &$requirements) { /** @var \Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface $checker */ $checker = \Drupal::service('automatic_updates.readiness_checker'); if (!$checker->isEnabled()) { - return; + return []; } $last_check_timestamp = $checker->timestamp(); $requirements['automatic_updates_readiness'] = [ 'title' => t('Update readiness checks'), 'severity' => REQUIREMENT_OK, - 'value' => t('Your site is ready to for automatic updates.', ['@readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks']), + 'value' => t('Your site is ready to for automatic updates.', [':readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks']), ]; $error_results = $checker->getResults(ReadinessCheckerManagerInterface::ERROR); $warning_results = $checker->getResults(ReadinessCheckerManagerInterface::WARNING); @@ -54,22 +43,22 @@ function _automatic_updates_checker_requirements(array &$requirements) { } if (\Drupal::time()->getRequestTime() > $last_check_timestamp + ReadinessCheckerManagerInterface::LAST_CHECKED_WARNING) { $requirements['automatic_updates_readiness']['severity'] = REQUIREMENT_ERROR; - $requirements['automatic_updates_readiness']['value'] = t('Your site has not recently checked if it is ready to apply automatic updates.', ['@readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks']); + $requirements['automatic_updates_readiness']['value'] = t('Your site has not recently checked if it is ready to apply automatic updates.', [':readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks']); $readiness_check = Url::fromRoute('automatic_updates.update_readiness'); $time_ago = \Drupal::service('date.formatter')->formatTimeDiffSince($last_check_timestamp); if ($last_check_timestamp === 0) { - $requirements['automatic_updates_readiness']['description'] = t('Run readiness checks manually.', [ - '@link' => $readiness_check->toString(), + $requirements['automatic_updates_readiness']['description'] = t('Run readiness checks manually.', [ + ':url' => $readiness_check->toString(), ]); } elseif ($readiness_check->access()) { - $requirements['automatic_updates_readiness']['description'] = t('Last run @time ago. Run readiness checks manually.', [ + $requirements['automatic_updates_readiness']['description'] = t('Last run @time ago. Run readiness checks manually.', [ '@time' => $time_ago, - '@link' => $readiness_check->toString(), + ':link' => $readiness_check->toString(), ]); } else { $requirements['automatic_updates_readiness']['description'] = t('Readiness checks were last run @time ago.', ['@time' => $time_ago]); } - } + }; } diff --git a/core/modules/automatic_updates/automatic_updates.module b/core/modules/automatic_updates/automatic_updates.module index 12574bf49f..b65e7d9039 100644 --- a/core/modules/automatic_updates/automatic_updates.module +++ b/core/modules/automatic_updates/automatic_updates.module @@ -7,6 +7,7 @@ use Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface; use Drupal\Core\Url; + /** * Implements hook_page_top(). */ @@ -14,6 +15,8 @@ function automatic_updates_page_top(array &$page_top) { /** @var \Drupal\Core\Routing\AdminContext $admin_context */ $admin_context = \Drupal::service('router.admin_context'); $route_match = \Drupal::routeMatch(); + // @todo Is 'administer site configuration' the correct permission? + // get feedback from contrib module maintainers. if ($admin_context->isAdminRoute($route_match->getRouteObject()) && \Drupal::currentUser()->hasPermission('administer site configuration')) { $disabled_routes = [ 'update.theme_update', @@ -34,22 +37,22 @@ function automatic_updates_page_top(array &$page_top) { $last_check_timestamp = \Drupal::service('automatic_updates.readiness_checker')->timestamp(); if (\Drupal::time()->getRequestTime() > $last_check_timestamp + ReadinessCheckerManagerInterface::LAST_CHECKED_WARNING) { $readiness_settings = Url::fromRoute('automatic_updates.settings'); - \Drupal::messenger()->addError(t('Your site has not recently run an update readiness check. Administer automatic updates and run readiness checks manually.', [ - '@link' => $readiness_settings->toString(), + \Drupal::messenger()->addError(t('Your site has not recently run an update readiness check. Administer automatic updates and run readiness checks manually.', [ + ':url' => $readiness_settings->toString(), ])); } /** @var \Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface $checker */ $checker = \Drupal::service('automatic_updates.readiness_checker'); $results = $checker->getResults(ReadinessCheckerManagerInterface::ERROR); if ($results) { - \Drupal::messenger()->addError(t('Your site is currently failing readiness checks for automatic updates. It cannot be automatically updated until further action is performed:', ['@readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); + \Drupal::messenger()->addError(t('Your site is currently failing readiness checks for automatic updates. It cannot be automatically updated until further action is performed:', [':readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); foreach ($results as $message) { \Drupal::messenger()->addError($message); } } $results = $checker->getResults('warning'); if ($results) { - \Drupal::messenger()->addWarning(t('Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might effect the eligibility for automatic updates.', ['@readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); + \Drupal::messenger()->addWarning(t('Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might effect the eligibility for automatic updates.', [':readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); foreach ($results as $message) { \Drupal::messenger()->addWarning($message); } diff --git a/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php b/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php index 0976e7bb80..44e015222f 100644 --- a/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php +++ b/core/modules/automatic_updates/src/Controller/ReadinessCheckerController.php @@ -9,6 +9,9 @@ /** * A controller for running Readiness Checkers. + * + * @internal + * Controller classes are internal. */ class ReadinessCheckerController extends ControllerBase { @@ -46,16 +49,16 @@ public static function create(ContainerInterface $container) { * Run the readiness checkers. * * @return \Symfony\Component\HttpFoundation\RedirectResponse - * A redirect response object. + * A redirect to the automatic updates settings page. */ public function run() { $messages = []; foreach ($this->checker->getCategories() as $category) { $messages[] = $this->checker->run($category); } - $messages = array_merge(...$messages); - if (empty($messages)) { - $this->messenger()->addStatus($this->t('No issues found. Your site is ready for automatic updates.', ['@readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); + // Flatten the array and check if it is empty. + if (empty(array_merge(...$messages))) { + $this->messenger()->addStatus($this->t('No issues found. Your site is ready for automatic updates.', [':readiness_checks' => 'https://www.drupal.org/docs/8/update/automatic-updates#readiness-checks'])); } return $this->redirect('automatic_updates.settings'); } diff --git a/core/modules/automatic_updates/src/Form/SettingsForm.php b/core/modules/automatic_updates/src/Form/SettingsForm.php index dc3e8bab83..bde8a08b5b 100644 --- a/core/modules/automatic_updates/src/Form/SettingsForm.php +++ b/core/modules/automatic_updates/src/Form/SettingsForm.php @@ -11,6 +11,7 @@ * Settings form for Automatic Updates. */ class SettingsForm extends ConfigFormBase { + /** * The readiness checker manager. * @@ -94,23 +95,11 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $config->get('enable_readiness_checks'), ]; if ($this->checker->isEnabled()) { - $form['readiness']['enable_readiness_checks']['#description'] = $this->t('Readiness checks were last run @time ago. Manually run the readiness checks.', [ + $form['readiness']['enable_readiness_checks']['#description'] = $this->t('Readiness checks were last run @time ago. Manually run the readiness checks.', [ '@time' => $this->dateFormatter->formatTimeDiffSince($last_check_timestamp), - '@link' => Url::fromRoute('automatic_updates.update_readiness')->toString(), + ':url' => Url::fromRoute('automatic_updates.update_readiness')->toString(), ]); } - $form['readiness']['ignored_paths'] = [ - '#type' => 'textarea', - '#title' => $this->t('Paths to ignore for readiness checks'), - '#description' => $this->t('Paths relative to %drupal_root. One path per line. Automatic Updates is intentionally limited to Drupal core. It is recommended to ignore paths to contrib extensions.', ['%drupal_root' => $this->drupalRoot]), - '#default_value' => $config->get('ignored_paths'), - '#states' => [ - 'visible' => [ - ':input[name="enable_readiness_checks"]' => ['checked' => TRUE], - ], - ], - ]; - return parent::buildForm($form, $form_state); } diff --git a/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php b/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php index 82d86eef5e..70afc80661 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/DiskSpace.php @@ -7,7 +7,7 @@ /** * The disk space readiness checker. */ -class DiskSpace extends Filesystem { +class DiskSpace extends FilesystemBase { /** * Minimum disk space (in bytes) is 10mb. diff --git a/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php b/core/modules/automatic_updates/src/ReadinessChecker/FilesystemBase.php similarity index 96% rename from core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php rename to core/modules/automatic_updates/src/ReadinessChecker/FilesystemBase.php index 48eb4b87c8..77f644a2ac 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/Filesystem.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/FilesystemBase.php @@ -7,7 +7,7 @@ /** * Base class for filesystem checkers. */ -abstract class Filesystem implements ReadinessCheckerInterface { +abstract class FilesystemBase implements ReadinessCheckerInterface { use StringTranslationTrait; /** diff --git a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php index b656943f30..97585e056f 100644 --- a/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php +++ b/core/modules/automatic_updates/src/ReadinessChecker/ReadinessCheckerManagerInterface.php @@ -30,7 +30,9 @@ interface ReadinessCheckerManagerInterface { * @param string $category * (optional) The category of check. * @param int $priority - * (optional) The priority of the checker being added. + * (optional) The priority of the checker being added. If not provided the + * default priority is 0. Readiness checkers with larger priorities will run + * first within a category. * * @return $this */ diff --git a/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php b/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php index 7efc53affe..d1097de1cc 100644 --- a/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php +++ b/core/modules/automatic_updates/tests/src/Kernel/ReadinessChecker/DiskSpaceTest.php @@ -42,12 +42,12 @@ public function testDiskSpace() { } /** - * Class TestDiskSpace. + * Test checker with the free disk space minimum set to an insanely high number. */ class TestDiskSpace extends DiskSpace { /** - * Override the default free disk space minimum to an insanely high number. + * {@inheritdoc} */ const MINIMUM_DISK_SPACE = 99999999999999999999999999999999999999999999999999;