diff --git a/src/CronUpdater.php b/src/CronUpdater.php index c5bf5c3507c823129d7e3b15e30a4f2172780e8e..cba9e6cc33c86d6db4ec7e67358212f5e36f8eac 100644 --- a/src/CronUpdater.php +++ b/src/CronUpdater.php @@ -73,7 +73,7 @@ class CronUpdater extends Updater { return; } - $next_release = $this->releaseChooser->refresh()->getLatestInInstalledMinor(); + $next_release = $this->releaseChooser->getLatestInInstalledMinor(); if ($next_release) { $this->performUpdate($next_release->getVersion()); } diff --git a/src/Form/UpdaterForm.php b/src/Form/UpdaterForm.php index 92b7cc300f055b870958c59c2e7313b755dec6f7..d121735fcb1097b269705fbfb9d4ae8108070b39 100644 --- a/src/Form/UpdaterForm.php +++ b/src/Form/UpdaterForm.php @@ -139,7 +139,7 @@ class UpdaterForm extends FormBase { // currently installed minor. Failing that, try to show the latest // release in the next minor. If neither of those are available, just // show the first available release. - $recommended_release = $this->releaseChooser->refresh()->getLatestInInstalledMinor(); + $recommended_release = $this->releaseChooser->getLatestInInstalledMinor(); if (!$recommended_release) { $recommended_release = $this->releaseChooser->getLatestInNextMinor(); if (!$recommended_release) { @@ -176,7 +176,7 @@ class UpdaterForm extends FormBase { ], ]; - $project = $project_info->getProjectInfo('drupal'); + $project = $project_info->getProjectInfo(); if (empty($project['title']) || empty($project['link'])) { throw new \UnexpectedValueException('Expected project data to have a title and link.'); } diff --git a/src/ProjectInfo.php b/src/ProjectInfo.php index e61253b2be15fe8fede155432aedddbda453d821..fce9a1ae6dca5573a66dcdc5472a9f9a4004fe5f 100644 --- a/src/ProjectInfo.php +++ b/src/ProjectInfo.php @@ -35,19 +35,14 @@ class ProjectInfo { /** * Returns up-to-date project information. * - * @param bool $refresh - * (optional) Whether to fetch the latest information about available - * updates from drupal.org. This can be an expensive operation, so defaults - * to FALSE. - * * @return array|null * The retrieved project information. * * @throws \RuntimeException * If data about available updates cannot be retrieved. */ - public function getProjectInfo(bool $refresh = FALSE): ?array { - $available_updates = update_get_available($refresh); + public function getProjectInfo(): ?array { + $available_updates = update_get_available(TRUE); $project_data = update_calculate_project_data($available_updates); return $project_data[$this->name] ?? NULL; } @@ -55,11 +50,6 @@ class ProjectInfo { /** * Gets all project releases to which the site can update. * - * @param bool $refresh - * (optional) Whether to fetch the latest information about available - * updates from drupal.org. This can be an expensive operation, so defaults - * to FALSE. - * * @return \Drupal\automatic_updates_9_3_shim\ProjectRelease[]|null * If the project information is available, an array of releases that can be * installed, keyed by version number; otherwise NULL. The releases are in @@ -67,19 +57,19 @@ class ProjectInfo { * first). * * @throws \RuntimeException - * Thrown if $refresh is TRUE and there are no available releases. + * Thrown if there are no available releases. * * @todo Remove or simplify this function in https://www.drupal.org/i/3252190. */ - public function getInstallableReleases(bool $refresh = FALSE): ?array { - $project = $this->getProjectInfo($refresh); + public function getInstallableReleases(): ?array { + $project = $this->getProjectInfo(); if (!$project) { return NULL; } $installed_version = $this->getInstalledVersion(); - // If we refreshed and we were able to get available releases we should - // always have at least have the current release stored. - if ($refresh && empty($project['releases'])) { + // If we were able to get available releases we should always have at least + // the current release stored. + if (empty($project['releases'])) { throw new \RuntimeException('There was a problem getting update information. Try again later.'); } // If we're already up-to-date, there's nothing else we need to do. @@ -111,17 +101,12 @@ class ProjectInfo { /** * Returns the installed project version, according to the Update module. * - * @param bool $refresh - * (optional) Whether to fetch the latest information about available - * updates from drupal.org. This can be an expensive operation, so defaults - * to FALSE. - * * @return string|null * The installed project version as known to the Update module or NULL if * the project information is not available. */ - public function getInstalledVersion(bool $refresh = FALSE): ?string { - if ($project_data = $this->getProjectInfo($refresh)) { + public function getInstalledVersion(): ?string { + if ($project_data = $this->getProjectInfo()) { return $project_data['existing_version']; } return NULL; diff --git a/src/ReleaseChooser.php b/src/ReleaseChooser.php index b0edf92b283d19f83f6bbe8613a1edf662a9b86a..6163320a2c3218ce3d0e9a6ef6116f84db20d7f6 100644 --- a/src/ReleaseChooser.php +++ b/src/ReleaseChooser.php @@ -39,17 +39,6 @@ class ReleaseChooser { $this->projectInfo = new ProjectInfo('drupal'); } - /** - * Refreshes the project information through the Update module. - * - * @return $this - * The called object. - */ - public function refresh(): self { - $this->projectInfo->getProjectInfo(TRUE); - return $this; - } - /** * Returns the releases that are installable. * diff --git a/src/Validation/ReadinessValidationManager.php b/src/Validation/ReadinessValidationManager.php index 436569bc63ea90671a6b1f9ce0d9626a61aef705..08e50d6f8e73b8e544574a3157da57b026dceeb9 100644 --- a/src/Validation/ReadinessValidationManager.php +++ b/src/Validation/ReadinessValidationManager.php @@ -4,7 +4,6 @@ namespace Drupal\automatic_updates\Validation; use Drupal\automatic_updates\CronUpdater; use Drupal\automatic_updates\Event\ReadinessCheckEvent; -use Drupal\automatic_updates\ProjectInfo; use Drupal\automatic_updates\Updater; use Drupal\Component\Datetime\TimeInterface; use Drupal\Core\Config\ConfigFactoryInterface; @@ -112,8 +111,6 @@ class ReadinessValidationManager implements EventSubscriberInterface { $stage = $this->cronUpdater; } $event = new ReadinessCheckEvent($stage); - // Version validators will need up-to-date project info. - (new ProjectInfo('drupal'))->getProjectInfo(TRUE); $this->eventDispatcher->dispatch($event); $results = $event->getResults(); $this->keyValueExpirable->setWithExpire( diff --git a/tests/src/Kernel/ReleaseChooserTest.php b/tests/src/Kernel/ReleaseChooserTest.php index dac21432ae7bbb84da72d8aaae577ce10900dc2c..9b4470b282a7b37af02c9bab667385a0a2c92e10 100644 --- a/tests/src/Kernel/ReleaseChooserTest.php +++ b/tests/src/Kernel/ReleaseChooserTest.php @@ -145,7 +145,6 @@ class ReleaseChooserTest extends AutomaticUpdatesKernelTestBase { $this->config('automatic_updates.settings')->set('allow_core_minor_updates', $minor_support)->save(); /** @var \Drupal\automatic_updates\ReleaseChooser $chooser */ $chooser = $this->container->get($chooser_service); - $chooser->refresh(); $this->assertReleaseVersion($current_minor, $chooser->getLatestInInstalledMinor()); $this->assertReleaseVersion($next_minor, $chooser->getLatestInNextMinor()); } diff --git a/tests/src/Unit/ProjectInfoTest.php b/tests/src/Unit/ProjectInfoTest.php index 1b5eda2b6e9b6278c095964bc7db46bc2fa5a039..6578069d10a9326fe0c58d5b2429e1af439821ec 100644 --- a/tests/src/Unit/ProjectInfoTest.php +++ b/tests/src/Unit/ProjectInfoTest.php @@ -122,7 +122,7 @@ class ProjectInfoTest extends UnitTestCase { '8.2.4' => $release_objects['8.2.4'], ], ], - [ + 'no data' => [ NULL, NULL, ], @@ -141,6 +141,12 @@ class ProjectInfoTest extends UnitTestCase { */ public function testGetInstallableReleases(?array $project_data, ?array $expected_releases): void { $project_info = $this->getMockedProjectInfo($project_data); + + // If data is returned, but there are no releases, we should get an + // exception. + if (isset($project_data, $expected_releases) && empty($project_data['releases'])) { + $this->expectExceptionMessage('There was a problem getting update information. Try again later.'); + } $this->assertEqualsCanonicalizing($expected_releases, $project_info->getInstallableReleases()); }