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