[!!!][TASK][CONF] Remove deprecated code for 4.7
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / ws / class.wslib.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Library with Workspace related functionality
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32
33
34
35
36
37
38
39
40
41
42
43
44 /**
45 * Library with Workspace related functionality
46 *
47 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
48 * @package TYPO3
49 * @subpackage core
50 */
51 class wslib {
52
53
54
55
56 /**
57 * Building tcemain CMD-array for swapping all versions in a workspace.
58 *
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
63 */
64 function getCmdArrayForPublishWS($wsid, $doSwap,$pageId=0) {
65
66 $wsid = intval($wsid);
67 $cmd = array();
68
69 if ($wsid>=-1 && $wsid!==0) {
70
71 // Define stage to select:
72 $stage = -99;
73 if ($wsid>0) {
74 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace',$wsid);
75 if ($workspaceRec['publish_access']&1) {
76 $stage = 10;
77 }
78 }
79
80 // Select all versions to swap:
81 $versions = $this->selectVersionsInWorkspace($wsid,0,$stage,($pageId?$pageId:-1));
82
83 // Traverse the selection to build CMD array:
84 foreach($versions as $table => $records) {
85 foreach($records as $rec) {
86
87 // Build the cmd Array:
88 $cmd[$table][$rec['t3ver_oid']]['version'] = array(
89 'action' => 'swap',
90 'swapWith' => $rec['uid'],
91 'swapIntoWS' => $doSwap ? 1 : 0
92 );
93 }
94 }
95 }
96 return $cmd;
97 }
98
99 /**
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
103 *
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"
109 */
110 function selectVersionsInWorkspace($wsid,$filter=0,$stage=-99,$pageId=-1) {
111 $wsid = intval($wsid);
112 $filter = intval($filter);
113 $output = array();
114
115 // Traversing all tables supporting versioning:
116 foreach ($GLOBALS['TCA'] as $table => $cfg) {
117 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
118
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'),
133 '',
134 'B.uid' // Order by UID, mostly to have a sorting in the backend overview module which doesn't "jump around" when swapping.
135 );
136 if (count($recs)) {
137 $output[$table] = $recs;
138 }
139 }
140 }
141
142 return $output;
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156 /****************************
157 *
158 * Scheduler methods
159 *
160 ****************************/
161
162 /**
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
166 * and publishes them
167 *
168 * @return void
169 */
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;
175
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',
179 'sys_workspace',
180 'pid=0
181 AND
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')
185 );
186
187 foreach($workspaces as $rec) {
188
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);
192
193 // Get CMD array:
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.
195
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();
201 }
202
203 // Restore admin status
204 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
205 }
206 }
207
208
209
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']);
212 }
213 ?>