diff --git a/core/modules/update/src/Form/UpdateManagerUpdate.php b/core/modules/update/src/Form/UpdateManagerUpdate.php
index f88aaa751d..6915cf3f92 100644
--- a/core/modules/update/src/Form/UpdateManagerUpdate.php
+++ b/core/modules/update/src/Form/UpdateManagerUpdate.php
@@ -8,7 +8,7 @@
use Drupal\Core\Link;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Url;
-use Drupal\update\ReleaseInfo;
+use Drupal\update\ModuleVersionParser;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -134,8 +134,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$recommended_release = $project['releases'][$project['recommended']];
$recommended_version = '{{ release_version }} ({{ release_notes }})';
- $project_info = new ReleaseInfo($recommended_release);
- if ($project_info->getMajorVersion() != $project['existing_major']) {
+ $recommended_version_parser = new ModuleVersionParser($recommended_release['version']);
+ if ($recommended_version_parser->getMajorVersion() != $project['existing_major']) {
$recommended_version .= '
{{ major_update_warning_text }}
';
}
diff --git a/core/modules/update/src/ReleaseInfo.php b/core/modules/update/src/ModuleVersionParser.php
similarity index 77%
rename from core/modules/update/src/ReleaseInfo.php
rename to core/modules/update/src/ModuleVersionParser.php
index 03991ce00f..ff2cbef1d9 100644
--- a/core/modules/update/src/ReleaseInfo.php
+++ b/core/modules/update/src/ModuleVersionParser.php
@@ -3,25 +3,25 @@
namespace Drupal\update;
/**
- * Provides a value object for update release data.
+ * Provides a module version parser.
*/
-class ReleaseInfo {
+class ModuleVersionParser {
/**
- * The release data.
+ * The version_string.
*
- * @var array
+ * @var string
*/
- protected $data;
+ protected $version;
/**
- * Constructs an ReleaseInfo object.
+ * Constructs a ModuleVersionParser object.
*
- * @param array $data
- * The release data.
+ * @param string $version
+ * The version string.
*/
- public function __construct(array $data) {
- $this->data = $data;
+ public function __construct($version) {
+ $this->version = $version;
}
/**
@@ -64,7 +64,7 @@ public function getPatchVersion() {
* The version string.
*/
private function getVersionString() {
- $original_version = $this->data['version'];
+ $original_version = $this->version;
$version = strpos($original_version, '8.x-') === 0 ? str_replace('8.x-', '', $original_version) : $original_version;
return $version;
}
@@ -81,8 +81,14 @@ public function getVersionExtra() {
return count($last_version_parts) === 1 ? NULL : $last_version_parts[1];
}
- public function getBranch() {
- $version = $this->data['version'];
+ /**
+ * Gets the support branch.
+ *
+ * @return string
+ * The support branch as is used in update XML files.
+ */
+ public function getSupportBranch() {
+ $version = $this->version;
if ($extra = $this->getVersionExtra()) {
$version = str_replace("-$extra", '', $version);
}
diff --git a/core/modules/update/tests/src/Unit/ReleaseInfoTest.php b/core/modules/update/tests/src/Unit/ModuleVersionParserTest.php
similarity index 82%
rename from core/modules/update/tests/src/Unit/ReleaseInfoTest.php
rename to core/modules/update/tests/src/Unit/ModuleVersionParserTest.php
index 7054df4436..580dd19562 100644
--- a/core/modules/update/tests/src/Unit/ReleaseInfoTest.php
+++ b/core/modules/update/tests/src/Unit/ModuleVersionParserTest.php
@@ -3,14 +3,14 @@
namespace Drupal\Tests\update\Unit;
use Drupal\Tests\UnitTestCase;
-use Drupal\update\ReleaseInfo;
+use Drupal\update\ModuleVersionParser;
/**
- * @coversDefaultClass \Drupal\update\ReleaseInfo
+ * @coversDefaultClass \Drupal\update\ModuleVersionParser
*
* @group update
*/
-class ReleaseInfoTest extends UnitTestCase {
+class ModuleVersionParserTest extends UnitTestCase {
/**
* @covers ::getMajorVersion
@@ -18,7 +18,7 @@ class ReleaseInfoTest extends UnitTestCase {
* @dataProvider providerVersionInfos
*/
public function testGetMajorVersion($version, $excepted_version_info) {
- $releaseInfo = new ReleaseInfo(['version' => $version]);
+ $releaseInfo = new ModuleVersionParser($version);
$this->assertSame($excepted_version_info['major'], $releaseInfo->getMajorVersion());
}
@@ -28,7 +28,7 @@ public function testGetMajorVersion($version, $excepted_version_info) {
* @dataProvider providerVersionInfos
*/
public function testGetMinorVersion($version, $excepted_version_info) {
- $releaseInfo = new ReleaseInfo(['version' => $version]);
+ $releaseInfo = new ModuleVersionParser($version);
$this->assertSame($excepted_version_info['minor'], $releaseInfo->getMinorVersion());
}
@@ -38,7 +38,7 @@ public function testGetMinorVersion($version, $excepted_version_info) {
* @dataProvider providerVersionInfos
*/
public function testGetPatchVersion($version, $excepted_version_info) {
- $releaseInfo = new ReleaseInfo(['version' => $version]);
+ $releaseInfo = new ModuleVersionParser($version);
$this->assertSame($excepted_version_info['patch'], $releaseInfo->getPatchVersion());
}
@@ -48,18 +48,18 @@ public function testGetPatchVersion($version, $excepted_version_info) {
* @dataProvider providerVersionInfos
*/
public function testGetVersionExtra($version, $excepted_version_info) {
- $releaseInfo = new ReleaseInfo(['version' => $version]);
+ $releaseInfo = new ModuleVersionParser($version);
$this->assertSame($excepted_version_info['extra'], $releaseInfo->getVersionExtra());
}
/**
- * @covers ::getBranch
+ * @covers ::getSupportBranch
*
* @dataProvider providerVersionInfos
*/
- public function testGetBranch($version, $excepted_version_info) {
- $releaseInfo = new ReleaseInfo(['version' => $version]);
- $this->assertSame($excepted_version_info['branch'], $releaseInfo->getBranch());
+ public function testGetSupportBranch($version, $excepted_version_info) {
+ $releaseInfo = new ModuleVersionParser($version);
+ $this->assertSame($excepted_version_info['branch'], $releaseInfo->getSupportBranch());
}
/**
diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc
index 377184553c..be79cce0af 100644
--- a/core/modules/update/update.compare.inc
+++ b/core/modules/update/update.compare.inc
@@ -5,7 +5,7 @@
* Code required only when comparing available updates to existing data.
*/
-use Drupal\update\ReleaseInfo;
+use Drupal\update\ModuleVersionParser;
/**
* Determines version and type information for currently installed projects.
@@ -234,37 +234,35 @@ function update_calculate_project_update_status(&$project_data, $available) {
}
// Figure out the target major version.
- $existing_release_info = new ReleaseInfo(['version' => $project_data['existing_version']]);
+ $existing_version_parser = new ModuleVersionParser($project_data['existing_version']);
+ $existing_major = $existing_version_parser->getMajorVersion();
$supported_branches = [];
if (isset($available['supported_branches'])) {
$supported_branches = explode(',', $available['supported_branches']);
}
- if (in_array($existing_release_info->getBranch(), $supported_branches)) {
+ if (in_array($existing_version_parser->getSupportBranch(), $supported_branches)) {
// Still supported, stay at the current major version.
- $target_branch = $existing_release_info->getBranch();
- $target_major = $existing_release_info->getMajorVersion();
+ $target_major = $existing_major;
}
elseif (isset($available['recommended_branch'])) {
// Since 'recommended_branch' is defined, we know this is the new XML
// format. Therefore, we know the current release is unsupported since
// its major version was not in the 'supported_branches' list. We should
// find the best release from the recommended major version.
- $target_branch = $available['recommended_branch'];
- $branch_release_info = new ReleaseInfo(['version' => $target_branch . 'x']);
- $target_major = $branch_release_info->getMajorVersion();
+ $branch_version_parser = new ModuleVersionParser($available['recommended_branch'] . 'x');
+ $target_major = $branch_version_parser->getMajorVersion();
$project_data['status'] = UPDATE_NOT_SUPPORTED;
}
elseif (isset($available['default_major'])) {
// Older release history XML file without recommended, so recommend
// the currently defined "default_major" version.
- $target_branch = $available['default_major'];
+ $target_major = $available['default_major'];
}
else {
// Malformed XML file? Stick with the current branch.
- $target_branch = $existing_release_info->getBranch();
- $target_major = $existing_release_info->getMajorVersion();
+ $target_major = $existing_major;
}
// Make sure we never tell the admin to downgrade. If we recommended an
@@ -274,8 +272,7 @@ function update_calculate_project_update_status(&$project_data, $available) {
// unsupported, and there's nothing newer for them to upgrade to, we
// can't print out a "Recommended version", but just have to tell them
// what they have is unsupported and let them figure it out.
- $target_branch = max($existing_release_info->getBranch(), $target_branch);
- $target_major = max($existing_release_info->getMajorVersion(), $target_major);
+ $target_major = max($existing_major, $target_major);
$release_patch_changed = '';
$patch = '';
@@ -298,7 +295,7 @@ function update_calculate_project_update_status(&$project_data, $available) {
return;
}
foreach ($available['releases'] as $version => $release) {
- $release_info = new ReleaseInfo($release);
+ $release_version_parser = new ModuleVersionParser($release['version']);
// First, if this is the existing release, check a few conditions.
if ($project_data['existing_version'] === $version) {
if (isset($release['terms']['Release type']) &&
@@ -338,15 +335,15 @@ function update_calculate_project_update_status(&$project_data, $available) {
continue;
}
- $release_major_version = $release_info->getMajorVersion();
- $release_patch_version = $release_info->getPatchVersion();
+ $release_major_version = $release_version_parser->getMajorVersion();
+ $release_patch_version = $release_version_parser->getPatchVersion();
// See if this is a higher major version than our target and yet still
// supported. If so, record it as an "Also available" release.
// Note: Some projects have a HEAD release from CVS days, which could
// 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_info->getMajorVersion() > $target_major) {
- if (in_array($release_info->getBranch(), $supported_branches)) {
+ if ($release_major_version !== NULL && $release_major_version > $target_major) {
+ if (in_array($release_version_parser->getSupportBranch(), $supported_branches)) {
if (!isset($project_data['also'])) {
$project_data['also'] = [];
}
@@ -368,15 +365,15 @@ function update_calculate_project_update_status(&$project_data, $available) {
// Look for the 'latest version' if we haven't found it yet. Latest is
// defined as the most recent version for the target major version.
if (!isset($project_data['latest_version'])
- && $release_info->getMajorVersion() == $target_major) {
+ && $release_major_version == $target_major) {
$project_data['latest_version'] = $version;
$project_data['releases'][$version] = $release;
}
// Look for the development snapshot release for this branch.
if (!isset($project_data['dev_version'])
- && $release_info->getMajorVersion() == $target_major
- && $release_info->getVersionExtra() === 'dev') {
+ && $release_major_version == $target_major
+ && $release_version_parser->getVersionExtra() === 'dev') {
$project_data['dev_version'] = $version;
$project_data['releases'][$version] = $release;
}
@@ -384,13 +381,13 @@ function update_calculate_project_update_status(&$project_data, $available) {
// 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_info->getMajorVersion() == $target_major
+ && $release_major_version == $target_major
&& $release_patch_version !== NULL) {
if ($patch != $release_patch_version) {
$patch = $release_patch_version;
$release_patch_changed = $release;
}
- if ($release_info->getVersionExtra() === NULL && $patch == $release_patch_version) {
+ if ($release_version_parser->getVersionExtra() === NULL && $patch == $release_patch_version) {
$project_data['recommended'] = $release_patch_changed['version'];
$project_data['releases'][$release_patch_changed['version']] = $release_patch_changed;
}