Skip to content

Commit

Permalink
[BUGFIX] Allow null returns when loading DB record
Browse files Browse the repository at this point in the history
The BackendLayoutView override class assumes that
records are possible to read from DB because it is
almost only used in the PageLayoutView which can only
show records that exist.

However, the class is also consulted for colPos value
lists when creating tt_content records as IRRE so it must
be allowed to silently ignore possibly missing parent
or child records for parents that have not been saved.

Close: #1598
  • Loading branch information
NamelessCoder committed Mar 3, 2019
1 parent d6fd227 commit 3509426
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Classes/Integration/Overrides/BackendLayoutView.php
Expand Up @@ -65,6 +65,9 @@ public function getSelectedBackendLayout($pageId)
{
if ($this->addingItemsForContent) {
$pageRecord = $this->loadRecordFromTable('pages', (int)$pageId);
if (!$pageRecord) {
return null;
}
$pageLevelProvider = $this->resolvePrimaryProviderForRecord('pages', $pageRecord);
if ($pageLevelProvider instanceof GridProviderInterface) {
return $pageLevelProvider->getGrid($pageRecord)->buildExtendedBackendLayoutArray(0);
Expand Down Expand Up @@ -123,6 +126,9 @@ protected function addColPosListLayoutItems($pageId, $items)
$parentRecordUid = ColumnNumberUtility::calculateParentUid($this->record['colPos']);
if ($parentRecordUid > 0) {
$parentRecord = $this->loadRecordFromTable('tt_content', $parentRecordUid);
if (!$parentRecord) {
return $items;
}
$provider = $this->resolvePrimaryProviderForRecord('tt_content', $parentRecord);
if ($provider) {
$items = array_merge(
Expand All @@ -143,14 +149,19 @@ protected function addColPosListLayoutItems($pageId, $items)
return $items;
}

protected function loadRecordFromTable(string $table, int $uid): array
/**
* @param string $table
* @param int $uid
* @return array|null
*/
protected function loadRecordFromTable(string $table, int $uid)
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$query = $queryBuilder->select('*')
->from($table)
->where($queryBuilder->expr()->eq('uid', $uid));
$query->getRestrictions()->removeAll();
return $query->execute()->fetchAll()[0];
return $query->execute()->fetchAll()[0] ?? null;
}

protected function resolvePrimaryProviderForRecord(string $table, array $record)
Expand Down

0 comments on commit 3509426

Please sign in to comment.