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