Commit db9d8328 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[TASK] Add command to migrate dependencies to JSON

parent 70202684
Pipeline #9848 failed with stages
in 2 minutes and 41 seconds
......@@ -545,8 +545,8 @@ class ExtensionVersion
'software_relations' => 0,
't3x_file_size' => @filesize($t3xFile),
'zip_file_size' => 0,
'composer_info' => json_encode($composerInfo),
'dependencies' => (string)serialize($dependenciesArr),
'composer_info' => json_encode($composerInfo) ?: '',
'dependencies' => json_encode($dependenciesArr) ?: '',
'authorname' => (string)$extensionInfoData->metaData->authorName,
'authoremail' => (string)$extensionInfoData->metaData->authorEmail,
'authorcompany' => (string)$extensionInfoData->metaData->authorCompany,
......
<?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);
$queryBuilderForDetails = $connectionPool->getQueryBuilderForTable('tx_terfe2_domain_model_version');
$queryBuilderForDetails->getRestrictions()->removeAll();
$statement = $queryBuilderForDetails
->select('uid', 'dependencies')
->from('tx_terfe2_domain_model_version')
->execute();
$itemsProcessed = 0;
while ($row = $statement->fetchAssociative()) {
$dependencies = (string)($row['dependencies'] ?? '');
if ($dependencies === '' || strpos($dependencies, 'a:') === false) {
// skip already migrated or not serialized row
continue;
}
try {
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_terfe2_domain_model_version')
->update(
'tx_terfe2_domain_model_version',
['dependencies' => json_encode((array)(unserialize($dependencies, [self::class]) ?: []), 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,6 +17,9 @@ return [
'ter_fe2:fetchTranslationStatus' => [
'class' => \T3o\TerFe2\Command\FetchTranslationStatusCommand::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