Commit 397e0361 authored by Benni Mack's avatar Benni Mack

[TASK] Move LTS version check into centralized LTS version Service

The LTS version service now also handles checks for oldest / newest
versions when uploading a new release.
parent a24e80ac
Pipeline #9168 passed with stages
in 6 minutes and 41 seconds
......@@ -15,7 +15,7 @@ use T3o\Ter\Exception\FailedDependencyException;
use T3o\Ter\Exception\InternalServerErrorException;
use T3o\Ter\Exception\NotFoundException;
use T3o\Ter\Exception\UnauthorizedException;
use TYPO3\CMS\Core\Core\Environment;
use T3o\TerFe2\Service\LTSVersionService;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -113,13 +113,13 @@ class ExtensionVersion
*/
public function checkExtensionDependencyOnSupportedTypo3Version($dependencies): void
{
[$oldestSupportedCoreVersion, $newestCoreVersion] = $this->getSupportedCoreVersions();
// Compare currently supported core version with the dependency in the extension
$typo3Range = '';
if (!is_array($dependencies)) {
throw new FailedDependencyException('No dependency for TYPO3 Core given.', ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYINCORRECT);
}
$versionService = GeneralUtility::makeInstance(LTSVersionService::class);
// Compare currently supported core version with the dependency in the extension
$typo3Range = '';
foreach ($dependencies as $dependency) {
if (is_object($dependency)) {
if ($dependency->kind == 'depends' && $dependency->extensionKey == 'typo3') {
......@@ -146,11 +146,11 @@ class ExtensionVersion
// Either part is a zero version (n < n.0 < n.0.0)
throw new FailedDependencyException('Invalid version for TYPO3 Core given.', ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYINCORRECT);
}
if (version_compare($upper, $oldestSupportedCoreVersion, '<')) {
if (version_compare($upper, $versionService->getOldestSupportedVersion(), '<')) {
// Upper limit is lower than oldest core version
throw new FailedDependencyException('Invalid version constraint for TYPO3 Core given. Upper limit is lower than oldest core version.', ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYINCORRECT);
}
if (version_compare($upper, $newestCoreVersion, '>')) {
if (version_compare($upper, $versionService->getNewestSupportedVersion(), '>')) {
// Upper limit is larger than newest core version
throw new FailedDependencyException('Invalid version constraint for TYPO3 Core given. Upper limit is higher than latest core version.', ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYINCORRECT);
}
......@@ -249,63 +249,4 @@ class ExtensionVersion
}
}
}
/**
* Helper functions to fetch the latest and lowest supported TYPO3 Core versions. This method should be extracted into its own class
*
* @return array
* @throws FailedDependencyException
*/
protected function getSupportedCoreVersions(): array
{
$coreVersionData = GeneralUtility::getUrl(
Environment::getPublicPath() . '/' . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json'
);
$currentCores = json_decode($coreVersionData, true);
if ($currentCores === null) {
throw new FailedDependencyException('No core data found', ResultCodes::ERROR_UPLOADEXTENSION_TYPO3DEPENDENCYCHECKFAILED);
}
// Collect currently supported core versions
$supportedCoreVersions = [];
$oldestSupportedCoreVersion = '99.99.99';
$newestCoreVersion = '0.0.0';
foreach ($currentCores as $version => $coreInfo) {
if (is_array($coreInfo) && ($coreInfo['active'] === true || $coreInfo['elts'] === true)) {
// Only use keys that represent a branch number
if (strpos((string)$version, '.') && preg_match('/^(\d+)\.\d+$/', $version, $matches)) {
$latestBranchVersion = $coreInfo['latest'];
} else {
// Manage core version without branch (>= 7 LTS)
$latestBranchVersion = $version . '.99.999';
}
// Checks the latest version
if (!preg_match('/dev|alpha/', $latestBranchVersion)) {
$supportedCoreVersions[] = $latestBranchVersion;
if (version_compare($newestCoreVersion, $latestBranchVersion, '<')) {
$newestCoreVersion = $latestBranchVersion;
}
}
// Check the oldest active version
if (version_compare($version . '.0', (string)$oldestSupportedCoreVersion, '<')) {
$oldestSupportedCoreVersion = $version;
}
}
}
// clean newest core version
preg_match('/^(\d+)\.(\d+)\.(\d+)/', $newestCoreVersion, $matches);
$newestCoreVersion = $matches[1] . '.' . $matches[2] . '.999';
// get first beta of oldest active version
$oldestSupportedCoreVersionReleases = array_reverse($currentCores[$oldestSupportedCoreVersion]['releases']);
foreach ($oldestSupportedCoreVersionReleases as $subVersion => $subVersionInfo) {
if (!preg_match('/dev|alpha/', $subVersion)) {
$oldestSupportedCoreVersion = $subVersion;
break;
}
}
return [$oldestSupportedCoreVersion, $newestCoreVersion];
}
}
......@@ -50,9 +50,9 @@ class LTSVersionService
public function buildReleases()
{
foreach ($this->coreData as $release) {
foreach ($this->coreData as $majorVersion => $release) {
if (is_array($release)) {
$this->releases[] = $release;
$this->releases[$majorVersion] = $release;
}
}
}
......@@ -255,4 +255,55 @@ class LTSVersionService
return ($mainVersion >= self::FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER && $mainVersion <= $this->getLatestDevelopmentVersion()) || in_array($firstRelease, $this->ltsVersionsWithMinorVersions, true);
}
public function getOldestSupportedVersion(): string
{
$oldestSupportedCoreVersion = '99.99.99';
foreach ($this->releases as $version => $coreInfo) {
if ($coreInfo['active'] !== true && $coreInfo['elts'] !== true) {
continue;
}
// Check the oldest active version
if (version_compare($version . '.0', (string)$oldestSupportedCoreVersion, '<')) {
$oldestSupportedCoreVersion = $version;
}
}
// get first beta of oldest active version
if (is_array($this->releases[$oldestSupportedCoreVersion]['releases'])) {
$oldestSupportedCoreVersionReleases = array_reverse($this->releases[$oldestSupportedCoreVersion]['releases']);
foreach ($oldestSupportedCoreVersionReleases as $subVersion => $subVersionInfo) {
if (!preg_match('/dev|alpha/', $subVersion)) {
$oldestSupportedCoreVersion = $subVersion;
break;
}
}
}
return $oldestSupportedCoreVersion;
}
public function getNewestSupportedVersion(): string
{
$newestCoreVersion = '0.0.0';
foreach ($this->releases as $version => $coreInfo) {
if ($coreInfo['active'] !== true && $coreInfo['elts'] !== true) {
continue;
}
// Only use keys that represent a branch number
if (strpos((string)$version, '.') && preg_match('/^(\d+)\.\d+$/', $version, $matches)) {
$latestBranchVersion = $coreInfo['latest'];
} else {
// Manage core version without branch (>= 7 LTS)
$latestBranchVersion = $version . '.99.999';
}
// Checks the latest version
if (!preg_match('/dev|alpha/', $latestBranchVersion) && version_compare($newestCoreVersion, $latestBranchVersion, '<')) {
$newestCoreVersion = $latestBranchVersion;
}
}
// clean newest core version
preg_match('/^(\d+)\.(\d+)\.(\d+)/', $newestCoreVersion, $matches);
return $matches[1] . '.' . $matches[2] . '.999';
}
}
......@@ -34,9 +34,9 @@ class LTSVersionServiceTest extends UnitTestCase
$this->subject = GeneralUtility::makeInstance(LTSVersionService::class);
$this->subject->coreData = $this->getSampleData();
$this->subject->releases = [];
foreach ($this->subject->coreData as $release) {
foreach ($this->subject->coreData as $version => $release) {
if (is_array($release)) {
$this->subject->releases[] = $release;
$this->subject->releases[$version] = $release;
}
}
}
......@@ -149,6 +149,27 @@ class LTSVersionServiceTest extends UnitTestCase
);
}
/**
* @test
*/
public function getOldestVersionReturnsStringWithOldestVersionIncludingELTS()
{
self::assertSame(
'6.2',
$this->subject->getOldestSupportedVersion()
);
}
/**
* @test
*/
public function getNewestVersionReturnsStringWithNewestNonLTSVersion()
{
self::assertSame(
'10.99.999',
$this->subject->getNewestSupportedVersion()
);
}
/**
* Return Sample Json Data for testing purpose
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment