Skip to content

Commit

Permalink
[BUGFIX] Avoid using SimpleTcaSchemaFactory in RelationResolver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nhovratov committed Apr 26, 2024
1 parent b84d79f commit 9fd03ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
4 changes: 1 addition & 3 deletions Classes/DataProcessing/RelationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {}
Expand Down Expand Up @@ -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);
Expand Down
66 changes: 33 additions & 33 deletions Tests/Functional/DataProcessing/RelationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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);
Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand Down Expand Up @@ -862,7 +862,7 @@ public function canResolveFlexForm(): void
</T3FlexForms>',
];

$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');

Expand Down Expand Up @@ -909,7 +909,7 @@ public function canResolveFlexFormWithSheetsOtherThanDefault(): void
</T3FlexForms>',
];

$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');

Expand All @@ -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');

Expand Down

0 comments on commit 9fd03ef

Please sign in to comment.