From 9fd03efde3a6469b832c94f15f06612b45ae0b7e Mon Sep 17 00:00:00 2001 From: Nikita Hovratov Date: Fri, 26 Apr 2024 19:01:26 +0200 Subject: [PATCH] [BUGFIX] Avoid using SimpleTcaSchemaFactory in RelationResolver SimpleTcaSchemaFactory should only hold "base" TCA without overrides. This does not suit for RelationResolver, which expects full TCA. Remove this usage and replace with plain global TCA access. Note: This did only work "by accident" as in fully cached scenarios SimpleTcaSchema was initialised with full TCA bypassing the early call in TCA overrides content-blocks.php. Fixes: #185 --- Classes/DataProcessing/RelationResolver.php | 4 +- .../DataProcessing/RelationResolverTest.php | 66 +++++++++---------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/Classes/DataProcessing/RelationResolver.php b/Classes/DataProcessing/RelationResolver.php index 6fce5136..1007c0d7 100644 --- a/Classes/DataProcessing/RelationResolver.php +++ b/Classes/DataProcessing/RelationResolver.php @@ -25,7 +25,6 @@ use TYPO3\CMS\ContentBlocks\Definition\TcaFieldDefinition; use TYPO3\CMS\ContentBlocks\FieldType\FieldType; use TYPO3\CMS\ContentBlocks\FieldType\FolderFieldType; -use TYPO3\CMS\ContentBlocks\Schema\SimpleTcaSchemaFactory; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\RelationHandler; use TYPO3\CMS\Core\Domain\Repository\PageRepository; @@ -43,7 +42,6 @@ class RelationResolver public function __construct( protected readonly TableDefinitionCollection $tableDefinitionCollection, - protected readonly SimpleTcaSchemaFactory $simpleTcaSchemaFactory, protected readonly FlexFormService $flexFormService, protected readonly RelationResolverSession $relationResolverSession, ) {} @@ -307,7 +305,7 @@ protected function getRelations( $relationHandler = GeneralUtility::makeInstance(RelationHandler::class); $relationHandler->start($uidList, $tableList, $mmTable, $uid, $currentTable, $tcaFieldConf); foreach (array_keys($relationHandler->tableArray) as $table) { - if ($this->simpleTcaSchemaFactory->has($table)) { + if (isset($GLOBALS['TCA'][$table])) { $autoHiddenSelection = -1; $ignoreWorkspaceFilter = ['pid' => true]; $additionalWhere = $pageRepository->enableFields($table, $autoHiddenSelection, $ignoreWorkspaceFilter); diff --git a/Tests/Functional/DataProcessing/RelationResolverTest.php b/Tests/Functional/DataProcessing/RelationResolverTest.php index caecdbdf..a663701d 100644 --- a/Tests/Functional/DataProcessing/RelationResolverTest.php +++ b/Tests/Functional/DataProcessing/RelationResolverTest.php @@ -70,7 +70,7 @@ public function canResolveFileReferences(): void 'image' => 1, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -95,7 +95,7 @@ public function canResolveFilesFromFolder(): void 'typo3tests_contentelementb_folder' => '1:/', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -120,7 +120,7 @@ public function canResolveFilesFromFolderRecursive(): void 'typo3tests_contentelementb_folder_recursive' => '1:/', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -146,7 +146,7 @@ public function canResolveCollections(): void 'typo3tests_contentelementb_collection' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -172,7 +172,7 @@ public function canResolveCollectionsWithAlternativeTableName(): void 'typo3tests_contentelementb_collection2' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -198,7 +198,7 @@ public function canResolveCollectionsExternal(): void 'typo3tests_contentelementb_collection_external' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -224,7 +224,7 @@ public function canResolveCollectionsRecursively(): void 'typo3tests_contentelementb_collection_recursive' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -258,7 +258,7 @@ public function canResolveCollectionsInWorkspaces(): void '_ORIG_uid' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -284,7 +284,7 @@ public function canResolveCategoriesManyToMany(): void 'typo3tests_contentelementb_categories_mm' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -315,7 +315,7 @@ public function canResolveCategoriesManyToManyInWorkspaces(): void 'typo3tests_contentelementb_categories_mm' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -352,7 +352,7 @@ public function canResolveCategoriesManyToManyLocalized(): void '_LOCALIZED_UID' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -377,7 +377,7 @@ public function canResolveCategoriesOneToOne(): void 'typo3tests_contentelementb_categories_11' => 7, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -402,7 +402,7 @@ public function canResolveCategoriesOneToMany(): void 'typo3tests_contentelementb_categories_1m' => '7,8', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -428,7 +428,7 @@ public function canResolveDbRelation(): void 'typo3tests_contentelementb_pages_relation' => '1,2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -454,7 +454,7 @@ public function canResolveCircularRelation(): void 'typo3tests_contentelementb_circular_relation' => '1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); self::assertCount(1, $result); @@ -478,7 +478,7 @@ public function canResolveDbRelationRecursive(): void 'typo3tests_contentelementb_record_relation_recursive' => '1,2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -512,7 +512,7 @@ public function canResolveDbRelationsInWorkspaces(): void 'typo3tests_contentelementb_pages_relation' => '1,2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -538,7 +538,7 @@ public function canResolveMultipleDbRelations(): void 'typo3tests_contentelementb_pages_content_relation' => 'pages_1,pages_2,tt_content_1,tt_content_2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -566,7 +566,7 @@ public function canResolveDbRelationsMM(): void 'typo3tests_contentelementb_pages_mm' => 2, ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -590,7 +590,7 @@ public function selectCheckboxCommaListConvertedToArray(): void 'typo3tests_contentelementb_select_checkbox' => '1,2,3', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -612,7 +612,7 @@ public function selectSingleBoxCommaListConvertedToArray(): void 'typo3tests_contentelementb_select_single_box' => '1,2,3', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -634,7 +634,7 @@ public function selectMultipleSideBySideCommaListConvertedToArray(): void 'typo3tests_contentelementb_select_multiple' => '1,2,3', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -656,7 +656,7 @@ public function selectMultipleSideBySideWithOneValueConvertedToArray(): void 'typo3tests_contentelementb_select_multiple' => '1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -678,7 +678,7 @@ public function selectMultipleSideBySideWithEmptyOneValueConvertedToArray(): voi 'typo3tests_contentelementb_select_multiple' => '', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -701,7 +701,7 @@ public function canResolveSelectForeignTableSingle(): void 'typo3tests_contentelementb_select_foreign' => '1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -724,7 +724,7 @@ public function canResolveSelectForeignTableMultiple(): void 'typo3tests_contentelementb_select_foreign_multiple' => '1,2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -749,7 +749,7 @@ public function canResolveSelectForeignTableMultipleAndSame(): void 'typo3tests_contentelementb_select_foreign_multiple' => '1,1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -776,7 +776,7 @@ public function canResolveSelectForeignNativeTableSingle(): void 'typo3tests_contentelementb_select_foreign_native' => '1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -799,7 +799,7 @@ public function canResolveSelectForeignNativeTableMultiple(): void 'typo3tests_contentelementb_select_foreign_native_multiple' => '1,2', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -824,7 +824,7 @@ public function canResolveSelectForeignTableRecursive(): void 'typo3tests_contentelementb_select_foreign' => '1', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -862,7 +862,7 @@ public function canResolveFlexForm(): void ', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -909,7 +909,7 @@ public function canResolveFlexFormWithSheetsOtherThanDefault(): void ', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content'); @@ -934,7 +934,7 @@ public function canResolveJson(): void 'typo3tests_contentelementb_json' => '{"foo": "bar"}', ]; - $relationResolver = new RelationResolver($tableDefinitionCollection, $simpleTcaSchemaFactory, new FlexFormService(), new RelationResolverSession()); + $relationResolver = new RelationResolver($tableDefinitionCollection, new FlexFormService(), new RelationResolverSession()); $result = $relationResolver->processField($fieldDefinition, $elementDefinition, $dummyRecord, 'tt_content');