Commit 8d64a717 authored by Benni Mack's avatar Benni Mack
Browse files

[TASK] Add additional fields to version table for TER v1 migration

Four new fields are added to the tx_terfe2_domain_model_version table,
which are migrated through a one-time-command "ter:migratedetailstov2"
from TER v1 tables, and updated on TER v1 Upload as well.

These fields are available in a normalized way, but are also needed
flat for the extensions.xml.gz file, which makes the SQL query for building
the XML faster in the future (next update), and allows for dropping the
tx_ter_extensions table in the next iteration.

The fields are currently not added to TCA as they serve no purpose
(yet) for the frontend as it is up to decide if we keep the "*_authors" table
or keep the extension version information in the main *_version table.
parent 1cf68831
Pipeline #9354 passed with stages
in 8 minutes and 51 seconds
<?php
declare(strict_types = 1);
namespace T3o\Ter\Command;
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 TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* One time command, can be removed in late 2020.
*/
class MigrateExtensionDetailsToV2Command extends Command
{
protected function configure()
{
$this->setDescription('One-time-migration. Migrates existing data from tx_ter_extensions.* into tx_terfe2_domain_model.version.*');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->section('Updating all items in tx_terfe2_domain_model_version now');
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_terfe2_domain_model_version');
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$itemsProcessed = 0;
$stmt = $queryBuilder
->select(
'v.uid',
'v.version_string',
'e.ext_key'
)
->from('tx_terfe2_domain_model_version', 'v')
->leftJoin(
'v',
'tx_terfe2_domain_model_extension',
'e',
$queryBuilder->expr()->eq('e.uid', $queryBuilder->quoteIdentifier('v.extension'))
)
->where(
$queryBuilder->expr()->isNull('v.authorname')
)
->execute();
// Prepare the SELECT query (v1)
$queryBuilderForSource = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_ter_extensions');
$queryBuilderForSource
->select('dependencies', 'authorname', 'authoremail', 'authorcompany')
->from('tx_ter_extensions')
->where(
$queryBuilderForSource->expr()->eq('extensionkey', $queryBuilderForSource->createNamedParameter('key', \PDO::PARAM_STR, ':key')),
$queryBuilderForSource->expr()->eq('version', $queryBuilderForSource->createNamedParameter('version', \PDO::PARAM_STR, ':version'))
);
while ($row = $stmt->fetch()) {
// Execute the SELECT query (v1)
$originalRow = $queryBuilderForSource
->setParameters(
[
':key' => $row['ext_key'],
':version' => $row['version_string']
]
)
->execute()
->fetch();
// Update the v2 table
if ($originalRow) {
$connection->update('tx_terfe2_domain_model_version', $originalRow, ['uid' => $row['uid']]);
$itemsProcessed++;
}
}
$io->success('Done. Updated ' . $itemsProcessed . ' items.');
return 0;
}
}
......@@ -17,4 +17,7 @@ return [
'ter:migrateextensiondetails' => [
'class' => \T3o\Ter\Command\MigrateExtensionDetailsCommand::class
],
'ter:migratedetailstov2' => [
'class' => \T3o\Ter\Command\MigrateExtensionDetailsToV2Command::class
],
];
......@@ -275,7 +275,11 @@ class ImportExtensionsFromQueueTask extends Task
'software_relations' => 0,
't3x_file_size' => @filesize($t3xFile),
'zip_file_size' => 0,
'composer_info' => $extData['composerinfo']
'composer_info' => $extData['composerinfo'],
'dependencies' => (string)$extData['dependencies'],
'authorname' => (string)$extData['authorname'],
'authoremail' => (string)$extData['authoremail'],
'authorcompany' => (string)$extData['authorcompany'],
];
if ($extData['composerinfo']) {
......
......@@ -83,6 +83,11 @@ CREATE TABLE tx_terfe2_domain_model_version (
t3x_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
zip_file_size bigint(15) unsigned DEFAULT '0' NOT NULL,
composer_info text NOT NULL,
# not in TCA as this is purely needed for DB-only purpose for the time being
dependencies text DEFAULT '',
authorname tinytext DEFAULT '',
authoremail tinytext DEFAULT '',
authorcompany tinytext DEFAULT '',
tstamp int(11) unsigned DEFAULT '0' NOT NULL,
crdate int(11) unsigned DEFAULT '0' NOT NULL,
......
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