Loading core/modules/package_manager/src/ProjectInfo.php +4 −7 Original line number Diff line number Diff line Loading @@ -21,10 +21,7 @@ */ final class ProjectInfo { public function __construct( private readonly string $name, private readonly UpdateManagerInterface $updateManager, ) {} public function __construct(private readonly string $name) {} /** * Determines if a release can be installed. Loading Loading @@ -67,7 +64,7 @@ private function isInstallable(ProjectRelease $release, array $support_branches) */ public function getProjectInfo(): ?array { $available_updates = $this->getAvailableProjects(); $project_data = update_calculate_project_data($available_updates); $project_data = \Drupal::service(UpdateManagerInterface::class)->calculateProjectData($available_updates); if (!isset($project_data[$this->name])) { return $available_updates[$this->name] ?? NULL; } Loading Loading @@ -150,7 +147,7 @@ public function getInstalledVersion(): ?string { $existing_version = $project_data['existing_version']; // Treat an unknown version the same as a project whose project // information is not available, so return NULL. // @see \update_process_project_info() // @see \Drupal\update\UpdateCalculator::processProjectInfo() if ($existing_version instanceof TranslatableMarkup && $existing_version->getUntranslatedString() === 'Unknown') { return NULL; } Loading Loading @@ -181,7 +178,7 @@ public function getInstalledVersion(): ?string { * @see \Drupal\update\UpdateManagerInterface::getAvailable() */ private function getAvailableProjects(): array { $available_projects = $this->updateManager->getAvailable(TRUE); $available_projects = \Drupal::service(UpdateManagerInterface::class)->getAvailable(TRUE); // \Drupal\update\UpdateManagerInterface::getAvailable() will only return // projects that are in the active codebase. If the project specified by // ::name is not returned in $available_projects, it means it is not in the Loading core/modules/package_manager/src/Validator/SupportedReleaseValidator.php +1 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\package_manager\LegacyVersionUtility; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\update\UpdateManagerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** Loading @@ -27,7 +26,6 @@ final class SupportedReleaseValidator implements EventSubscriberInterface { public function __construct( private readonly ComposerInspector $composerInspector, private readonly PathLocator $pathLocator, private readonly UpdateManagerInterface $updateManager, ) {} /** Loading @@ -48,7 +46,7 @@ public function __construct( * given version is not supported will return FALSE. */ private function isSupportedRelease(string $name, string $semantic_version): bool { $supported_releases = (new ProjectInfo($name, $this->updateManager))->getInstallableReleases(); $supported_releases = (new ProjectInfo($name))->getInstallableReleases(); if (!$supported_releases) { return FALSE; } Loading core/modules/package_manager/tests/src/Kernel/ProjectInfoTest.php +5 −5 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ public function testGetInstallableReleases(string $fixture, string $installed_ve } $metadata_fixtures[$project] = "$fixtures_directory$fixture"; $this->setReleaseMetadata($metadata_fixtures); $project_info = new ProjectInfo($project, \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo($project); $actual_releases = $project_info->getInstallableReleases(); // Assert that we returned the correct releases in the expected order. $this->assertSame($expected_versions, array_keys($actual_releases)); Loading Loading @@ -148,7 +148,7 @@ public function testNewProject(): void { // Set the state that the Update Status module uses to store last checked // time ensure our calls do not affect it. $state->set('update.last_check', 123); $project_info = new ProjectInfo('package_manager_test_update', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('package_manager_test_update'); $project_data = $project_info->getProjectInfo(); // Ensure the project information is correct. $this->assertSame('Package Manager Test Update', $project_data['title']); Loading Loading @@ -192,7 +192,7 @@ public function testNewProject(): void { */ public function testNotPublishedProject(): void { $this->setReleaseMetadata(['drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.2_unknown_status.xml']); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->expectException(\RuntimeException::class); $this->expectExceptionMessageIs("The project 'drupal' can not be updated because its status is any status besides published"); $project_info->getInstallableReleases(); Loading Loading @@ -254,7 +254,7 @@ public function testInstalledVersionSafe(string $installed_version, string $rele $this->setCoreVersion($installed_version); $this->setReleaseMetadata(['drupal' => $release_xml]); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->assertSame($expected_to_be_safe, $project_info->isInstalledVersionSafe()); } Loading Loading @@ -301,7 +301,7 @@ public static function providerGetSupportedBranches(): array { #[DataProvider('providerGetSupportedBranches')] public function testGetSupportedBranches(string $release_xml, array $expected_supported_branches): void { $this->setReleaseMetadata(['drupal' => $release_xml]); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->assertSame($expected_supported_branches, $project_info->getSupportedBranches()); } Loading core/modules/update/src/Controller/UpdateController.php +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public function updateStatus() { ]; if ($available = $this->updateManager->getAvailable(TRUE)) { $this->moduleHandler()->loadInclude('update', 'compare.inc'); $build['#data'] = update_calculate_project_data($available); $build['#data'] = $this->updateManager->calculateProjectData($available); // @todo Consider using 'fetch_failures' from the 'update' collection // in the key_value_expire service for this? Loading core/modules/update/src/Hook/UpdateRequirements.php +3 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public function runtime(): array { $requirements = []; if ($available = $this->updateManager->getAvailable(FALSE)) { $this->moduleHandler->loadInclude('update', 'inc', 'update.compare'); $data = update_calculate_project_data($available); $data = $this->updateManager->calculateProjectData($available); // First, populate the requirements for core: $requirements['update_core'] = $this->requirementCheck($data['drupal'], 'core'); if (!empty($available['drupal']['releases'])) { Loading Loading @@ -102,7 +102,7 @@ public function runtime(): array { * * @param array $project * Array of information about the project we're testing as returned by * update_calculate_project_data(). * \Drupal\update\UpdateManagerInterface::calculateProjectData(). * @param string $type * What kind of project this is ('core' or 'contrib'). * Loading @@ -111,7 +111,7 @@ public function runtime(): array { * * @see hook_requirements() * @see Drupal\update\Hook\UpdateRequirements::runtime() * @see update_calculate_project_data() * @see \Drupal\update\UpdateManagerInterface::calculateProjectData() */ protected function requirementCheck($project, $type): array { $requirement = []; Loading Loading
core/modules/package_manager/src/ProjectInfo.php +4 −7 Original line number Diff line number Diff line Loading @@ -21,10 +21,7 @@ */ final class ProjectInfo { public function __construct( private readonly string $name, private readonly UpdateManagerInterface $updateManager, ) {} public function __construct(private readonly string $name) {} /** * Determines if a release can be installed. Loading Loading @@ -67,7 +64,7 @@ private function isInstallable(ProjectRelease $release, array $support_branches) */ public function getProjectInfo(): ?array { $available_updates = $this->getAvailableProjects(); $project_data = update_calculate_project_data($available_updates); $project_data = \Drupal::service(UpdateManagerInterface::class)->calculateProjectData($available_updates); if (!isset($project_data[$this->name])) { return $available_updates[$this->name] ?? NULL; } Loading Loading @@ -150,7 +147,7 @@ public function getInstalledVersion(): ?string { $existing_version = $project_data['existing_version']; // Treat an unknown version the same as a project whose project // information is not available, so return NULL. // @see \update_process_project_info() // @see \Drupal\update\UpdateCalculator::processProjectInfo() if ($existing_version instanceof TranslatableMarkup && $existing_version->getUntranslatedString() === 'Unknown') { return NULL; } Loading Loading @@ -181,7 +178,7 @@ public function getInstalledVersion(): ?string { * @see \Drupal\update\UpdateManagerInterface::getAvailable() */ private function getAvailableProjects(): array { $available_projects = $this->updateManager->getAvailable(TRUE); $available_projects = \Drupal::service(UpdateManagerInterface::class)->getAvailable(TRUE); // \Drupal\update\UpdateManagerInterface::getAvailable() will only return // projects that are in the active codebase. If the project specified by // ::name is not returned in $available_projects, it means it is not in the Loading
core/modules/package_manager/src/Validator/SupportedReleaseValidator.php +1 −3 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\package_manager\LegacyVersionUtility; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreApplyEvent; use Drupal\update\UpdateManagerInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** Loading @@ -27,7 +26,6 @@ final class SupportedReleaseValidator implements EventSubscriberInterface { public function __construct( private readonly ComposerInspector $composerInspector, private readonly PathLocator $pathLocator, private readonly UpdateManagerInterface $updateManager, ) {} /** Loading @@ -48,7 +46,7 @@ public function __construct( * given version is not supported will return FALSE. */ private function isSupportedRelease(string $name, string $semantic_version): bool { $supported_releases = (new ProjectInfo($name, $this->updateManager))->getInstallableReleases(); $supported_releases = (new ProjectInfo($name))->getInstallableReleases(); if (!$supported_releases) { return FALSE; } Loading
core/modules/package_manager/tests/src/Kernel/ProjectInfoTest.php +5 −5 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ public function testGetInstallableReleases(string $fixture, string $installed_ve } $metadata_fixtures[$project] = "$fixtures_directory$fixture"; $this->setReleaseMetadata($metadata_fixtures); $project_info = new ProjectInfo($project, \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo($project); $actual_releases = $project_info->getInstallableReleases(); // Assert that we returned the correct releases in the expected order. $this->assertSame($expected_versions, array_keys($actual_releases)); Loading Loading @@ -148,7 +148,7 @@ public function testNewProject(): void { // Set the state that the Update Status module uses to store last checked // time ensure our calls do not affect it. $state->set('update.last_check', 123); $project_info = new ProjectInfo('package_manager_test_update', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('package_manager_test_update'); $project_data = $project_info->getProjectInfo(); // Ensure the project information is correct. $this->assertSame('Package Manager Test Update', $project_data['title']); Loading Loading @@ -192,7 +192,7 @@ public function testNewProject(): void { */ public function testNotPublishedProject(): void { $this->setReleaseMetadata(['drupal' => __DIR__ . '/../../fixtures/release-history/drupal.9.8.2_unknown_status.xml']); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->expectException(\RuntimeException::class); $this->expectExceptionMessageIs("The project 'drupal' can not be updated because its status is any status besides published"); $project_info->getInstallableReleases(); Loading Loading @@ -254,7 +254,7 @@ public function testInstalledVersionSafe(string $installed_version, string $rele $this->setCoreVersion($installed_version); $this->setReleaseMetadata(['drupal' => $release_xml]); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->assertSame($expected_to_be_safe, $project_info->isInstalledVersionSafe()); } Loading Loading @@ -301,7 +301,7 @@ public static function providerGetSupportedBranches(): array { #[DataProvider('providerGetSupportedBranches')] public function testGetSupportedBranches(string $release_xml, array $expected_supported_branches): void { $this->setReleaseMetadata(['drupal' => $release_xml]); $project_info = new ProjectInfo('drupal', \Drupal::service(UpdateManagerInterface::class)); $project_info = new ProjectInfo('drupal'); $this->assertSame($expected_supported_branches, $project_info->getSupportedBranches()); } Loading
core/modules/update/src/Controller/UpdateController.php +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ public function updateStatus() { ]; if ($available = $this->updateManager->getAvailable(TRUE)) { $this->moduleHandler()->loadInclude('update', 'compare.inc'); $build['#data'] = update_calculate_project_data($available); $build['#data'] = $this->updateManager->calculateProjectData($available); // @todo Consider using 'fetch_failures' from the 'update' collection // in the key_value_expire service for this? Loading
core/modules/update/src/Hook/UpdateRequirements.php +3 −3 Original line number Diff line number Diff line Loading @@ -54,7 +54,7 @@ public function runtime(): array { $requirements = []; if ($available = $this->updateManager->getAvailable(FALSE)) { $this->moduleHandler->loadInclude('update', 'inc', 'update.compare'); $data = update_calculate_project_data($available); $data = $this->updateManager->calculateProjectData($available); // First, populate the requirements for core: $requirements['update_core'] = $this->requirementCheck($data['drupal'], 'core'); if (!empty($available['drupal']['releases'])) { Loading Loading @@ -102,7 +102,7 @@ public function runtime(): array { * * @param array $project * Array of information about the project we're testing as returned by * update_calculate_project_data(). * \Drupal\update\UpdateManagerInterface::calculateProjectData(). * @param string $type * What kind of project this is ('core' or 'contrib'). * Loading @@ -111,7 +111,7 @@ public function runtime(): array { * * @see hook_requirements() * @see Drupal\update\Hook\UpdateRequirements::runtime() * @see update_calculate_project_data() * @see \Drupal\update\UpdateManagerInterface::calculateProjectData() */ protected function requirementCheck($project, $type): array { $requirement = []; Loading