diff --git a/Classes/helpers/class.tx_caretaker_LatestVersionsHelper.php b/Classes/helpers/class.tx_caretaker_LatestVersionsHelper.php index d2ac9019..095a51a5 100644 --- a/Classes/helpers/class.tx_caretaker_LatestVersionsHelper.php +++ b/Classes/helpers/class.tx_caretaker_LatestVersionsHelper.php @@ -52,6 +52,7 @@ class tx_caretaker_LatestVersionsHelper protected static $releaseJsonFeed = 'https://get.typo3.org/json'; /** + * @throws Exception * @return bool */ public static function updateLatestTypo3VersionRegistry() @@ -60,24 +61,18 @@ public static function updateLatestTypo3VersionRegistry() if (!is_array($releases)) { throw new Exception( - 'It seems like ' . self::$releaseJsonFeed . - ' did not return the json string for the TYPO3 releases. Maybe it has been moved!?' + 'It seems like ' . self::$releaseJsonFeed . + ' did not return the json string for the TYPO3 releases. Maybe it has been moved!?' ); } - $max = array(); - $stable = array(); - foreach ($releases as $major => $details) { - if (is_array($details) && !empty($details['latest'])) { - $max[$major] = $details['latest']; - } + $latestVersions = self::getLatestFromReleases($releases); - if (is_array($details) && !empty($details['stable'])) { - $stable[$major] = $details['stable']; - } - } - \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry')->set('tx_caretaker', 'TYPO3versions', $max); - \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry')->set('tx_caretaker', 'TYPO3versionsStable', $stable); + /** @var \TYPO3\CMS\Core\Registry $registry */ + $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Registry'); + $registry->set('tx_caretaker', 'TYPO3versions', $latestVersions['max']); + $registry->set('tx_caretaker', 'TYPO3versionsStable', $latestVersions['stable']); + $registry->set('tx_caretaker', 'TYPO3versionsSecurity', $latestVersions['security']); return true; } @@ -113,4 +108,38 @@ protected static function curlRequest($requestUrl = false) return $response; } + + /** + * @param array $releases + * @return array + */ + public static function getLatestFromReleases($releases) + { + $max = array(); + $stable = array(); + $security = array(); + foreach ($releases as $major => $details) { + if (is_array($details) && !empty($details['latest'])) { + $max[$major] = $details['latest']; + } + + if (is_array($details) && !empty($details['stable'])) { + $stable[$major] = $details['stable']; + } + if (is_array($details) && is_array($details['releases'])) { + foreach ($details['releases'] as $version => $versionDetails) { + $security[$major] = $version; + if ($versionDetails['type'] === 'security') { + break; + } + } + } + } + + return array( + 'max' => $max, + 'stable' => $stable, + 'security' => $security, + ); + } } diff --git a/Tests/Unit/Fixtures/versions.json b/Tests/Unit/Fixtures/versions.json new file mode 100644 index 00000000..bd40ddba --- /dev/null +++ b/Tests/Unit/Fixtures/versions.json @@ -0,0 +1,88 @@ +{ + "3": { + "releases": { + "3.0.2": { + "version": "3.0.2", + "type": "regular" + }, + "3.0.1": { + "version": "3.0.1", + "type": "regular" + }, + "3.0.0": { + "version": "3.0.0", + "type": "release" + } + }, + "latest": "3.0.2", + "stable": "3.0.1", + "active": true + }, + "2": { + "releases": { + "2.1.2": { + "version": "2.1.2", + "type": "regular" + }, + "2.1.1": { + "version": "2.1.1", + "type": "security" + }, + "2.1.0": { + "version": "2.1.0", + "type": "release" + }, + "2.0.2": { + "version": "2.0.2", + "type": "regular" + }, + "2.0.1": { + "version": "2.0.1", + "type": "security" + }, + "2.0.0": { + "version": "2.0.0", + "type": "release" + } + }, + "latest": "2.1.2", + "stable": "2.1.2", + "active": true + }, + "1": { + "releases": { + "1.1.2": { + "version": "1.1.2", + "type": "regular" + }, + "1.1.1": { + "version": "1.1.1", + "type": "security" + }, + "1.1.0": { + "version": "1.1.0", + "type": "release" + }, + "1.0.2": { + "version": "1.0.2", + "type": "regular" + }, + "1.0.1": { + "version": "1.0.1", + "type": "security" + }, + "1.0.0": { + "version": "1.0.0", + "type": "release" + } + }, + "latest": "1.1.2", + "stable": "1.1.2", + "active": true + }, + + "latest_stable": "2.1.2", + "latest_old_stable": "1.1.2", + "latest_lts": "2.1.2", + "latest_old_lts": "1.1.2" +} \ No newline at end of file diff --git a/Tests/Unit/LatestVersionsHelperTest.php b/Tests/Unit/LatestVersionsHelperTest.php new file mode 100644 index 00000000..cdef7a79 --- /dev/null +++ b/Tests/Unit/LatestVersionsHelperTest.php @@ -0,0 +1,68 @@ +releases = json_decode($json, true); + } + + public function testLatest() + { + $latest = \tx_caretaker_LatestVersionsHelper::getLatestFromReleases($this->releases); + + $this->assertEquals('3.0.2', $latest['max']['3'], 'v3: latest release'); + $this->assertEquals('3.0.1', $latest['stable']['3'], 'v3: stable release'); + $this->assertEquals('3.0.0', $latest['security']['3'], 'v3: no security release falls back to the first release'); + + $this->assertEquals('2.1.2', $latest['max']['2'], 'v2: latest release'); + $this->assertEquals('2.1.2', $latest['stable']['2'], 'v2: stable release'); + $this->assertEquals('2.1.1', $latest['security']['2'], 'v2: security release'); + + $this->assertEquals('1.1.2', $latest['max']['1'], 'v1: latest release'); + $this->assertEquals('1.1.2', $latest['stable']['1'], 'v1: stable release'); + $this->assertEquals('1.1.1', $latest['security']['1'], 'v1: security release'); + } +}