Commit 6000af36 authored by Georg Ringer's avatar Georg Ringer
Browse files

[BUGFIX] Check if vanillaUid is actually a real number

Avoid exceptions when creating inline relations if the
parent record is not yet persisted.

Resolves: #96900
Releases: main, 11.5
Change-Id: I383fd37efa8bec09333ee61156be1add99fd6e56
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73519

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent eb274401
......@@ -16,6 +16,7 @@
namespace TYPO3\CMS\Backend\Form\FormDataProvider;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* Fetch parent page row from database if possible
......@@ -34,28 +35,29 @@ class DatabaseParentPageRow extends AbstractDatabaseRecordProvider implements Fo
// $parentPageRow end up NULL if a record added or edited on root node
$parentPageRow = null;
if ($result['command'] === 'new') {
if ($result['vanillaUid'] < 0) {
// vanillaUid points to a neighbor record in same table - get its record and its pid from there to find parent record
$neighborRow = $this->getRecordFromDatabase($result['tableName'], (int)abs($result['vanillaUid']));
if (!empty($neighborRow['t3ver_oid'])) {
$neighborRow = $this->getRecordFromDatabase($result['tableName'], (int)$neighborRow['t3ver_oid']);
if (MathUtility::canBeInterpretedAsInteger($result['vanillaUid'])) {
$vanillaUid = (int)$result['vanillaUid'];
if ($vanillaUid < 0) {
// vanillaUid points to a neighbor record in same table - get its record and its pid from there to find parent record
$neighborRow = $this->getRecordFromDatabase($result['tableName'], (int)abs($vanillaUid));
if (!empty($neighborRow['t3ver_oid'])) {
$neighborRow = $this->getRecordFromDatabase($result['tableName'], (int)$neighborRow['t3ver_oid']);
}
$result['neighborRow'] = $neighborRow;
// uid of page the record is located in
$neighborRowPid = (int)$neighborRow['pid'];
if ($neighborRowPid !== 0) {
// Fetch the parent page record only if it is not the '0' root
$parentPageRow = $this->getRecordFromDatabase('pages', $neighborRowPid);
}
} elseif ($vanillaUid > 0) {
// vanillaUid points to a page uid directly
$parentPageRow = $this->getRecordFromDatabase('pages', $vanillaUid);
}
$result['neighborRow'] = $neighborRow;
// uid of page the record is located in
$neighborRowPid = (int)$neighborRow['pid'];
if ($neighborRowPid !== 0) {
// Fetch the parent page record only if it is not the '0' root
$parentPageRow = $this->getRecordFromDatabase('pages', $neighborRowPid);
}
} elseif ($result['vanillaUid'] > 0) {
// vanillaUid points to a page uid directly
$parentPageRow = $this->getRecordFromDatabase('pages', $result['vanillaUid']);
}
} else {
} elseif ($result['databaseRow']['pid'] > 0) {
// On "edit", the row itself has been fetched already
if ($result['databaseRow']['pid'] > 0) {
$parentPageRow = $this->getRecordFromDatabase('pages', $result['databaseRow']['pid']);
}
$parentPageRow = $this->getRecordFromDatabase('pages', (int)$result['databaseRow']['pid']);
}
$result['parentPageRow'] = $parentPageRow;
......
......@@ -164,4 +164,42 @@ class DatabaseParentPageRowTest extends UnitTestCase
self::assertSame($parentPageRow, $result['parentPageRow']);
}
/**
* @test
*/
public function addDataSetsParentPageRowOnNullWithNew(): void
{
$input = [
'tableName' => 'tt_content',
'command' => 'new',
'vanillaUid' => 'NEW123',
'databaseRow' => [],
];
$this->subject->expects(self::never())->method('getDatabaseRow');
$result = $this->subject->addData($input);
self::assertNull($result['parentPageRow']);
}
/**
* @test
*/
public function addDataSetsParentPageRowOnNullWithZero(): void
{
$input = [
'tableName' => 'tt_content',
'command' => 'new',
'vanillaUid' => 0,
'databaseRow' => [],
];
$this->subject->expects(self::never())->method('getDatabaseRow');
$result = $this->subject->addData($input);
self::assertNull($result['parentPageRow']);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment