2 namespace TYPO3\CMS\Core\Utility;
91 'backend_layout_next_level'
124 $this->pageUid = (int)$uid;
126 if ($context === null) {
128 $this->pageContext =
$GLOBALS[
'TSFE']->sys_page;
133 $this->pageContext = $context;
146 $this->languageUid = (int)$this->pageContext->sys_language_uid;
147 $this->workspaceUid = (
int)$this->pageContext->versioningWorkspaceId;
148 $this->versionPreview = $this->pageContext->versioningPreview;
149 if ($this->mountPointParameter !==
'') {
150 if (!
$GLOBALS[
'TYPO3_CONF_VARS'][
'FE'][
'enable_mount_pids']) {
151 throw new \RuntimeException(
'Mount-Point Pages are disabled for this installation. Cannot resolve a Rootline for a page with Mount-Points', 1343462896);
156 if (self::$cache === null) {
160 self::$rootlineFields = array_unique(self::$rootlineFields);
161 $this->databaseConnection =
$GLOBALS[
'TYPO3_DB'];
175 self::$localCache = array();
176 self::$pageRecordCache = array();
192 return implode(
'_', array(
193 $otherUid !== null ? (
int)$otherUid : $this->pageUid,
197 $this->versionPreview ? 1 : 0
206 public function get()
208 if (!isset(static::$localCache[$this->cacheIdentifier])) {
209 $entry = static::$cache->get($this->cacheIdentifier);
211 $this->generateRootlineCache();
214 $depth = count($entry);
222 if (isset(static::$localCache[$parentCacheIdentifier])) {
227 $entry = array_slice($entry, 1, null,
true);
228 static::$localCache[$parentCacheIdentifier] = $entry;
245 if (!isset(self::$pageRecordCache[$currentCacheIdentifier])) {
246 $row = $this->databaseConnection->exec_SELECTgetSingleRow(implode(
',', self::$rootlineFields),
'pages',
'uid = ' . (
int)$uid .
' AND pages.deleted = 0 AND pages.doktype <> ' .
PageRepository::DOKTYPE_RECYCLER);
248 throw new \RuntimeException(
'Could not fetch page data for uid ' . $uid .
'.', 1343589451);
250 $this->pageContext->versionOL(
'pages', $row,
false,
true);
251 $this->pageContext->fixVersioningPid(
'pages', $row);
252 if (is_array($row)) {
253 if ($this->languageUid > 0) {
254 $row = $this->pageContext->getPageOverlay($row, $this->languageUid);
256 $row = $this->enrichWithRelationFields(isset($row[
'_PAGES_OVERLAY_UID']) ? $row[
'_PAGES_OVERLAY_UID'] : $uid, $row);
257 self::$pageRecordCache[$currentCacheIdentifier] = $row;
260 if (!is_array(self::$pageRecordCache[$currentCacheIdentifier])) {
261 throw new \RuntimeException(
'Broken rootline. Could not resolve page with uid ' . $uid .
'.', 1343464101);
263 return self::$pageRecordCache[$currentCacheIdentifier];
274 protected function enrichWithRelationFields($uid, array $pageRecord)
277 foreach (
$GLOBALS[
'TCA'][
'pages'][
'columns'] as $column => $configuration) {
279 $configuration = $configuration[
'config'];
280 if ($configuration[
'MM']) {
284 $pageRecord[$column],
285 isset($configuration[
'allowed']) ? $configuration[
'allowed'] : $configuration[
'foreign_table'],
286 $configuration[
'MM'],
291 $relatedUids = isset($loadDBGroup->tableArray[$configuration[
'foreign_table']])
292 ? $loadDBGroup->tableArray[$configuration[
'foreign_table']]
295 $columnIsOverlaid = in_array($column, $pageOverlayFields,
true);
296 $table = $configuration[
'foreign_table'];
297 $field = $configuration[
'foreign_field'];
298 $whereClauseParts = array($field .
' = ' . (
int)($columnIsOverlaid ? $uid : $pageRecord[
'uid']));
299 if (isset($configuration[
'foreign_match_fields']) && is_array($configuration[
'foreign_match_fields'])) {
300 foreach ($configuration[
'foreign_match_fields'] as $field => $value) {
301 $whereClauseParts[] = $field .
' = ' . $this->databaseConnection->fullQuoteStr($value, $table);
304 if (isset($configuration[
'foreign_table_field'])) {
305 if ((
int)$this->languageUid > 0 && $columnIsOverlaid) {
306 $whereClauseParts[] = trim($configuration[
'foreign_table_field']) .
' = \'pages_language_overlay\'';
308 $whereClauseParts[] = trim($configuration[
'foreign_table_field']) .
' = \'pages\'';
311 if (isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled'])) {
312 $whereClauseParts[] = $table .
'.' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled'] .
' = 0';
314 $whereClause = implode(
' AND ', $whereClauseParts);
315 $whereClause .= $this->pageContext->deleteClause($table);
316 $orderBy = isset($configuration[
'foreign_sortby']) ? $configuration[
'foreign_sortby'] :
'';
317 $rows = $this->databaseConnection->exec_SELECTgetRows(
'uid', $table, $whereClause,
'', $orderBy);
318 if (!is_array($rows)) {
319 throw new \RuntimeException(
'Could to resolve related records for page ' . $uid .
' and foreign_table ' . htmlspecialchars($configuration[
'foreign_table']), 1343589452);
321 $relatedUids = array();
322 foreach ($rows as $row) {
323 $relatedUids[] = $row[
'uid'];
326 $pageRecord[$column] = implode(
',', $relatedUids);
341 $configuration = $configuration[
'config'];
342 if (!empty($configuration[
'MM']) && !empty($configuration[
'type']) && in_array($configuration[
'type'], array(
'select',
'inline',
'group'))) {
345 if (!empty($configuration[
'foreign_field']) && !empty($configuration[
'type']) && in_array($configuration[
'type'], array(
'select',
'inline'))) {
357 protected function generateRootlineCache()
362 $mountPoint = $this->
getRecordArray($this->parsedMountPointParameters[$this->pageUid]);
364 $parentUid = $mountPoint[
'pid'];
366 unset($this->parsedMountPointParameters[$this->pageUid]);
368 $parentUid = $page[
'pid'];
370 $cacheTags = array(
'pageId_' . $page[
'uid']);
371 if ($parentUid > 0) {
373 $mountPointParameter = !empty($this->parsedMountPointParameters) ? $this->mountPointParameter :
'';
376 $rootline = $rootline->get();
378 foreach ($rootline as $entry) {
379 $cacheTags[] =
'pageId_' . $entry[
'uid'];
380 if ($entry[
'uid'] == $this->pageUid) {
381 throw new \RuntimeException(
'Circular connection in rootline for page with uid ' . $this->pageUid .
' found. Check your mountpoint configuration.', 1343464103);
387 array_push($rootline, $page);
389 static::$cache->set($this->cacheIdentifier, $rootline, $cacheTags);
401 return in_array($this->pageUid, array_keys($this->parsedMountPointParameters));
414 if ($mountPointPageData[
'mount_pid'] != $mountedPageData[
'uid']) {
415 throw new \RuntimeException(
'Broken rootline. Mountpoint parameter does not match the actual rootline. mount_pid (' . $mountPointPageData[
'mount_pid'] .
') does not match page uid (' . $mountedPageData[
'uid'] .
').', 1343464100);
418 if ($mountPointPageData[
'mount_pid_ol']) {
419 $mountedPageData[
'_MOUNT_OL'] =
true;
420 $mountedPageData[
'_MOUNT_PAGE'] = array(
421 'uid' => $mountPointPageData[
'uid'],
422 'pid' => $mountPointPageData[
'pid'],
423 'title' => $mountPointPageData[
'title']
427 $mountedPageData = $mountPointPageData;
430 $mountedPageData[
'_MP_PARAM'] = $this->pageUid .
'-' . $mountPointPageData[
'uid'];
431 return $mountedPageData;
444 foreach ($mountPoints as $mP) {
446 $this->parsedMountPointParameters[$mountedPageUid] = $mountPageUid;