Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Oct 1, 2021
1 parent f2a22f6 commit 2dccd76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 12 additions & 10 deletions core-bundle/src/Resources/contao/drivers/DC_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -3580,16 +3580,16 @@ protected function treeView()
}
}

$topMostRootIds = $this->root;

if (!empty($this->visibleRootTrails))
{
// Make sure we use the topmost root IDs only from all the visible root trail ids and also ensure correct sorting
$topMostRootIds = array_map('\intval', $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=0 AND id IN (" . implode(',', $this->visibleRootTrails) . ")" . ($this->Database->fieldExists('sorting', $table) ? 'ORDER BY sorting' : ''))
->execute()
->fetchEach('id'));
}
else
{
$topMostRootIds = $this->root;
$topMostRootIds = $this->Database->prepare("SELECT id FROM $table WHERE pid=0 AND id IN (" . implode(',', $this->visibleRootTrails) . ")" . ($this->Database->fieldExists('sorting', $table) ? 'ORDER BY sorting' : ''))
->execute()
->fetchEach('id');

$topMostRootIds = array_map('\intval', $topMostRootIds);
}

// Call a recursive function that builds the tree
Expand Down Expand Up @@ -6195,7 +6195,10 @@ protected function formatGroupHeader($field, $value, $mode, $row)
return $group;
}

protected function initRoots(): void
/**
* Initialize the root pages
*/
protected function initRoots()
{
$table = $this->strTable;

Expand All @@ -6207,8 +6210,7 @@ protected function initRoots(): void
// Unless there are any root records specified, use all records with parent ID 0
if (!isset($GLOBALS['TL_DCA'][$table]['list']['sorting']['root']) || $GLOBALS['TL_DCA'][$table]['list']['sorting']['root'] === false)
{
$objIds = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?")
->execute(0);
$objIds = $this->Database->execute("SELECT id FROM $table WHERE pid=0");

if ($objIds->numRows > 0)
{
Expand Down
5 changes: 2 additions & 3 deletions core-bundle/src/Resources/contao/library/Contao/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public function getChildRecords($arrParentIds, $strTable, $blnSorting=false, $ar
*
* @param integer $intId The ID of the record
* @param string $strTable The table name
* @param bool $skipId This method will include the provided ID in the result set. Pass true to omit it.
* @param bool $skipId Omit the provided ID in the result set
*
* @return array An array of parent record IDs
*/
Expand All @@ -571,8 +571,7 @@ public function getParentRecords($intId, $strTable, bool $skipId = false)
$objPages = $this->prepare("SELECT id, @pid:=pid FROM $strTable WHERE id=?" . str_repeat(" UNION SELECT id, @pid:=pid FROM $strTable WHERE id=@pid", 9))
->execute($intId);

$ids = $objPages->fetchEach('id');
$ids = array_map('\intval', $ids);
$ids = array_map('\intval', $objPages->fetchEach('id'));

// Trigger recursion in case our query returned exactly 10 IDs in which case we might have higher parent records
if (\count($ids) === 10)
Expand Down

0 comments on commit 2dccd76

Please sign in to comment.