Commit 25200f66 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[TASK] Add new field for a list of compatible typo3 versions

This adds a new field `compatible_typo3_versions` to the
`tx_terfe2_domain_model_version` table to provide a list of
compatible TYPO3 versions for each extension version.

This information is needed in the database to allow simple SQL
queries, e.g. used for the REST API `GET /extension` endpoint.

The information is automatically added while uploading a new
extension version. Furthermore, a one time migration symfony
command is available to add this data to already existing records.
parent e3e21a8c
Pipeline #9858 passed with stages
in 5 minutes and 23 seconds
......@@ -21,6 +21,7 @@ use T3o\Ter\Exception\UnauthorizedException;
use T3o\TerFe2\Service\LTSVersionService;
use T3o\TerFe2\Utility\ArchiveUtility;
use T3o\TerFe2\Utility\CategoryUtility;
use T3o\TerFe2\Utility\VersionUtility;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -546,6 +547,7 @@ class ExtensionVersion
't3x_file_size' => @filesize($t3xFile),
'zip_file_size' => 0,
'composer_info' => json_encode($composerInfo),
'compatible_typo3_versions' => VersionUtility::getCompatibleTypo3Versions($dependenciesArr),
'dependencies' => (string)serialize($dependenciesArr),
'authorname' => (string)$extensionInfoData->metaData->authorName,
'authoremail' => (string)$extensionInfoData->metaData->authorEmail,
......
<?php
declare(strict_types = 1);
namespace T3o\TerFe2\Command;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use T3o\TerFe2\Utility\VersionUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* One time command, can be removed in late 2020.
*/
class AddCompatibleTypo3Versions extends Command
{
protected function configure(): void
{
$this->setDescription('One-time-migration. Adds tx_terfe2_domain_model_version.compatible_typo3_versions from dependencies data.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->section('Updating field \'compatible_typo3_versions\' of all \'tx_terfe2_domain_model_version\' rows now');
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_terfe2_domain_model_version');
$queryBuilder->getRestrictions()->removeAll();
$statement = $queryBuilder
->select('uid', 'dependencies')
->from('tx_terfe2_domain_model_version')
->execute();
$itemsProcessed = 0;
while ($row = $statement->fetchAssociative()) {
// @todo Once https://gitlab.typo3.org/t3o/ter/-/merge_requests/600 is merged,
// @todo we need to json_encode the dependencies instead of unserialize
$compatibleTypo3Versions = VersionUtility::getCompatibleTypo3Versions(
(array)(unserialize((string)($row['dependencies'] ?? ''), ['allowed_classes' => false]) ?: [])
);
if ($compatibleTypo3Versions === '') {
continue;
}
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_terfe2_domain_model_version')
->update(
'tx_terfe2_domain_model_version',
['compatible_typo3_versions' => $compatibleTypo3Versions],
['uid' => $row['uid']]
);
$itemsProcessed++;
}
$io->success('Done. Updated ' . $itemsProcessed . ' items.');
return 0;
}
}
......@@ -57,4 +57,29 @@ class VersionUtility
return false;
}
/**
* Generates a list with compatible TYPO3 versions from given dependencies
*
* @param array $dependencies
* @return string
*/
public static function getCompatibleTypo3Versions(array $dependencies): string
{
$compatibleTypo3Versions = [];
foreach ($dependencies as $relation) {
if ((string)($relation['kind'] ?? '') !== 'depends'
|| (string)($relation['extensionKey'] ?? '') !== 'typo3'
) {
continue;
}
foreach (explode('-', (string)($relation['versionRange'] ?? '')) as $version) {
$parts = explode('.', $version);
$compatibleTypo3Versions[] = array_shift($parts);
}
}
return implode(',', array_unique($compatibleTypo3Versions));
}
}
......@@ -17,6 +17,9 @@ return [
'ter_fe2:fetchTranslationStatus' => [
'class' => \T3o\TerFe2\Command\FetchTranslationStatusCommand::class
],
'ter_fe2:addCompatibleTypo3Versions' => [
'class' => \T3o\TerFe2\Command\AddCompatibleTypo3Versions::class
],
'ter:createExtensionIndexXml' => [
'class' => \T3o\TerFe2\Command\CreateExtensionIndexCommand::class
],
......
......@@ -87,6 +87,7 @@ CREATE TABLE tx_terfe2_domain_model_version (
composer_info text NOT NULL,
# not in TCA as this is purely needed for DB-only purpose for the time being
dependencies text DEFAULT '',
compatible_typo3_versions text DEFAULT '',
authorname tinytext DEFAULT '',
authoremail tinytext DEFAULT '',
authorcompany tinytext DEFAULT '',
......
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