From 32a13379001ac8c57449020debddd2a2cf7b8117 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Tue, 7 Jan 2025 10:15:58 +0000 Subject: [PATCH] Issue #2422681 by berdir, catch, ressa, nicxvan, alexpott, longwave: Remove the automatic cron run from the installer --- core/includes/install.core.inc | 5 ----- core/modules/system/src/Form/CronForm.php | 7 ++++++- .../tests/src/Functional/System/CronRunTest.php | 14 ++++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index f91937b07007..03074c610254 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1910,11 +1910,6 @@ function install_finished(&$install_state) { // installer does not use an HttpKernel, that event is never triggered. \Drupal::service('router.builder')->rebuild(); - // Run cron to populate update status tables (if available) so that users - // will be warned if they've installed an out of date Drupal version. - // Will also trigger indexing of profile-supplied content or feeds. - \Drupal::service('cron')->run(); - if ($install_state['interactive']) { // Load current user and perform final login tasks. // This has to be done after drupal_flush_all_caches() diff --git a/core/modules/system/src/Form/CronForm.php b/core/modules/system/src/Form/CronForm.php index 88db943d8fd2..ee40fb535833 100644 --- a/core/modules/system/src/Form/CronForm.php +++ b/core/modules/system/src/Form/CronForm.php @@ -111,7 +111,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t('Run cron'), '#submit' => ['::runCron'], ]; - $status = '<p>' . $this->t('Last run: %time ago.', ['%time' => $this->dateFormatter->formatTimeDiffSince($this->state->get('system.cron_last'))]) . '</p>'; + if ($time_ago = $this->state->get('system.cron_last')) { + $status = '<p>' . $this->t('Last run: %time ago.', ['%time' => $this->dateFormatter->formatTimeDiffSince($time_ago)]) . '</p>'; + } + else { + $status = '<p>' . $this->t('Last run: never') . '</p>'; + } $form['status'] = [ '#markup' => $status, ]; diff --git a/core/modules/system/tests/src/Functional/System/CronRunTest.php b/core/modules/system/tests/src/Functional/System/CronRunTest.php index 6fdd0ff9d083..a5885a660dfe 100644 --- a/core/modules/system/tests/src/Functional/System/CronRunTest.php +++ b/core/modules/system/tests/src/Functional/System/CronRunTest.php @@ -120,11 +120,17 @@ public function testCronExceptions(): void { public function testCronUI(): void { $admin_user = $this->drupalCreateUser(['administer site configuration']); $this->drupalLogin($admin_user); + \Drupal::state()->delete('system.cron_last'); $this->drupalGet('admin/config/system/cron'); - // Don't use REQUEST to calculate the exact time, because that will - // fail randomly. Look for the word 'years', because without a timestamp, - // the time will start at 1 January 1970. - $this->assertSession()->pageTextNotContains('years'); + // Check that cron has never run. + $this->assertSession()->pageTextContains('Last run: never'); + + // Now check that it has run. + // Sleep to allow cron time to complete since it happens during kernel + // terminate after the page response is set. + sleep(3); + $this->drupalGet('admin/config/system/cron'); + $this->assertSession()->pageTextNotContains('Last run: never'); $cron_last = time() - 200; \Drupal::state()->set('system.cron_last', $cron_last); -- GitLab