Commit 5afeac7c authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Move Core version check to LTSVersionService

This change provides a way centralize the Core version logic
in LTSVersionService
parent e573c62e
Pipeline #9174 passed with stages
in 7 minutes and 3 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,8 +113,6 @@ 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)) {
......@@ -133,6 +131,7 @@ class ExtensionVersion
}
}
}
$coreVersionService = GeneralUtility::makeInstance(LTSVersionService::class);
[$lower, $upper] = GeneralUtility::trimExplode('-', $typo3Range);
if (empty($lower) || empty($upper)) {
// Either part of the range is empty
......@@ -146,11 +145,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, $coreVersionService->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, $coreVersionService->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 +248,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];
}
}
......@@ -255,4 +255,32 @@ class LTSVersionService
return ($mainVersion >= self::FIRST_LTS_VERSION_WITH_MAIN_VERSION_NUMBER && $mainVersion <= $this->getLatestDevelopmentVersion()) || in_array($firstRelease, $this->ltsVersionsWithMinorVersions, true);
}
/**
* Returns 6.2.0 for the oldest supported LTS version.
*
* @return string
*/
public function getOldestSupportedVersion(): string
{
$result = $this->getELTSVersions();
$oldestELTSVersion = reset($result);
return VersionNumberUtility::convertIntegerToVersionNumber($oldestELTSVersion);
}
/**
* Returns 10.99.999 as the latest supported version
*
* @return string
*/
public function getNewestSupportedVersion(): string
{
$result = $this->getActiveVersions();
$latestMajorRelease = array_pop($result);
$asString = VersionNumberUtility::convertIntegerToVersionNumber($latestMajorRelease);
$stringParts = explode('.', $asString);
$stringParts[1] = 99;
$stringParts[2] = 999;
return implode('.', $stringParts);
}
}
......@@ -163,6 +163,8 @@ class LTSVersionServiceTest extends UnitTestCase
{
$eltsVersions = $this->subject->getELTSVersions();
self::assertSame(6002000, array_shift($eltsVersions));
$eltsVersionAsString = $this->subject->getOldestSupportedVersion();
self::assertSame('6.2.0', $eltsVersionAsString);
}
/**
......@@ -172,6 +174,8 @@ class LTSVersionServiceTest extends UnitTestCase
{
$activeVersions = $this->subject->getActiveVersions();
self::assertSame(10000000, array_pop($activeVersions));
$activeVersion = $this->subject->getNewestSupportedVersion();
self::assertSame('10.99.999', $activeVersion);
}
/**
......
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