‪TYPO3CMS  11.5
WorkspaceRestriction.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 
23 
40 {
41  protected int ‪$workspaceId;
42 
51 
52  public function ‪__construct(int ‪$workspaceId = 0, bool ‪$includeAllVersionedRecords = false)
53  {
54  $this->workspaceId = ‪$workspaceId;
55  $this->includeAllVersionedRecords = ‪$includeAllVersionedRecords;
56  }
57 
65  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
66  {
67  $constraints = [];
68  foreach ($queriedTables as $tableAlias => $tableName) {
69  if (empty(‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? false)) {
70  continue;
71  }
72  if ($this->workspaceId === 0) {
73  // Only include records from live workspace
74  $workspaceIdExpression = $expressionBuilder->‪eq($tableAlias . '.t3ver_wsid', 0);
75  } else {
76  // Include live records PLUS records from the given workspace
77  $workspaceIdExpression = $expressionBuilder->‪in(
78  $tableAlias . '.t3ver_wsid',
79  [0, $this->workspaceId]
80  );
81  }
82  // Always filter out versioned records that have an "offline" record
83  // But include moved records AND newly created records (t3ver_oid=0)
84  if ($this->includeAllVersionedRecords === false) {
85  $constraints[] = $expressionBuilder->‪andX(
86  $workspaceIdExpression,
87  $expressionBuilder->‪orX(
88  $expressionBuilder->‪eq(
89  $tableAlias . '.t3ver_oid',
90  0
91  ),
92  $expressionBuilder->‪eq(
93  $tableAlias . '.t3ver_state',
95  )
96  )
97  );
98  } else {
99  // Include live records plus records from the given workspace
100  // but never include versioned records marked as deleted
101  $constraints[] = $expressionBuilder->‪andX(
102  $workspaceIdExpression,
103  $expressionBuilder->‪neq(
104  't3ver_state',
106  )
107  );
108  }
109  }
110  return $expressionBuilder->‪andX(...$constraints);
111  }
112 }
‪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
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:136
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: WorkspaceRestriction.php:41
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\$includeAllVersionedRecords
‪bool $includeAllVersionedRecords
Definition: WorkspaceRestriction.php:50
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\neq
‪string neq(string $fieldName, $value)
Definition: ExpressionBuilder.php:155
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: WorkspaceRestriction.php:65
‪TYPO3\CMS\Core\Versioning\VersionState\DELETE_PLACEHOLDER
‪const DELETE_PLACEHOLDER
Definition: VersionState.php:61
‪TYPO3\CMS\Core\Versioning\VersionState\MOVE_POINTER
‪const MOVE_POINTER
Definition: VersionState.php:78
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\in
‪string in(string $fieldName, $value)
Definition: ExpressionBuilder.php:285
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:72
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:85
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\__construct
‪__construct(int $workspaceId=0, bool $includeAllVersionedRecords=false)
Definition: WorkspaceRestriction.php:52
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction
Definition: WorkspaceRestriction.php:40