From 8f73a5523809fcfb0ef650387743e2a9d5993909 Mon Sep 17 00:00:00 2001 From: Henrik Elsner Date: Sat, 5 Aug 2023 13:39:21 +0200 Subject: [PATCH] fix: prevent double required config key in TCA Resolves: #3450 --- composer.json | 3 + .../v12/v0/tca/MigrateRequiredFlagRector.php | 5 +- .../Fixture/database_record_list_renaming.php | 9 --- .../Fixture/fixture.php.inc | 58 ++++++++++++++++++- 4 files changed, 63 insertions(+), 12 deletions(-) delete mode 100644 tests/Rector/v10/v0/DatabaseRecordListRector/Fixture/database_record_list_renaming.php diff --git a/composer.json b/composer.json index 8c224c7ef..b5ab26c90 100644 --- a/composer.json +++ b/composer.json @@ -107,5 +107,8 @@ "branch-alias": { "dev-main": "1.0-dev" } + }, + "conflict": { + "phpstan/phpstan": "1.10.28" } } diff --git a/src/Rector/v12/v0/tca/MigrateRequiredFlagRector.php b/src/Rector/v12/v0/tca/MigrateRequiredFlagRector.php index dcbb8ba93..f4fd7e490 100644 --- a/src/Rector/v12/v0/tca/MigrateRequiredFlagRector.php +++ b/src/Rector/v12/v0/tca/MigrateRequiredFlagRector.php @@ -95,10 +95,11 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void $this->removeNode($evalArrayItem); } - // If required config exists already, remove it to avoid duplicate array items + // If required config exists already do not add one again $requiredItemToRemove = $this->extractArrayItemByKey($configArray, self::REQUIRED); if ($requiredItemToRemove instanceof ArrayItem) { - $this->removeNode($requiredItemToRemove); + $this->hasAstBeenChanged = true; + return; } $configArray->items[] = new ArrayItem(new ConstFetch(new Name('true')), new String_(self::REQUIRED)); diff --git a/tests/Rector/v10/v0/DatabaseRecordListRector/Fixture/database_record_list_renaming.php b/tests/Rector/v10/v0/DatabaseRecordListRector/Fixture/database_record_list_renaming.php deleted file mode 100644 index 3bc80edff..000000000 --- a/tests/Rector/v10/v0/DatabaseRecordListRector/Fixture/database_record_list_renaming.php +++ /dev/null @@ -1,9 +0,0 @@ -thumbCode([], 'foo', 'bar'); - -$uri = $databaseRecordList->requestUri(); diff --git a/tests/Rector/v12/v0/tca/MigrateRequiredFlagRector/Fixture/fixture.php.inc b/tests/Rector/v12/v0/tca/MigrateRequiredFlagRector/Fixture/fixture.php.inc index d4ec6168a..dca78c57b 100644 --- a/tests/Rector/v12/v0/tca/MigrateRequiredFlagRector/Fixture/fixture.php.inc +++ b/tests/Rector/v12/v0/tca/MigrateRequiredFlagRector/Fixture/fixture.php.inc @@ -15,12 +15,39 @@ return [ 'eval' => 'required', ], ], + 'required_column2_copy' => [ + 'config' => [ + 'type' => 'foo', + 'eval' => 'required', + ], + ], 'already_required_column' => [ 'config' => [ 'eval' => 'required', 'required' => true, ], ], + 'contact_person_salutation' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang_db.xlf:tx_legacy_exntesion_domain_model_order.contact_person_salutation', + 'config' => [ + 'type' => 'select', + 'items' => [ + ['-', 0], + [ + 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.1.label', + 1, + ], + [ + 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.2.label', + 2, + ], + ], + 'size' => 1, + 'eval' => 'required', + 'maxitems' => 1, + ], + ], ], ]; @@ -43,8 +70,37 @@ return [ 'required' => true, ], ], + 'required_column2_copy' => [ + 'config' => [ + 'type' => 'foo', + 'required' => true, + ], + ], 'already_required_column' => [ - 'config' => ['required' => true], + 'config' => [ + 'required' => true, + ], + ], + 'contact_person_salutation' => [ + 'exclude' => 1, + 'label' => 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang_db.xlf:tx_legacy_exntesion_domain_model_order.contact_person_salutation', + 'config' => [ + 'type' => 'select', + 'items' => [ + ['-', 0], + [ + 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.1.label', + 1, + ], + [ + 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.2.label', + 2, + ], + ], + 'size' => 1, + 'maxitems' => 1, + 'required' => true, + ], ], ], ];