Skip to content
Snippets Groups Projects
Commit 09df1539 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3292933 by tedbow: UpdateReady form also needs to check for updates in themes

parent 812c4756
No related branches found
No related tags found
1 merge request!356Issue #3292933: UpdateREady from also needs to check for updates in themes
...@@ -107,14 +107,14 @@ class UpdateReady extends FormBase { ...@@ -107,14 +107,14 @@ class UpdateReady extends FormBase {
$messages = []; $messages = [];
// If there are any installed modules with database updates in the staging // If there are any installed extensions with database updates in the
// area, warn the user that they might be sent to update.php once the // staging area, warn the user that they might be sent to update.php once
// staged changes have been applied. // the staged changes have been applied.
$pending_updates = $this->getModulesWithStagedDatabaseUpdates(); $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater);
if ($pending_updates) { if ($pending_updates) {
$messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following modules; you may be redirected to the database update page in order to complete the update process.'); $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 $info) { foreach ($pending_updates as $pending_update) {
$messages[MessengerInterface::TYPE_WARNING][] = $info['name']; $messages[MessengerInterface::TYPE_WARNING][] = $pending_update;
} }
} }
...@@ -181,20 +181,6 @@ class UpdateReady extends FormBase { ...@@ -181,20 +181,6 @@ class UpdateReady extends FormBase {
return $form; return $form;
} }
/**
* Returns info for all installed modules that have staged database updates.
*
* @return array[]
* The info arrays for the modules which have staged database updates, keyed
* by module machine name.
*/
protected function getModulesWithStagedDatabaseUpdates(): array {
$filter = function (string $name): bool {
return $this->stagedDatabaseUpdateValidator->hasStagedUpdates($this->updater, $this->moduleList->get($name));
};
return array_filter($this->moduleList->getAllInstalledInfo(), $filter, ARRAY_FILTER_USE_KEY);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\automatic_updates\Validator; namespace Drupal\automatic_updates\Validator;
use Drupal\automatic_updates\CronUpdater; use Drupal\automatic_updates\CronUpdater;
use Drupal\automatic_updates\Updater;
use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ThemeExtensionList; use Drupal\Core\Extension\ThemeExtensionList;
...@@ -11,6 +10,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; ...@@ -11,6 +10,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\package_manager\Event\PreApplyEvent; use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\PathLocator; use Drupal\package_manager\PathLocator;
use Drupal\package_manager\Stage;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
...@@ -76,21 +76,7 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface { ...@@ -76,21 +76,7 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface {
return; return;
} }
$invalid_extensions = []; $invalid_extensions = $this->getExtensionsWithDatabaseUpdates($stage);
// Although \Drupal\automatic_updates\Validator\StagedProjectsValidator
// should prevent non-core modules from being added, updated, or removed in
// the staging area, we check all installed modules so as not to rely on the
// presence of StagedProjectsValidator.
foreach ($this->moduleList->getAllInstalledInfo() as $module_name => $module_info) {
if ($this->hasStagedUpdates($stage, $this->moduleList->get($module_name))) {
$invalid_extensions[] = $module_info['name'];
}
}
foreach ($this->themeList->getAllInstalledInfo() as $theme_name => $theme_info) {
if ($this->hasStagedUpdates($stage, $this->themeList->get($theme_name))) {
$invalid_extensions[] = $theme_info['name'];
}
}
if ($invalid_extensions) { if ($invalid_extensions) {
$event->addError($invalid_extensions, $this->t('The update cannot proceed because possible database updates have been detected in the following extensions.')); $event->addError($invalid_extensions, $this->t('The update cannot proceed because possible database updates have been detected in the following extensions.'));
} }
...@@ -99,7 +85,7 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface { ...@@ -99,7 +85,7 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface {
/** /**
* Determines if a staged extension has changed update functions. * Determines if a staged extension has changed update functions.
* *
* @param \Drupal\automatic_updates\Updater $updater * @param \Drupal\package_manager\Stage $stage
* The updater which is controlling the update process. * The updater which is controlling the update process.
* @param \Drupal\Core\Extension\Extension $extension * @param \Drupal\Core\Extension\Extension $extension
* The extension to check. * The extension to check.
...@@ -120,9 +106,9 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface { ...@@ -120,9 +106,9 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface {
* *
* @see https://www.drupal.org/project/automatic_updates/issues/3253828 * @see https://www.drupal.org/project/automatic_updates/issues/3253828
*/ */
public function hasStagedUpdates(Updater $updater, Extension $extension): bool { public function hasStagedUpdates(Stage $stage, Extension $extension): bool {
$active_dir = $this->pathLocator->getProjectRoot(); $active_dir = $this->pathLocator->getProjectRoot();
$stage_dir = $updater->getStageDirectory(); $stage_dir = $stage->getStageDirectory();
$web_root = $this->pathLocator->getWebRoot(); $web_root = $this->pathLocator->getWebRoot();
if ($web_root) { if ($web_root) {
...@@ -175,4 +161,31 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface { ...@@ -175,4 +161,31 @@ class StagedDatabaseUpdateValidator implements EventSubscriberInterface {
]; ];
} }
/**
* Get extensions that have database updates.
*
* @param \Drupal\package_manager\Stage $stage
* The stage.
*
* @return string[]
* The names of the extensions that have possible database updates.
*/
public function getExtensionsWithDatabaseUpdates(Stage $stage): array {
$invalid_extensions = [];
// Although \Drupal\automatic_updates\Validator\StagedProjectsValidator
// should prevent non-core modules from being added, updated, or removed in
// the staging area, we check all installed extensions so as not to rely on
// the presence of StagedProjectsValidator.
$lists = [$this->moduleList, $this->themeList];
foreach ($lists as $list) {
foreach ($list->getAllInstalledInfo() as $name => $info) {
if ($this->hasStagedUpdates($stage, $list->get($name))) {
$invalid_extensions[] = $info['name'];
}
}
}
return $invalid_extensions;
}
} }
...@@ -456,6 +456,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -456,6 +456,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
public function testStagedDatabaseUpdates(bool $maintenance_mode_on): void { public function testStagedDatabaseUpdates(bool $maintenance_mode_on): void {
$this->setCoreVersion('9.8.0'); $this->setCoreVersion('9.8.0');
$this->checkForUpdates(); $this->checkForUpdates();
$this->container->get('theme_installer')->install(['automatic_updates_theme_with_updates']);
$cached_message = $this->setAndAssertCachedMessage(); $cached_message = $this->setAndAssertCachedMessage();
$state = $this->container->get('state'); $state = $this->container->get('state');
...@@ -488,9 +489,10 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -488,9 +489,10 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
// changes have been applied, we should be redirected to update.php, where // changes have been applied, we should be redirected to update.php, where
// neither warning should be visible. // neither warning should be visible.
$assert_session->pageTextNotContains(reset($messages)); $assert_session->pageTextNotContains(reset($messages));
$possible_update_message = 'Possible database updates were detected in the following modules; you may be redirected to the database update page in order to complete the update process.'; $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->pageTextContains($possible_update_message);
$assert_session->pageTextContains('System'); $assert_session->pageTextContains('System');
$assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates');
if ($maintenance_mode_on === TRUE) { if ($maintenance_mode_on === TRUE) {
$assert_session->fieldNotExists('maintenance_mode'); $assert_session->fieldNotExists('maintenance_mode');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment