Skip to content

Commit

Permalink
DQA-8186: Component check enable update module (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocsilva authored Nov 9, 2023
1 parent 030e98b commit e344268
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
59 changes: 41 additions & 18 deletions src/TaskRunner/Commands/ComponentCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
}

Expand Down Expand Up @@ -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.
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/commands/component-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e344268

Please sign in to comment.