diff --git a/Classes/Command/DeleteChildrenWithUnusedColPosCommand.php b/Classes/Command/DeleteChildrenWithUnusedColPosCommand.php new file mode 100644 index 00000000..44aa6c82 --- /dev/null +++ b/Classes/Command/DeleteChildrenWithUnusedColPosCommand.php @@ -0,0 +1,56 @@ +integrity = $integrity; + $this->integrityFix = $integrityFix; + parent::__construct($name); + } + + public function execute(InputInterface $input, OutputInterface $output): int + { + Bootstrap::initializeBackendAuthentication(); + $GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']); + $res = $this->integrity->run(); + foreach ($res['warnings'] as $warning) { + if ($warning instanceof UnusedColPosWarning) { + $this->integrityFix->deleteChildrenWithUnusedColPos($warning); + } + } + return 0; + } +} diff --git a/Classes/Integrity/Error/UnusedColPosWarning.php b/Classes/Integrity/Error/UnusedColPosWarning.php index 04e23519..f61b3931 100644 --- a/Classes/Integrity/Error/UnusedColPosWarning.php +++ b/Classes/Integrity/Error/UnusedColPosWarning.php @@ -46,6 +46,14 @@ public function __construct(array $childRecord, array $containerRecord) . ' with CType ' . $containerRecord['CType']; } + /** + * @return array + */ + public function getChildRecord(): array + { + return $this->childRecord; + } + /** * @return string */ diff --git a/Classes/Integrity/IntegrityFix.php b/Classes/Integrity/IntegrityFix.php index e9c51916..1b94964d 100644 --- a/Classes/Integrity/IntegrityFix.php +++ b/Classes/Integrity/IntegrityFix.php @@ -14,6 +14,7 @@ use B13\Container\Integrity\Error\ChildInTranslatedContainerError; use B13\Container\Integrity\Error\NonExistingParentWarning; +use B13\Container\Integrity\Error\UnusedColPosWarning; use B13\Container\Integrity\Error\WrongL18nParentError; use B13\Container\Integrity\Error\WrongPidError; use B13\Container\Tca\Registry; @@ -60,6 +61,16 @@ public function deleteChildrenWithNonExistingParent(NonExistingParentWarning $no $dataHandler->process_cmdmap(); } + public function deleteChildrenWithUnusedColPos(UnusedColPosWarning $unusedColPosWarning): void + { + $dataHandler = GeneralUtility::makeInstance(DataHandler::class); + $dataHandler->enableLogging = false; + $childRecord = $unusedColPosWarning->getChildRecord(); + $cmd = ['tt_content' => [$childRecord['uid'] => ['delete' => 1]]]; + $dataHandler->start([], $cmd); + $dataHandler->process_cmdmap(); + } + public function changeContainerParentToDefaultLanguageContainer(ChildInTranslatedContainerError $e): void { $translatedContainer = $e->getContainerRecord(); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index d3324614..14003c59 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -102,6 +102,12 @@ services: command: 'container:deleteChildrenWithNonExistingParent' schedulable: false description: delete all child records with a non existing parent record (they are displayed as unsued) + B13\Container\Command\DeleteChildrenWithUnusedColPosCommand: + tags: + - name: 'console.command' + command: 'container:deleteChildrenWithUnusedColPos' + schedulable: false + description: delete all child records with a colPos that is not available for the parent CType (they are displayed as unsued) B13\Container\Command\IntegrityCommand: tags: - name: 'console.command' diff --git a/README.md b/README.md index 67d2436a..13d9117c 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ bin/typo3 container:fixLanguageMode bin/typo3 container:fixContainerParentForConnectedMode bin/typo3 container:deleteChildrenWithWrongPid bin/typo3 container:deleteChildrenWithNonExistingParent +bin/typo3 container:deleteChildrenWithUnusedColPos ``` ## TODOs