Skip to content
Snippets Groups Projects

Issue #3230507: Create build tests for case where site is using core recommended Composer project

Merged Issue #3230507: Create build tests for case where site is using core recommended Composer project
1 unresolved thread
1 unresolved thread
Compare and
5 files
+ 259
66
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 42
1
@@ -8,6 +8,7 @@ use Drupal\automatic_updates\Event\PreStartEvent;
use Drupal\automatic_updates\Event\UpdateEvent;
use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\Component\FileSystem\FileSystem;
use Drupal\Component\Serialization\Json;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
@@ -167,7 +168,7 @@ class Updater {
throw new \InvalidArgumentException("Currently only updates to Drupal core are supported.");
}
$packages = [
'drupal/core' => $project_versions['drupal'],
$this->getCorePackageName() => $project_versions['drupal'],
];
$stage_key = $this->createActiveStage($packages);
/** @var \Drupal\automatic_updates\Event\PreStartEvent $event */
@@ -176,6 +177,46 @@ class Updater {
return $stage_key;
}
/**
* Determines the name of the core package in the project composer.json.
*
* This makes the following assumptions:
* - The vendor directory is next to the project composer.json.
* - The project composer.json contains a requirement for a core package.
* - That requirement is either for drupal/core or drupal/core-recommended.
*
* @return string
* The name of the core package (either drupal/core or
* drupal/core-recommended).
*
* @throws \RuntimeException
* If the project composer.json is not found.
* @throws \LogicException
* If the project composer.json does not contain one of the supported core
* packages.
*
* @todo Move this to an update validator, or use a more robust method of
* detecting the core package.
*/
protected function getCorePackageName(): string {
$composer = realpath(static::getVendorDirectory() . '/../composer.json');
if (empty($composer) || !file_exists($composer)) {
throw new \RuntimeException("Could not find project-level composer.json");
}
$composer = file_get_contents($composer);
$composer = Json::decode($composer);
if (isset($composer['require']['drupal/core'])) {
return 'drupal/core';
}
elseif (isset($composer['require']['drupal/core-recommended'])) {
return 'drupal/core-recommended';
}
throw new \LogicException("Could not determine the Drupal core package in the project-level composer.json.");
}
/**
* Gets the excluded paths collected by an event object.
*
Loading