2 declare(strict_types = 1);
18 use Symfony\Component\Console\Command\Command;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Input\InputOption;
21 use Symfony\Component\Console\Output\OutputInterface;
22 use Symfony\Component\Console\Style\SymfonyStyle;
43 ->setDescription(
'Updates all database records which have a FlexForm field and the XML data does not match the chosen datastructure.')
44 ->setHelp(
'Traverse page tree and find and clean/update records with dirty FlexForm values. If you want to get more detailed information, use the --verbose option.')
48 InputOption::VALUE_REQUIRED,
49 'Setting start page in page tree. Default is the page tree root, 0 (zero)'
54 InputOption::VALUE_REQUIRED,
55 'Setting traversal depth. 0 (zero) will only analyze start page (see --pid), 1 will traverse one level of subpages etc.'
60 InputOption::VALUE_NONE,
61 'If this option is set, the records will not be updated, but only show the output which records would have been updated.'
76 $io =
new SymfonyStyle($input,
$output);
77 $io->title($this->getDescription());
89 if ($io->isVerbose()) {
90 $io->section(
'Searching the database now for records with FlexForms that need to be updated.');
94 $dryRun = $input->hasOption(
'dry-run') && $input->getOption(
'dry-run') !=
false ? true :
false;
99 if (!$io->isQuiet()) {
100 $io->note(
'Found ' . count($recordsToUpdate) .
' records with wrong FlexForms information.');
103 if (!empty($recordsToUpdate)) {
104 $io->section(
'Cleanup process starting now.' . ($dryRun ?
' (Not deleting now, just a dry run)' :
''));
109 $io->success(
'All done!');
111 $io->success(
'Nothing to do - You\'re all set!');
130 foreach (
$GLOBALS[
'TCA'] as $tableName => $tableConfiguration) {
131 if ($tableName !==
'pages') {
133 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
134 ->getQueryBuilderForTable($tableName);
136 $queryBuilder->getRestrictions()
139 $result = $queryBuilder
143 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT))
147 while ($rowSub = $result->fetch()) {
154 'uid,t3ver_wsid,t3ver_count',
158 if (is_array($versions)) {
159 foreach ($versions as $verRec) {
160 if (!$verRec[
'_CURRENT_VERSION']) {
173 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
174 ->getQueryBuilderForTable(
'pages');
176 $queryBuilder->getRestrictions()
179 $result = $queryBuilder
183 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT))
188 while ($row = $result->fetch()) {
195 if (is_array($versions)) {
196 foreach ($versions as $verRec) {
197 if (!$verRec[
'_CURRENT_VERSION']) {
203 return $dirtyFlexFormFields;
217 $flexObj = GeneralUtility::makeInstance(FlexFormTools::class);
218 foreach (
$GLOBALS[
'TCA'][$tableName][
'columns'] as $columnName => $columnConfiguration) {
219 if ($columnConfiguration[
'config'][
'type'] ===
'flex') {
220 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
221 ->getQueryBuilderForTable($tableName);
222 $queryBuilder->getRestrictions()->removeAll();
224 $fullRecord = $queryBuilder->select(
'*')
227 $queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
232 if ($fullRecord[$columnName]) {
234 $newXML = $flexObj->cleanFlexFormXML($tableName, $columnName, $fullRecord);
235 if (!hash_equals(md5($fullRecord[$columnName]), md5($newXML))) {
236 $dirtyFlexFormFields[$tableName .
':' . $uid .
':' . $columnName] = $fullRecord;
241 return $dirtyFlexFormFields;
253 $flexObj = GeneralUtility::makeInstance(FlexFormTools::class);
256 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
257 $dataHandler->dontProcessTransformations =
true;
258 $dataHandler->bypassWorkspaceRestrictions =
true;
259 $dataHandler->bypassFileHandling =
true;
261 $dataHandler->bypassAccessCheckForRecords =
true;
264 foreach ($records as $recordIdentifier => $fullRecord) {
265 list($table, $uid, $field) = explode(
':', $recordIdentifier);
266 if ($io->isVerbose()) {
267 $io->writeln(
'Cleaning FlexForm XML in "' . $recordIdentifier .
'"');
272 if ($fullRecord[$field]) {
273 $data[$table][$uid][$field] = $flexObj->cleanFlexFormXML($table, $field, $fullRecord);
275 $io->note(
'The field "' . $field .
'" in record "' . $table .
':' . $uid .
'" was not found.');
278 $dataHandler->start($data, []);
279 $dataHandler->process_datamap();
281 if (!empty($dataHandler->errorLog)) {
282 $errorMessage = array_merge([
'DataHandler reported an error'], $dataHandler->errorLog);
283 $io->error($errorMessage);
284 } elseif (!$io->isQuiet()) {
285 $io->writeln(
'Updated FlexForm in record "' . $table .
':' . $uid .
'".');