function ProjectInfo::getInstallableReleases

Gets all project releases to which the site can update.

@todo Remove or simplify this function in https://www.drupal.org/i/3252190.

Return value

\Drupal\update\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 descending order by version number (i.e., higher versions are listed first). The currently installed version of the project, and any older versions, are not considered installable releases.

Throws

\RuntimeException Thrown if there are no available releases.

File

core/modules/package_manager/src/ProjectInfo.php, line 90

Class

ProjectInfo
Defines a class for retrieving project information from Update module.

Namespace

Drupal\package_manager

Code

public function getInstallableReleases() : ?array {
    $project = $this->getProjectInfo();
    if (!$project) {
        return NULL;
    }
    $available_updates = $this->getAvailableProjects()[$this->name];
    if ($available_updates['project_status'] !== 'published') {
        throw new \RuntimeException("The project '{$this->name}' can not be updated because its status is " . $available_updates['project_status']);
    }
    $installed_version = $this->getInstalledVersion();
    if ($installed_version && empty($available_updates['releases'])) {
        // If project is installed but not current we should always have at
        // least one release.
        throw new \RuntimeException('There was a problem getting update information. Try again later.');
    }
    $support_branches = explode(',', $available_updates['supported_branches']);
    $installable_releases = [];
    foreach ($available_updates['releases'] as $release_info) {
        try {
            $release = ProjectRelease::createFromArray($release_info);
        } catch (\UnexpectedValueException $exception) {
            // Ignore releases that are in an invalid format. Although this is
            // unlikely we should still only process releases in the correct format.
            \Drupal::logger('package_manager')->error(sprintf('Invalid project format: %s', print_r($release_info, TRUE)), Error::decodeException($exception));
            continue;
        }
        $version = $release->getVersion();
        if ($installed_version) {
            $semantic_version = LegacyVersionUtility::convertToSemanticVersion($version);
            $semantic_installed_version = LegacyVersionUtility::convertToSemanticVersion($installed_version);
            if (Comparator::lessThanOrEqualTo($semantic_version, $semantic_installed_version)) {
                // If the project is installed stop searching for releases as soon as
                // we find the installed version.
                break;
            }
        }
        if ($this->isInstallable($release, $support_branches)) {
            $installable_releases[$version] = $release;
        }
    }
    return $installable_releases;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.