Commit f056aa8d authored by Thomas Löffler's avatar Thomas Löffler
Browse files

[TASK] Remove migration commands which are used one-time

parent 9bf6f24a
Pipeline #21492 passed with stages
in 6 minutes and 8 seconds
<?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\Input\InputOption;
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.')
->addOption(
'skipNonEmptyFields',
null,
InputOption::VALUE_OPTIONAL,
'If command is used a second time, skip already migrated fields.',
false
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$skipNonEmptyFields = (bool)$input->getOption('skipNonEmptyFields');
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$queryBuilder = $connectionPool->getQueryBuilderForTable('tx_terfe2_domain_model_version');
$io->section('Updating field \'compatible_typo3_versions\' of all \'tx_terfe2_domain_model_version\' rows now');
$io->warning('Please make sure, the new column \'compatible_typo3_versions\' exists.');
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder
->select('uid', 'dependencies')
->from('tx_terfe2_domain_model_version');
if ($skipNonEmptyFields) {
$io->writeln('<info>Rows with non empty fields are skipped.</info>');
$queryBuilder->where(
$queryBuilder->expr()->isNull('compatible_typo3_versions')
);
}
$result = $queryBuilder->execute();
$itemsProcessed = 0;
while ($row = $result->fetchAssociative()) {
// First check if the data is still in old serialized format
$dependencies = (array)(unserialize((string)($row['dependencies'] ?? ''), ['allowed_classes' => false]) ?: []);
if ($dependencies === []) {
// Fallback for the new JSON format
try {
$dependencies = (array)(json_decode((string)($row['dependencies'] ?? ''), true, 512, JSON_THROW_ON_ERROR) ?: []);
if ($dependencies === []) {
// If still empty move on with next row
continue;
}
} catch (\JsonException $e) {
continue;
}
}
$compatibleTypo3Versions = VersionUtility::getCompatibleTypo3Versions($dependencies);
if ($compatibleTypo3Versions === '') {
continue;
}
$connectionPool
->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;
}
}
<?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 TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* One time command, can be removed in late 2020.
*/
class MigrateDependenciesToJson extends Command
{
protected function configure(): void
{
$this->setDescription('One-time-migration. Migrates tx_terfe2_domain_model_version.dependencies from serialized array to JSON.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->section('Updating field \'dependencies\' 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();
$queryBuilder
->select('uid', 'dependencies')
->from('tx_terfe2_domain_model_version');
$result = $queryBuilder->execute();
$itemsProcessed = 0;
while ($row = $result->fetchAssociative()) {
$dependencies = (string)($row['dependencies'] ?? '');
if ($dependencies === '' || strpos($dependencies, 'a:') === false) {
// skip already migrated or not serialized row
continue;
}
try {
$connectionPool
->getConnectionForTable('tx_terfe2_domain_model_version')
->update(
'tx_terfe2_domain_model_version',
['dependencies' => json_encode((array)(unserialize($dependencies, ['allowed_classes' => false]) ?: []), JSON_THROW_ON_ERROR)],
['uid' => $row['uid']]
);
$itemsProcessed++;
} catch (\JsonException $e) {
$io->error('Could not update record: \'' . $row['uid'] . '\'');
}
}
$io->success('Done. Updated ' . $itemsProcessed . ' items.');
return 0;
}
}
......@@ -17,12 +17,6 @@ return [
'ter_fe2:fetchTranslationStatus' => [
'class' => \T3o\TerFe2\Command\FetchTranslationStatusCommand::class
],
'ter_fe2:addCompatibleTypo3Versions' => [
'class' => \T3o\TerFe2\Command\AddCompatibleTypo3Versions::class
],
'ter_fe2:migrateDependenciesToJson' => [
'class' => \T3o\TerFe2\Command\MigrateDependenciesToJson::class
],
'ter:createExtensionIndexXml' => [
'class' => \T3o\TerFe2\Command\CreateExtensionIndexCommand::class
],
......
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