diff --git a/automatic_updates_extensions/src/Form/UpdateReady.php b/automatic_updates_extensions/src/Form/UpdateReady.php index 76af9c14c6783c3e901b8559045741e59821c097..35f27ea5ec9463e8185869274d813cb8af4234ca 100644 --- a/automatic_updates_extensions/src/Form/UpdateReady.php +++ b/automatic_updates_extensions/src/Form/UpdateReady.php @@ -2,6 +2,7 @@ namespace Drupal\automatic_updates_extensions\Form; +use Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator; use Drupal\automatic_updates_extensions\BatchProcessor; use Drupal\automatic_updates\BatchProcessor as AutoUpdatesBatchProcessor; use Drupal\automatic_updates_extensions\ExtensionUpdater; @@ -44,6 +45,13 @@ final class UpdateReady extends FormBase { */ protected $moduleList; + /** + * The staged database update validator service. + * + * @var \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator + */ + protected $stagedDatabaseUpdateValidator; + /** * Constructs a new UpdateReady object. * @@ -55,12 +63,15 @@ final class UpdateReady extends FormBase { * The state service. * @param \Drupal\Core\Extension\ModuleExtensionList $module_list * The module list service. + * @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator + * The staged database update validator service. */ - public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list) { + public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator) { $this->updater = $updater; $this->setMessenger($messenger); $this->state = $state; $this->moduleList = $module_list; + $this->stagedDatabaseUpdateValidator = $staged_database_update_validator; } /** @@ -79,6 +90,7 @@ final class UpdateReady extends FormBase { $container->get('messenger'), $container->get('state'), $container->get('extension.list.module'), + $container->get('automatic_updates.validator.staged_database_updates') ); } @@ -96,11 +108,16 @@ final class UpdateReady extends FormBase { $messages = []; - // @todo Add logic to warn about possible new database updates. Determine if - // \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator - // should be duplicated or changed so that it can work with other stages. - // @see \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator - // @see \Drupal\automatic_updates\Form\UpdateReady::buildForm() + // If there are any installed extension with database updates in the staging + // area, warn the user that they might be sent to update.php once the staged + // changes have been applied. + $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater); + if ($pending_updates) { + $messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.'); + foreach ($pending_updates as $pending_update) { + $messages[MessengerInterface::TYPE_WARNING][] = $pending_update; + } + } // Don't set any messages if the form has been submitted, because we don't // want them to be set during form submit. diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php index cde96d5856ed87930e058753ce4b518fdaf1ecf2..eccf389f628e96a670d62380902cc7f9fbd5c5b4 100644 --- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php +++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php @@ -145,6 +145,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Package Manager is bypassed. $this->disableValidators(['automatic_updates.validator.scaffold_file_permissions']); + $this->container->get('theme_installer')->install(['automatic_updates_theme_with_updates']); $this->updateProject = $project_name; $this->setReleaseMetadata(__DIR__ . '/../../../../tests/fixtures/release-history/drupal.9.8.2.xml'); $this->setReleaseMetadata(__DIR__ . "/../../fixtures/release-history/$project_name.1.1.xml"); @@ -168,9 +169,15 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdateStagedTimes(1); // Confirm that the site was put into maintenance mode if needed. $this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on); + $assert_session = $this->assertSession(); + $possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.'; + $assert_session->pageTextContains($possible_update_message); + $assert_session->pageTextContainsOnce('System'); + $assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates'); + $page->pressButton('Continue'); $this->checkForMetaRefresh(); - $assert_session = $this->assertSession(); + $assert_session->addressEquals('/admin/reports/updates'); // Confirm that the site was in maintenance before the update was applied. // @see \Drupal\package_manager_test_validation\EventSubscriber\TestSubscriber::handleEvent()