Skip to content

Commit

Permalink
[BUGFIX] Include pid in field list of BU::getCommonSelectFields
Browse files Browse the repository at this point in the history
Add the pid to the list of fields which should always be
retrieved when selecting a record. This especially avoid
a PHP warning in FormEngine when workspace records are
overlaid.

Resolves: #98181
Releases: main, 12.4, 11.5
Change-Id: Iaf5479e329693486c992495228fca1b711ba6161
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80043
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
georgringer authored and lolli42 committed Jul 17, 2023
1 parent 2e24b66 commit b083868
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 4 additions & 0 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -1873,10 +1873,14 @@ public static function getProcessedValueExtra(
* @param array $fields Preset fields (must include prefix if that is used)
* @return string List of fields.
* @internal should only be used from within TYPO3 Core
* @todo: Consider dropping this method: It is used only twice and may select not actually needed fields.
* Also, the CSV string return is unfortunate. Consuming callers know better what they actually need,
* this method should be inlined to consumers instead.
*/
public static function getCommonSelectFields($table, $prefix = '', $fields = [])
{
$fields[] = $prefix . 'uid';
$fields[] = $prefix . 'pid';
if (isset($GLOBALS['TCA'][$table]['ctrl']['label']) && $GLOBALS['TCA'][$table]['ctrl']['label'] != '') {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['label'];
}
Expand Down
Expand Up @@ -132,7 +132,7 @@ protected function mockDatabaseConnectionForProcessSelectField(): void
$statementProphet = $this->prophesize(Result::class);
$statementProphet->fetchAllAssociative()->shouldBeCalled();

$queryBuilderProphet->select('foreignTable.uid')
$queryBuilderProphet->select('foreignTable.uid', 'foreignTable.pid')
->shouldBeCalled()
->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('foreignTable')
Expand Down Expand Up @@ -1008,7 +1008,7 @@ public function addDataReplacesMarkersInForeignTableClause(string $foreignTableW
$statementProphet = $this->prophesize(Result::class);
$statementProphet->fetchAllAssociative()->shouldBeCalled()->willReturn([]);

$queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->select('fTable.uid', 'fTable.pid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->where(...array_shift($expectedWhere))->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down Expand Up @@ -1103,7 +1103,7 @@ public function addDataForeignTableSplitsGroupOrderAndLimit(): void
$statementProphet = $this->prophesize(Result::class);
$statementProphet->fetchAllAssociative()->shouldBeCalled()->willReturn([]);

$queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->select('fTable.uid', 'fTable.pid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->groupBy('groupField1', 'groupField2')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public function addDataForeignTableQueuesFlashMessageOnDatabaseError(): void

[$queryBuilderProphet, $connectionPoolProphet] = $this->mockDatabaseConnection();

$queryBuilderProphet->select('fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->select('fTable.uid', 'fTable.pid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->where('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down Expand Up @@ -1206,7 +1206,7 @@ private function mockForeignTableItemsQuery(): array

$statementProphet = $this->prophesize(Result::class);

$queryBuilderProphet->select('fTable.uid', 'fTable.labelField')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->select('fTable.uid', 'fTable.pid', 'fTable.labelField')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->where('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down Expand Up @@ -1365,7 +1365,7 @@ public function addDataRemovesItemsThatAreRestrictedByUserStorageAddedByForeignT

$statementProphet = $this->prophesize(Result::class);

$queryBuilderProphet->select('sys_file_storage.uid', 'sys_file_storage.labelField')
$queryBuilderProphet->select('sys_file_storage.uid', 'sys_file_storage.pid', 'sys_file_storage.labelField')
->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('sys_file_storage')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down Expand Up @@ -1463,7 +1463,7 @@ public function addDataForeignTableResolvesIconFromSelicon(): void

$statementProphet = $this->prophesize(Result::class);

$queryBuilderProphet->select('fTable.uid', 'fTable.icon')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->select('fTable.uid', 'fTable.pid', 'fTable.icon')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->where('')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
Expand Down
Expand Up @@ -89,7 +89,7 @@ protected function mockDatabaseConnection(): void
->shouldBeCalled()
->willReturn($queryBuilderProphet->reveal());

$queryBuilderProphet->select('foreignTable.uid')
$queryBuilderProphet->select('foreignTable.uid', 'foreignTable.pid')
->shouldBeCalled()
->willReturn($queryBuilderProphet->reveal());
$queryBuilderProphet->from('foreignTable')
Expand Down
18 changes: 9 additions & 9 deletions typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
Expand Up @@ -609,12 +609,12 @@ public function getProcessedValueForCheckWithSingleItemInvertStateDisplay(): voi
public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
{
return [
'only uid' => [
'minimum fields' => [
'table' => 'test_table',
'prefix' => '',
'presetFields' => [],
'tca' => [],
'expectedFields' => 'uid',
'expectedFields' => 'uid,pid',
],
'label set' => [
'table' => 'test_table',
Expand All @@ -625,7 +625,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'label' => 'label',
],
],
'expectedFields' => 'uid,label',
'expectedFields' => 'uid,pid,label',
],
'label_alt set' => [
'table' => 'test_table',
Expand All @@ -636,7 +636,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'label_alt' => 'label,label2',
],
],
'expectedFields' => 'uid,label,label2',
'expectedFields' => 'uid,pid,label,label2',
],
'versioningWS set' => [
'table' => 'test_table',
Expand All @@ -647,7 +647,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'versioningWS' => true,
],
],
'expectedFields' => 'uid,t3ver_state,t3ver_wsid',
'expectedFields' => 'uid,pid,t3ver_state,t3ver_wsid',
],
'selicon_field set' => [
'table' => 'test_table',
Expand All @@ -658,7 +658,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'selicon_field' => 'field',
],
],
'expectedFields' => 'uid,field',
'expectedFields' => 'uid,pid,field',
],
'typeicon_column set' => [
'table' => 'test_table',
Expand All @@ -669,7 +669,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'typeicon_column' => 'field',
],
],
'expectedFields' => 'uid,field',
'expectedFields' => 'uid,pid,field',
],
'enablecolumns set' => [
'table' => 'test_table',
Expand All @@ -685,7 +685,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
],
],
],
'expectedFields' => 'uid,hidden,start,stop,groups',
'expectedFields' => 'uid,pid,hidden,start,stop,groups',
],
'label set to uid' => [
'table' => 'test_table',
Expand All @@ -696,7 +696,7 @@ public function getCommonSelectFieldsReturnsCorrectFieldsDataProvider(): array
'label' => 'uid',
],
],
'expectedFields' => 'uid',
'expectedFields' => 'uid,pid',
],
];
}
Expand Down

0 comments on commit b083868

Please sign in to comment.