‪TYPO3CMS  10.4
FrontendWorkspaceRestriction.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
25 
30 {
34  protected ‪$workspaceId;
35 
40 
44  protected ‪$enforceLiveRowsOnly;
45 
51  public function ‪__construct(int ‪$workspaceId = null, bool ‪$includeRowsForWorkspacePreview = null, bool ‪$enforceLiveRowsOnly = true)
52  {
53  $globalWorkspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
54  $this->workspaceId = ‪$workspaceId ?? $globalWorkspaceId;
55  $this->includeRowsForWorkspacePreview = ‪$includeRowsForWorkspacePreview ?? $globalWorkspaceId > 0;
56  $this->enforceLiveRowsOnly = ‪$enforceLiveRowsOnly;
57  }
58 
67  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
68  {
69  $constraints = [];
70  foreach ($queriedTables as $tableAlias => $tableName) {
71  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
72  if (!empty($workspaceEnabled)) {
73  if (!$this->includeRowsForWorkspacePreview) {
74  // Filter out placeholder records (new/moved/deleted items)
75  // in case we are NOT in a versioning preview (That means we are online!)
76  $constraints[] = $expressionBuilder->‪lte(
77  $tableAlias . '.t3ver_state',
78  // Trigger __toString(), then cast int
80  );
81  } elseif ($tableName !== 'pages') {
82  // Show only records of the live and current workspace in case we are in a versioning preview
83  $constraints[] = $expressionBuilder->‪orX(
84  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', 0),
85  $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', (int)$this->workspaceId)
86  );
87  }
88  // Filter out versioned records
89  if ($this->enforceLiveRowsOnly) {
90  $constraints[] = $expressionBuilder->‪eq($tableAlias . '.t3ver_oid', 0);
91  }
92  }
93  }
94  return $expressionBuilder->‪andX(...$constraints);
95  }
96 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$enforceLiveRowsOnly
‪bool $enforceLiveRowsOnly
Definition: FrontendWorkspaceRestriction.php:41
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:109
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction
Definition: FrontendWorkspaceRestriction.php:30
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: FrontendWorkspaceRestriction.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendWorkspaceRestriction.php:64
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪string lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:154
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:70
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:82
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\$includeRowsForWorkspacePreview
‪bool $includeRowsForWorkspacePreview
Definition: FrontendWorkspaceRestriction.php:37
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, bool $includeRowsForWorkspacePreview=null, bool $enforceLiveRowsOnly=true)
Definition: FrontendWorkspaceRestriction.php:48