‪TYPO3CMS  ‪main
BackendWorkspaceRestriction.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 
31 {
35  protected ‪$workspaceId;
36 
41 
45  public function ‪__construct(int ‪$workspaceId = null, ‪$includeRowsForWorkspaceOverlay = true)
46  {
47  trigger_error('BackendWorkspaceRestriction will be removed in TYPO3 v13.0. Use WorkspaceRestriction instead.', E_USER_DEPRECATED);
48  if (‪$workspaceId === null) {
49  $this->workspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
50  } else {
51  $this->workspaceId = ‪$workspaceId;
52  }
53  $this->includeRowsForWorkspaceOverlay = ‪$includeRowsForWorkspaceOverlay;
54  }
55 
63  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
64  {
65  $constraints = [];
66  foreach ($queriedTables as $tableAlias => $tableName) {
67  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
68  if (!empty($workspaceEnabled)) {
69  $workspaceIdExpression = $expressionBuilder->‪eq(
70  $tableAlias . '.t3ver_wsid',
71  (int)$this->workspaceId
72  );
73  if ($this->includeRowsForWorkspaceOverlay) {
74  $constraints[] = $expressionBuilder->‪or(
75  $workspaceIdExpression,
76  $expressionBuilder->‪lte(
77  $tableAlias . '.t3ver_state',
78  // Trigger __toString(), then cast int
80  )
81  );
82  } else {
83  $comparisonExpression = $this->workspaceId === 0 ? 'eq' : 'gt';
84  $constraints[] = $workspaceIdExpression;
85  $constraints[] = $expressionBuilder->{$comparisonExpression}(
86  $tableAlias . '.t3ver_oid',
87  0
88  );
89  }
90  }
91  }
92  return $expressionBuilder->‪and(...$constraints);
93  }
94 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:36
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:128
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: BackendWorkspaceRestriction.php:34
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\or
‪or(CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:105
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
Definition: BackendWorkspaceRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:167
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\and
‪and(CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:97
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:55
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: BackendWorkspaceRestriction.php:61
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, $includeRowsForWorkspaceOverlay=true)
Definition: BackendWorkspaceRestriction.php:43
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$includeRowsForWorkspaceOverlay
‪bool $includeRowsForWorkspaceOverlay
Definition: BackendWorkspaceRestriction.php:38
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51