diff --git a/core/modules/update/src/ModuleVersion.php b/core/modules/update/src/ModuleVersion.php index dc2227b53d..6a5c3f55a9 100644 --- a/core/modules/update/src/ModuleVersion.php +++ b/core/modules/update/src/ModuleVersion.php @@ -17,11 +17,18 @@ class ModuleVersion { const CORE_COMPATIBILITY_PREFIX = \Drupal::CORE_COMPATIBILITY . '-'; /** - * The module version. + * The major version. * * @var string */ - protected $version; + protected $majorVersion; + + /** + * The version extra string. + * + * @var string|null + */ + protected $versionExtra; /** * Constructs a module version object from a version string. @@ -33,17 +40,25 @@ class ModuleVersion { * The module version instance. */ public static function createFromVersionString($version_string) { - return new static($version_string); + $version_string = strpos($version_string, static::CORE_COMPATIBILITY_PREFIX) === 0 ? str_replace(static::CORE_COMPATIBILITY_PREFIX, '', $version_string) : $version_string; + $version_parts = explode('.', $version_string); + $major_version = $version_parts[0]; + $last_part_split = explode('-', array_pop($version_parts)); + $version_extra = count($last_part_split) === 1 ? NULL : $last_part_split[1]; + return new static($major_version, $version_extra); } /** * Constructs a ModuleVersion object. * - * @param string $version - * The version number. + * @param string $major_version + * The major version. + * @param string|null $version_extra + * The extra version string. */ - protected function __construct($version) { - $this->version = $version; + protected function __construct($major_version, $version_extra) { + $this->majorVersion = $major_version; + $this->versionExtra = $version_extra; } /** @@ -69,8 +84,7 @@ public static function createFromSupportBranch($branch) { * The major version. */ public function getMajorVersion() { - $version_string = strpos($this->version, static::CORE_COMPATIBILITY_PREFIX) === 0 ? str_replace(static::CORE_COMPATIBILITY_PREFIX, '', $this->version) : $this->version; - return explode('.', $version_string)[0]; + return $this->majorVersion; } /** @@ -80,9 +94,7 @@ public function getMajorVersion() { * The version extra string if available otherwise NULL. */ public function getVersionExtra() { - $version_parts = explode('.', $this->version); - $last_part_split = explode('-', array_pop($version_parts)); - return count($last_part_split) == 1 ? NULL : $last_part_split[1]; + return $this->versionExtra; } } diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc index b56f61e368..503cd3acc7 100644 --- a/core/modules/update/update.compare.inc +++ b/core/modules/update/update.compare.inc @@ -310,6 +310,10 @@ function update_calculate_project_update_status(&$project_data, $available) { $project_data['reason'] = t('No available releases found'); return; } + + $recommended_version_without_extra = ''; + $recommended_release = NULL; + foreach ($available['releases'] as $version => $release) { $release_module_version = ModuleVersion::createFromVersionString($release['version']); // First, if this is the existing release, check a few conditions. @@ -358,7 +362,7 @@ function update_calculate_project_update_status(&$project_data, $available) { // be one of those being compared. They would not have version_major // set, so we must call isset first. if ($release_major_version !== NULL && $release_major_version > $target_major) { - if ($is_in_supported_branch($release_module_version)) { + if ($is_in_supported_branch($release['version'])) { if (!isset($project_data['also'])) { $project_data['also'] = []; } @@ -393,13 +397,24 @@ function update_calculate_project_update_status(&$project_data, $available) { $project_data['releases'][$version] = $release; } - // Look for the 'recommended' version if we haven't found it yet (see + if ($release_module_version->getVersionExtra()) { + $release_version_without_extra = str_replace('-' . $release_module_version->getVersionExtra(), '', $release['version']); + } + else { + $release_version_without_extra = $release['version']; + } + + // Look for the 'recommended' version if we haven't found it yet (SEE // phpdoc at the top of this function for the definition). if (!isset($project_data['recommended']) && $release_major_version == $target_major) { + if ($recommended_version_without_extra !== $release_version_without_extra) { + $recommended_version_without_extra = $release_version_without_extra; + $recommended_release = $release; + } if ($release_module_version->getVersionExtra() === NULL) { - $project_data['recommended'] = $release['version']; - $project_data['releases'][$release['version']] = $release; + $project_data['recommended'] = $recommended_release['version']; + $project_data['releases'][$recommended_release['version']] = $recommended_release; } }