From e3442681f1090a678fce991bff27e242caa4c4ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Costa=20Silva?= <1574795+joaocsilva@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:24:51 +0100 Subject: [PATCH] DQA-8186: Component check enable update module (#714) --- .../Commands/ComponentCheckCommands.php | 59 +++++++++++++------ tests/fixtures/commands/component-check.yml | 3 + 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/TaskRunner/Commands/ComponentCheckCommands.php b/src/TaskRunner/Commands/ComponentCheckCommands.php index 1987b4ec9..e4c4a9bc1 100644 --- a/src/TaskRunner/Commands/ComponentCheckCommands.php +++ b/src/TaskRunner/Commands/ComponentCheckCommands.php @@ -39,6 +39,7 @@ class ComponentCheckCommands extends AbstractCommands protected $io; protected array $composerLock; protected array $packageReviews; + protected bool $forcedUpdateModule = false; /** * Check composer for components that are not whitelisted/blacklisted. @@ -590,34 +591,30 @@ protected function componentAbandoned() */ protected function componentUnsupported() { - $include = "\Drupal::moduleHandler()->loadInclude('update', 'compare.inc')"; - $command = "update_calculate_project_data(\Drupal::keyValueExpirable('update_available_releases')->getAll())"; - $command = "$include ; echo json_encode($command)"; - $exec = $this->taskExec($this->getBin('drush') . ' eval "' . $command . '"') - ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG) - ->run()->getMessage(); - if (empty($exec)) { + if (empty($releases = $this->getReleases())) { $this->writeln('Failed to get the available releases.'); return; } - - $releases = json_decode($exec, true); // Filter by unsupported, @see \Drupal\update\UpdateManagerInterface::NOT_SUPPORTED. $unsupported = array_filter($releases, function ($item) { return $item['status'] === 3; }); if (empty($unsupported)) { $this->say('Unsupported components check passed.'); - return; + } else { + $this->unsupportedFailed = true; + foreach ($unsupported as $item) { + $this->writeln(sprintf( + "Package %s with version installed %s is not supported. Update to the recommended version %s", + $item['name'], + $item['existing_version'], + $item['recommended'] + )); + } } - $this->unsupportedFailed = true; - foreach ($unsupported as $item) { - $this->writeln(sprintf( - "Package %s with version installed %s is not supported. Update to the recommended version %s", - $item['name'], - $item['existing_version'], - $item['recommended'] - )); + + if ($this->forcedUpdateModule) { + $this->_exec($this->getBin('drush') . ' pm:uninstall update -y'); } } @@ -696,6 +693,32 @@ private function testPackages() ]; } + /** + * Returns the modules releases. + * + * If the update module is not enabled, it will be enabled, and later disabled. + */ + private function getReleases(): array + { + $include = "\Drupal::moduleHandler()->loadInclude('update', 'compare.inc')"; + $command = "update_calculate_project_data(\Drupal::keyValueExpirable('update_available_releases')->getAll())"; + $command = "$include ; echo json_encode($command)"; + $exec = $this->taskExec($this->getBin('drush') . ' eval "' . $command . '"') + ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG) + ->run()->getMessage(); + if (empty($exec) || str_contains($exec, 'Call to undefined function')) { + // Attempt to enable the module only once. + if ($this->forcedUpdateModule) { + return []; + } + $this->_exec($this->getBin('drush') . ' en update -y'); + $this->forcedUpdateModule = true; + return $this->getReleases(); + } + + return json_decode($exec, true); + } + /** * Returns the recommended components warning message. */ diff --git a/tests/fixtures/commands/component-check.yml b/tests/fixtures/commands/component-check.yml index 9f221719c..754835eab 100644 --- a/tests/fixtures/commands/component-check.yml +++ b/tests/fixtures/commands/component-check.yml @@ -44,6 +44,9 @@ Checking Unsupported components. ================================ + [Simulator] Running ./vendor/bin/drush eval "\Drupal::moduleHandler()->loadInclude('update', 'compare.inc') ; echo json_encode(update_calculate_project_data(\Drupal::keyValueExpirable('update_available_releases')->getAll()))" + [Simulator] Simulating Exec('./vendor/bin/drush en update -y') + [Simulator] Running ./vendor/bin/drush en update -y [Simulator] Running ./vendor/bin/drush eval "\Drupal::moduleHandler()->loadInclude('update', 'compare.inc') ; echo json_encode(update_calculate_project_data(\Drupal::keyValueExpirable('update_available_releases')->getAll()))" Failed to get the available releases.