TYPO3 CMS  TYPO3_7-6
WorkspacesUtility.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 
18 
23 {
32  public function getCmdArrayForPublishWS($wsid, $doSwap, $pageId = 0)
33  {
34  $wsid = (int)$wsid;
35  $cmd = [];
36  if ($wsid >= -1 && $wsid !== 0) {
37  // Define stage to select:
38  $stage = -99;
39  if ($wsid > 0) {
40  $workspaceRec = BackendUtility::getRecord('sys_workspace', $wsid);
41  if ($workspaceRec['publish_access'] & 1) {
42  $stage = 10;
43  }
44  }
45  // Select all versions to swap:
46  $versions = $this->selectVersionsInWorkspace($wsid, 0, $stage, $pageId ? $pageId : -1);
47  // Traverse the selection to build CMD array:
48  foreach ($versions as $table => $records) {
49  foreach ($records as $rec) {
50  // Build the cmd Array:
51  $cmd[$table][$rec['t3ver_oid']]['version'] = [
52  'action' => 'swap',
53  'swapWith' => $rec['uid'],
54  'swapIntoWS' => $doSwap ? 1 : 0
55  ];
56  }
57  }
58  }
59  return $cmd;
60  }
61 
73  public function selectVersionsInWorkspace($wsid, $filter = 0, $stage = -99, $pageId = -1)
74  {
75  $wsid = (int)$wsid;
76  $filter = (int)$filter;
77  $pageId = (int)$pageId;
78  $output = [];
79  // Traversing all tables supporting versioning:
80  foreach ($GLOBALS['TCA'] as $table => $cfg) {
81  if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
82  // Select all records from this table in the database from the workspace
83  // This joins the online version with the offline version as tables A and B
84  $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('A.uid, A.t3ver_oid, B.pid AS realpid', $table . ' A,' . $table . ' B', 'A.pid=-1' . ($pageId != -1 ? ($table === 'pages' ? ' AND B.uid=' . $pageId : ' AND B.pid=' . $pageId) : '') . ($wsid > -98 ? ' AND A.t3ver_wsid=' . $wsid : ($wsid === -98 ? ' AND A.t3ver_wsid!=0' : '')) . ($filter === 1 ? ' AND A.t3ver_count=0' : ($filter === 2 ? ' AND A.t3ver_count>0' : '')) . ($stage != -99 ? ' AND A.t3ver_stage=' . (int)$stage : '') . ' AND B.pid>=0' . ' AND A.t3ver_oid=B.uid' . BackendUtility::deleteClause($table, 'A') . BackendUtility::deleteClause($table, 'B'), '', 'B.uid');
85  if (!empty($recs)) {
86  $output[$table] = $recs;
87  }
88  }
89  }
90  return $output;
91  }
92 
93  /****************************
94  *
95  * Scheduler methods
96  *
97  ****************************/
106  public function autoPublishWorkspaces()
107  {
108  // Temporarily set admin rights
109  // @todo once workspaces are cleaned up a better solution should be implemented
110  $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
111  $GLOBALS['BE_USER']->user['admin'] = 1;
112  // Select all workspaces that needs to be published / unpublished:
113  $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,swap_modes,publish_time,unpublish_time', 'sys_workspace', 'pid=0
114  AND
115  ((publish_time!=0 AND publish_time<=' . (int)$GLOBALS['EXEC_TIME'] . ')
116  OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . (int)$GLOBALS['EXEC_TIME'] . '))' . BackendUtility::deleteClause('sys_workspace'));
117  foreach ($workspaces as $rec) {
118  // First, clear start/end time so it doesn't get select once again:
119  $fieldArray = $rec['publish_time'] != 0 ? ['publish_time' => 0] : ['unpublish_time' => 0];
120  $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . (int)$rec['uid'], $fieldArray);
121  // Get CMD array:
122  $cmd = $this->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
123  // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
124  // Execute CMD array:
125  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
126  $tce->stripslashes_values = 0;
127  $tce->start([], $cmd);
128  $tce->process_cmdmap();
129  }
130  // Restore admin status
131  $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
132  }
133 }
selectVersionsInWorkspace($wsid, $filter=0, $stage=-99, $pageId=-1)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getCmdArrayForPublishWS($wsid, $doSwap, $pageId=0)
static deleteClause($table, $tableAlias='')