From af71af97f251d3d019beaf74616a6c6cb95ad58b Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Wed, 5 Jul 2023 13:10:41 +0200 Subject: [PATCH] [BUGFIX] Avoid SQL errors in PageRepository->versionOL 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 Reviewed-by: Benni Mack Tested-by: Benni Mack --- .../Domain/Repository/PageRepository.php | 4 +-- .../Domain/Repository/PageRepositoryTest.php | 30 +++++++++++++++++++ .../Generic/Storage/Typo3DbBackendTest.php | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php b/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php index 1fee0510767d..8baf61db58c7 100644 --- a/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php +++ b/typo3/sysext/core/Classes/Domain/Repository/PageRepository.php @@ -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); diff --git a/typo3/sysext/core/Tests/Functional/Domain/Repository/PageRepositoryTest.php b/typo3/sysext/core/Tests/Functional/Domain/Repository/PageRepositoryTest.php index 240d219e740e..d1b617694921 100644 --- a/typo3/sysext/core/Tests/Functional/Domain/Repository/PageRepositoryTest.php +++ b/typo3/sysext/core/Tests/Functional/Domain/Repository/PageRepositoryTest.php @@ -635,4 +635,34 @@ public function getLanguageOverlayResolvesContentWithNullInValues(): void self::assertSame('Translated #2', $overlaidRecord['header']); self::assertNull($overlaidRecord['bodytext']); } + + /** + * @return array}> + */ + 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 $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); + } } diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php index 095fc0790c77..57dd4e323c1c 100644 --- a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php @@ -160,6 +160,7 @@ public function overlayLanguageAndWorkspaceChangesUidIfInPreview(): void $row = [ 'uid' => '42', 'pid' => '42', + 't3ver_oid' => '42', ]; $workspaceVersion = [ 'uid' => '43',