diff --git a/config/v12/tca-120.php b/config/v12/tca-120.php index 5da470826..af59e68b2 100644 --- a/config/v12/tca-120.php +++ b/config/v12/tca-120.php @@ -18,4 +18,5 @@ $rectorConfig->rule(MigrateRequiredFlagRector::class); $rectorConfig->rule(RemoveTCAInterfaceAlwaysDescriptionRector::class); $rectorConfig->rule(RemoveCruserIdRector::class); + $rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\tca\RemoveTableLocalPropertyRector::class); }; diff --git a/src/Rector/v12/v0/tca/RemoveTableLocalPropertyRector.php b/src/Rector/v12/v0/tca/RemoveTableLocalPropertyRector.php new file mode 100644 index 000000000..6545f85f1 --- /dev/null +++ b/src/Rector/v12/v0/tca/RemoveTableLocalPropertyRector.php @@ -0,0 +1,86 @@ +key) { + return null; + } + + if (! $this->valueResolver->isValue($node->key, 'foreign_match_fields')) { + return null; + } + + if (! $node->value instanceof Array_) { + return null; + } + + foreach ($node->value->items as $item) { + if (null === $item) { + continue; + } + + if (null === $item->key) { + continue; + } + + if ($this->valueResolver->isValue($item->key, 'table_local')) { + $this->removeNode($item); + } + } + + return null; + } + + /** + * @codeCoverageIgnore + */ + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Remove TCA property table_local in foreign_match_fields', [new CodeSample( + <<<'CODE_SAMPLE' +'foreign_match_fields' => [ + 'fieldname' => 'media', + 'tablenames' => 'tx_site_domain_model_mediacollection', + 'table_local' => 'sys_file', +], +'maxitems' => 1, +'minitems' => 1, +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +'foreign_match_fields' => [ + 'fieldname' => 'media', + 'tablenames' => 'tx_site_domain_model_mediacollection', +], +'maxitems' => 1, +'minitems' => 1, +CODE_SAMPLE + )]); + } +} diff --git a/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/Fixture/fixture.php.inc b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/Fixture/fixture.php.inc new file mode 100644 index 000000000..73bb433da --- /dev/null +++ b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/Fixture/fixture.php.inc @@ -0,0 +1,120 @@ + [], + 'columns' => [ + 'images' => [ + 'exclude' => 1, + 'label' => 'Bilder', + 'config' => ExtensionManagementUtility::getFileFieldTCAConfig( + 'images', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', + 'showPossibleLocalizationRecords' => true, + 'showRemovedLocalizationRecords' => true, + 'showAllLocalizationLink' => true, + 'showSynchronizationLink' => true, + ], + 'foreign_match_fields' => [ + 'fieldname' => 'images', + 'tablenames' => 'tx_aknwevents_domain_model_event', + 'table_local' => 'sys_file', + ], + 'minitems' => 0, + 'maxitems' => 999, + ], + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), + ], + 'images2' => [ + 'exclude' => 1, + 'label' => 'Bilder', + 'config' => ExtensionManagementUtility::getFileFieldTCAConfig( + 'images', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', + 'showPossibleLocalizationRecords' => true, + 'showRemovedLocalizationRecords' => true, + 'showAllLocalizationLink' => true, + 'showSynchronizationLink' => true, + ], + 'foreign_match_fields' => [ + 'fieldname' => 'images', + 'tablenames' => 'tx_aknwevents_domain_model_event', + ], + 'minitems' => 0, + 'maxitems' => 999, + ], + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), + ], + ], +]; + +?> +----- + [], + 'columns' => [ + 'images' => [ + 'exclude' => 1, + 'label' => 'Bilder', + 'config' => ExtensionManagementUtility::getFileFieldTCAConfig( + 'images', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', + 'showPossibleLocalizationRecords' => true, + 'showRemovedLocalizationRecords' => true, + 'showAllLocalizationLink' => true, + 'showSynchronizationLink' => true, + ], + 'foreign_match_fields' => [ + 'fieldname' => 'images', + 'tablenames' => 'tx_aknwevents_domain_model_event', + ], + 'minitems' => 0, + 'maxitems' => 999, + ], + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), + ], + 'images2' => [ + 'exclude' => 1, + 'label' => 'Bilder', + 'config' => ExtensionManagementUtility::getFileFieldTCAConfig( + 'images', + [ + 'appearance' => [ + 'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference', + 'showPossibleLocalizationRecords' => true, + 'showRemovedLocalizationRecords' => true, + 'showAllLocalizationLink' => true, + 'showSynchronizationLink' => true, + ], + 'foreign_match_fields' => [ + 'fieldname' => 'images', + 'tablenames' => 'tx_aknwevents_domain_model_event', + ], + 'minitems' => 0, + 'maxitems' => 999, + ], + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), + ], + ], +]; + +?> diff --git a/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/RemoveTableLocalPropertyRectorTest.php b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/RemoveTableLocalPropertyRectorTest.php new file mode 100644 index 000000000..016fe2597 --- /dev/null +++ b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/RemoveTableLocalPropertyRectorTest.php @@ -0,0 +1,32 @@ +doTestFile($filePath); + } + + /** + * @return Iterator> + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/config/configured_rule.php b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/config/configured_rule.php new file mode 100644 index 000000000..ea7770fbf --- /dev/null +++ b/tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/config/configured_rule.php @@ -0,0 +1,11 @@ +import(__DIR__ . '/../../../../../../../config/config_test.php'); + $rectorConfig->rule(RemoveTableLocalPropertyRector::class); +};