Skip to content
Snippets Groups Projects

Issue #3271240: Allow getting update information for any project not just Drupal core

Merged Issue #3271240: Allow getting update information for any project not just Drupal core
All threads resolved!
Merged Ted Bowman requested to merge issue/automatic_updates-3271240:3271240-any-project into 8.x-2.x
All threads resolved!
Files
2
+ 29
17
@@ -9,6 +9,11 @@ use Drupal\update\UpdateManagerInterface;
/**
* Defines a class for retrieving project information from Update module.
*
* @internal
* This class is an internal helper class for calling Drupal core's Update
* module's global functions. It should not be called by external code which
* should use the Update API directly.
*/
class ProjectInfo {
@@ -30,45 +35,49 @@ class ProjectInfo {
}
/**
* Returns up-to-date project information for Drupal core.
* 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
* The retrieved project information for Drupal core.
* @return array|null
* The retrieved project information.
*
* @throws \RuntimeException
* If data about available updates cannot be retrieved.
*/
public function getProjectInfo(bool $refresh = FALSE): array {
public function getProjectInfo(bool $refresh = FALSE): ?array {
$available_updates = update_get_available($refresh);
$project_data = update_calculate_project_data($available_updates);
return $project_data[$this->name];
return $project_data[$this->name] ?? NULL;
}
/**
* Gets all releases of Drupal core to which the site can update.
* 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[]
* An array of possible update releases with release versions as keys. The
* releases are in descending order by version number (i.e., higher versions
* are listed first).
* @return \Drupal\automatic_updates_9_3_shim\ProjectRelease[]|null
* If the project information is available an array of possible update
* releases with release versions as keys, otherwise NULL. The releases are
* in descending order by version number (i.e., higher versions are listed
* first).
*
* @throws \RuntimeException
* Thrown if $refresh is TRUE and 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 {
public function getInstallableReleases(bool $refresh = FALSE): ?array {
$project = $this->getProjectInfo($refresh);
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.
@@ -81,7 +90,7 @@ class ProjectInfo {
}
elseif (empty($project['recommended'])) {
// If we don't know what to recommend they update to, time to freak out.
throw new \LogicException('Drupal core is out of date, but the recommended version could not be determined.');
throw new \LogicException("The '{$this->name}' project is out of date, but the recommended version could not be determined.");
}
$installable_releases = [];
if (Comparator::greaterThan($project['recommended'], $installed_version)) {
@@ -109,12 +118,15 @@ class ProjectInfo {
* updates from drupal.org. This can be an expensive operation, so defaults
* to FALSE.
*
* @return string
* The installed project version as known to the Update module.
* @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 {
$project_data = $this->getProjectInfo($refresh);
return $project_data['existing_version'];
public function getInstalledVersion(bool $refresh = FALSE): ?string {
if ($project_data = $this->getProjectInfo($refresh)) {
return $project_data['existing_version'];
}
return NULL;
}
}
Loading