Skip to content

Commit

Permalink
[BUGFIX] Avoid SQL errors in PageRepository->versionOL
Browse files Browse the repository at this point in the history
This change adds an additional guard clause check
to avoid SQL errors when an invalid row is entered.

Resolves: #98189
Releases: main, 12.4, 11.5
Change-Id: Iecb12b9c6ef97fb603c8b720d5e2be7433543637
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79739
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
bmack committed Jul 5, 2023
1 parent 2803da6 commit af71af9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Expand Up @@ -1678,14 +1678,14 @@ public function fixVersioningPid($table, &$rr)
*/
public function versionOL($table, &$row, $unsetMovePointers = false, $bypassEnableFieldsCheck = false)
{
if ($this->versioningWorkspaceId > 0 && is_array($row)) {
if ($this->versioningWorkspaceId > 0 && is_array($row) && $row !== [] && isset($row['uid'], $row['t3ver_oid'])) {
// implode(',',array_keys($row)) = Using fields from original record to make
// sure no additional fields are selected. This is best for eg. getPageOverlay()
// Computed properties are excluded since those would lead to SQL errors.
$fieldNames = implode(',', array_keys($this->purgeComputedProperties($row)));
// will overlay any incoming moved record with the live record, which in turn
// will be overlaid with its workspace version again to fetch both PID fields.
$incomingRecordIsAMoveVersion = (int)($row['t3ver_oid'] ?? 0) > 0 && (int)($row['t3ver_state'] ?? 0) === VersionState::MOVE_POINTER;
$incomingRecordIsAMoveVersion = (int)($row['t3ver_oid']) > 0 && (int)($row['t3ver_state'] ?? 0) === VersionState::MOVE_POINTER;
if ($incomingRecordIsAMoveVersion) {
// Fetch the live version again if the given $row is a move pointer, so we know the original PID
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
Expand Down
Expand Up @@ -635,4 +635,34 @@ public function getLanguageOverlayResolvesContentWithNullInValues(): void
self::assertSame('Translated #2', $overlaidRecord['header']);
self::assertNull($overlaidRecord['bodytext']);
}

/**
* @return array<string, array{0: array<string, int>}>
*/
public static function invalidRowForVersionOLDataProvider(): array
{
return [
'no uid and no t3ver_oid' => [[]],
'zero uid and no t3ver_oid' => [['uid' => 0]],
'positive uid and no t3ver_oid' => [['uid' => 1]],
'no uid but t3ver_oid' => [['t3ver_oid' => 1]],
];
}

/**
* @test
* @param array<string, int> $input
* @dataProvider invalidRowForVersionOLDataProvider
*/
public function versionOLForAnInvalidRowUnchangedRowData(array $input): void
{
$context = new Context();
$context->setAspect('workspace', new WorkspaceAspect(4));
$subject = new PageRepository($context);
$originalInput = $input;

$subject->versionOL('pages', $input);

self::assertSame($originalInput, $input);
}
}
Expand Up @@ -160,6 +160,7 @@ public function overlayLanguageAndWorkspaceChangesUidIfInPreview(): void
$row = [
'uid' => '42',
'pid' => '42',
't3ver_oid' => '42',
];
$workspaceVersion = [
'uid' => '43',
Expand Down

0 comments on commit af71af9

Please sign in to comment.