‪TYPO3CMS  9.5
FrontendWorkspaceRestriction.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
23 
28 {
32  protected ‪$workspaceId;
33 
38 
42  protected ‪$enforceLiveRowsOnly;
43 
49  public function ‪__construct(int ‪$workspaceId = null, bool ‪$includeRowsForWorkspacePreview = null, bool ‪$enforceLiveRowsOnly = true)
50  {
51  $globalWorkspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
52  $this->workspaceId = ‪$workspaceId ?? $globalWorkspaceId;
53  $this->includeRowsForWorkspacePreview = ‪$includeRowsForWorkspacePreview ?? $globalWorkspaceId > 0;
54  $this->enforceLiveRowsOnly = ‪$enforceLiveRowsOnly;
55  }
56 
65  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
66  {
67  $constraints = [];
68  foreach ($queriedTables as $tableAlias => $tableName) {
69  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
70  if (!empty($workspaceEnabled)) {
71  if (!$this->includeRowsForWorkspacePreview) {
72  // Filter out placeholder records (new/moved/deleted items)
73  // in case we are NOT in a versioning preview (That means we are online!)
74  $constraints[] = $expressionBuilder->‪lte(
75  $tableAlias . '.t3ver_state',
76  // Trigger __toString(), then cast int
78  );
79  } elseif ($tableName !== 'pages') {
80  // Show only records of the live and current workspace in case we are in a versioning preview
81  $constraints[] = $expressionBuilder->‪orX(
82  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', 0),
83  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', (int)$this->workspaceId)
84  );
85  }
86  // Filter out versioned records
87  if ($this->enforceLiveRowsOnly) {
88  $constraints[] = $expressionBuilder->‪neq($tableAlias . '.pid', -1);
89  }
90  }
91  }
92  return $expressionBuilder->‪andX(...$constraints);
93  }
94 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$enforceLiveRowsOnly
‪bool $enforceLiveRowsOnly
Definition: FrontendWorkspaceRestriction.php:39
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:107
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\neq
‪string neq(string $fieldName, $value)
Definition: ExpressionBuilder.php:126
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction
Definition: FrontendWorkspaceRestriction.php:28
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: FrontendWorkspaceRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendWorkspaceRestriction.php:62
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪string lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:152
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:23
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:68
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:3
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:80
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$includeRowsForWorkspacePreview
‪bool $includeRowsForWorkspacePreview
Definition: FrontendWorkspaceRestriction.php:35
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:23
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, bool $includeRowsForWorkspacePreview=null, bool $enforceLiveRowsOnly=true)
Definition: FrontendWorkspaceRestriction.php:46