TYPO3 CMS  TYPO3_6-2
PlainDataResolver.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
28 
32  protected $tableName;
33 
37  protected $liveIds;
38 
42  protected $sortingStatement;
43 
47  protected $workspaceId;
48 
52  protected $keepLiveIds = FALSE;
53 
57  protected $keepDeletePlaceholder = FALSE;
58 
62  protected $keepMovePlaceholder = TRUE;
63 
67  protected $resolvedIds;
68 
74  public function __construct($tableName, array $liveIds, $sortingStatement = NULL) {
75  $this->tableName = $tableName;
76  $this->liveIds = $this->reindex($liveIds);
77  $this->sortingStatement = $sortingStatement;
78  }
79 
85  public function setWorkspaceId($workspaceId) {
86  $this->workspaceId = (int)$workspaceId;
87  }
88 
94  public function setKeepLiveIds($keepLiveIds) {
95  $this->keepLiveIds = (bool)$keepLiveIds;
96  }
97 
104  $this->keepDeletePlaceholder = (bool)$keepDeletePlaceholder;
105  }
106 
113  $this->keepMovePlaceholder = (bool)$keepMovePlaceholder;
114  }
115 
119  public function get() {
120  if (isset($this->resolvedIds)) {
121  return $this->resolvedIds;
122  }
123 
124  $ids = $this->processVersionOverlays($this->liveIds);
125  $ids = $this->processSorting($ids);
126  $ids = $this->applyLiveIds($ids);
127 
128  $this->resolvedIds = $ids;
129  return $this->resolvedIds;
130  }
131 
138  protected function processVersionOverlays(array $ids) {
139  if (empty($this->workspaceId) || !$this->isWorkspaceEnabled() || empty($ids)) {
140  return $ids;
141  }
142 
143  $ids = $this->processVersionMovePlaceholders($ids);
144  $versions = $this->getDatabaseConnection()->exec_SELECTgetRows(
145  'uid,t3ver_oid,t3ver_state',
146  $this->tableName,
147  'pid=-1 AND t3ver_oid IN (' . $this->intImplode(',', $ids) . ')'
148  . ' AND t3ver_wsid=' . $this->workspaceId
149  );
150 
151  if (!empty($versions)) {
152  foreach ($versions as $version) {
153  $liveReferenceId = $version['t3ver_oid'];
154  $versionId = $version['uid'];
155  if (isset($ids[$liveReferenceId])) {
156  if (!$this->keepDeletePlaceholder && VersionState::cast($version['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
157  unset($ids[$liveReferenceId]);
158  } else {
159  $ids[$liveReferenceId] = $versionId;
160  }
161  }
162  }
163  $ids = $this->reindex($ids);
164  }
165 
166  return $ids;
167  }
168 
175  protected function processVersionMovePlaceholders(array $ids) {
176  // Early return on insufficient data-set
177  if (empty($this->workspaceId) || !$this->isVersionMovePlaceholderAware() || empty($ids)) {
178  return $ids;
179  }
180 
181  $movePlaceholders = $this->getDatabaseConnection()->exec_SELECTgetRows(
182  'uid,t3ver_move_id',
183  $this->tableName,
184  'pid<>-1 AND t3ver_state=' . VersionState::MOVE_PLACEHOLDER
185  . ' AND t3ver_wsid=' . $this->workspaceId
186  . ' AND t3ver_move_id IN (' . $this->intImplode(',', $ids) . ')'
187  );
188 
189  if (!empty($movePlaceholders)) {
190  foreach ($movePlaceholders as $movePlaceholder) {
191  $liveReferenceId = $movePlaceholder['t3ver_move_id'];
192  $movePlaceholderId = $movePlaceholder['uid'];
193  // Substitute MOVE_PLACEHOLDER and purge live reference
194  if (isset($ids[$movePlaceholderId])) {
195  $ids[$movePlaceholderId] = $liveReferenceId;
196  unset($ids[$liveReferenceId]);
197  // Just purge live reference
198  } elseif (!$this->keepMovePlaceholder) {
199  unset($ids[$liveReferenceId]);
200  }
201  }
202  $ids = $this->reindex($ids);
203  }
204 
205  return $ids;
206  }
207 
215  protected function processSorting(array $ids) {
216  // Early return on missing sorting statement or insufficient data-set
217  if (empty($this->sortingStatement) || count($ids) < 2) {
218  return $ids;
219  }
220 
221  $records = $this->getDatabaseConnection()->exec_SELECTgetRows(
222  'uid',
223  $this->tableName,
224  'uid IN (' . $this->intImplode(',', $ids) . ')',
225  '',
226  $this->sortingStatement,
227  '',
228  'uid'
229  );
230 
231  if (!is_array($records)) {
232  return array();
233  }
234 
235  $ids = $this->reindex(array_keys($records));
236  return $ids;
237  }
238 
247  protected function applyLiveIds(array $ids) {
248  if (!$this->keepLiveIds || !$this->isWorkspaceEnabled() || empty($ids)) {
249  return $ids;
250  }
251 
252  $records = $this->getDatabaseConnection()->exec_SELECTgetRows(
253  'uid,t3ver_oid',
254  $this->tableName,
255  'uid IN (' . $this->intImplode(',', $ids) . ')',
256  '',
257  '',
258  '',
259  'uid'
260  );
261 
262  if (!is_array($records)) {
263  return array();
264  }
265 
266  foreach ($ids as $id) {
267  if (!empty($records[$id]['t3ver_oid'])) {
268  $ids[$id] = $records[$id]['t3ver_oid'];
269  }
270  }
271 
272  $ids = $this->reindex($ids);
273  return $ids;
274  }
275 
282  protected function reindex(array $ids) {
283  if (empty($ids)) {
284  return $ids;
285  }
286  $ids = array_values($ids);
287  $ids = array_combine($ids, $ids);
288  return $ids;
289  }
290 
294  protected function isWorkspaceEnabled() {
295  return BackendUtility::isTableWorkspaceEnabled($this->tableName);
296  }
297 
301  protected function isVersionMovePlaceholderAware() {
302  return BackendUtility::isTableMovePlaceholderAware($this->tableName);
303  }
304 
308  protected function isLocalizationEnabled() {
309  return BackendUtility::isTableLocalizable($this->tableName);
310  }
311 
319  protected function intImplode($delimiter, array $values) {
320  return implode($delimiter, $this->getDatabaseConnection()->cleanIntArray($values));
321  }
322 
326  protected function getDatabaseConnection() {
327  return $GLOBALS['TYPO3_DB'];
328  }
329 
330 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
__construct($tableName, array $liveIds, $sortingStatement=NULL)