Skip to content
Snippets Groups Projects
Commit ece5a5f4 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3273807 by phenaproxima: ProjectInfo should always refresh data

parent 7edf8a6a
No related branches found
No related tags found
No related merge requests found
......@@ -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());
}
......
......@@ -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.');
}
......
......@@ -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;
......
......@@ -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.
*
......
......@@ -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(
......
......@@ -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());
}
......
......@@ -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());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment