2 /***************************************************************
5 * (c) 2005-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Library with Workspace related functionality
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
45 * Library with Workspace related functionality
47 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
57 * Building tcemain CMD-array for swapping all versions in a workspace.
59 * @param integer Real workspace ID, cannot be ONLINE (zero).
60 * @param boolean If set, then the currently online versions are swapped into the workspace in exchange for the offline versions. Otherwise the workspace is emptied.
61 * @param [type] $pageId: ...
62 * @return array Command array for tcemain
64 function getCmdArrayForPublishWS($wsid, $doSwap, $pageId=0) {
66 $wsid = intval($wsid);
69 if ($wsid>=-1 && $wsid!==0) {
71 // Define stage to select:
74 $workspaceRec = t3lib_BEfunc
::getRecord('sys_workspace', $wsid);
75 if ($workspaceRec['publish_access']&1) {
80 // Select all versions to swap:
81 $versions = $this->selectVersionsInWorkspace($wsid, 0, $stage, ($pageId ?
$pageId : -1));
83 // Traverse the selection to build CMD array:
84 foreach ($versions as $table => $records) {
85 foreach ($records as $rec) {
87 // Build the cmd Array:
88 $cmd[$table][$rec['t3ver_oid']]['version'] = array(
90 'swapWith' => $rec['uid'],
91 'swapIntoWS' => $doSwap ?
1 : 0
100 * Select all records from workspace pending for publishing
101 * Used from backend to display workspace overview
102 * User for auto-publishing for selecting versions for publication
104 * @param integer Workspace ID. If -99, will select ALL versions from ANY workspace. If -98 will select all but ONLINE. >=-1 will select from the actual workspace
105 * @param integer Lifecycle filter: 1 = select all drafts (never-published), 2 = select all published one or more times (archive/multiple), anything else selects all.
106 * @param integer Stage filter: -99 means no filtering, otherwise it will be used to select only elements with that stage. For publishing, that would be "10"
107 * @param integer Page id: Live page for which to find versions in workspace!
108 * @return array Array of all records uids etc. First key is table name, second key incremental integer. Records are associative arrays with uid, t3ver_oid and t3ver_swapmode fields. The REAL pid of the online record is found as "realpid"
110 function selectVersionsInWorkspace($wsid, $filter = 0, $stage = -99, $pageId = -1) {
111 $wsid = intval($wsid);
112 $filter = intval($filter);
115 // Traversing all tables supporting versioning:
116 foreach ($GLOBALS['TCA'] as $table => $cfg) {
117 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
119 // Select all records from this table in the database from the workspace
120 // This joins the online version with the offline version as tables A and B
121 $recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows (
122 'A.uid, A.t3ver_oid,'.($table==='pages' ?
' A.t3ver_swapmode,':'').' B.pid AS realpid',
123 $table.' A,'.$table.' B',
124 'A.pid=-1'. // Table A is the offline version and pid=-1 defines offline
125 ($pageId!=-1 ?
($table==='pages' ?
' AND B.uid='.intval($pageId) : ' AND B.pid='.intval($pageId)) : '').
126 ($wsid>-98 ?
' AND A.t3ver_wsid='.$wsid : ($wsid===-98 ?
' AND A.t3ver_wsid!=0' : '')). // For "real" workspace numbers, select by that. If = -98, select all that are NOT online (zero). Anything else below -1 will not select on the wsid and therefore select all!
127 ($filter===1 ?
' AND A.t3ver_count=0' : ($filter===2 ?
' AND A.t3ver_count>0' : '')). // lifecycle filter: 1 = select all drafts (never-published), 2 = select all published one or more times (archive/multiple)
128 ($stage!=-99 ?
' AND A.t3ver_stage='.intval($stage) : '').
129 ' AND B.pid>=0'. // Table B (online) must have PID >= 0 to signify being online.
130 ' AND A.t3ver_oid=B.uid'. // ... and finally the join between the two tables.
131 t3lib_BEfunc
::deleteClause($table, 'A') .
132 t3lib_BEfunc
::deleteClause($table, 'B'),
134 'B.uid' // Order by UID, mostly to have a sorting in the backend overview module which doesn't "jump around" when swapping.
137 $output[$table] = $recs;
156 /****************************
160 ****************************/
163 * This method is called by the Scheduler task that triggers
164 * the autopublication process
165 * It searches for workspaces whose publication date is in the past
170 function autoPublishWorkspaces() {
171 // Temporarily set admin rights
172 // FIXME: once workspaces are cleaned up a better solution should be implemented
173 $currentAdminStatus = $GLOBALS['BE_USER']->user
['admin'];
174 $GLOBALS['BE_USER']->user
['admin'] = 1;
176 // Select all workspaces that needs to be published / unpublished:
177 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
178 'uid,swap_modes,publish_time,unpublish_time',
182 ((publish_time!=0 AND publish_time<='.intval($GLOBALS['EXEC_TIME']).')
183 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<='.intval($GLOBALS['EXEC_TIME']).'))'.
184 t3lib_BEfunc
::deleteClause('sys_workspace')
187 foreach ($workspaces as $rec) {
189 // First, clear start/end time so it doesn't get select once again:
190 $fieldArray = $rec['publish_time']!=0 ?
array('publish_time'=>0) : array('unpublish_time'=>0);
191 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . intval($rec['uid']), $fieldArray);
194 $cmd = $this->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes']==1); // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
196 // Execute CMD array:
197 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
198 $tce->stripslashes_values
= 0;
199 $tce->start(array(), $cmd);
200 $tce->process_cmdmap();
203 // Restore admin status
204 $GLOBALS['BE_USER']->user
['admin'] = $currentAdminStatus;
210 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/mod/user/ws/class.wslib.php'])) {
211 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['typo3/mod/user/ws/class.wslib.php']);