00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00068 class wslib {
00069
00070
00071
00072
00081 function getCmdArrayForPublishWS($wsid, $doSwap,$pageId=0) {
00082
00083 $wsid = intval($wsid);
00084 $cmd = array();
00085
00086 if ($wsid>=-1 && $wsid!==0) {
00087
00088
00089 $stage = -99;
00090 if ($wsid>0) {
00091 $workspaceRec = t3lib_BEfunc::getRecord('sys_workspace',$wsid);
00092 if ($workspaceRec['publish_access']&1) {
00093 $stage = 10;
00094 }
00095 }
00096
00097
00098 $versions = $this->selectVersionsInWorkspace($wsid,0,$stage,($pageId?$pageId:-1));
00099
00100
00101 foreach($versions as $table => $records) {
00102 foreach($records as $rec) {
00103
00104
00105 $cmd[$table][$rec['t3ver_oid']]['version'] = array(
00106 'action' => 'swap',
00107 'swapWith' => $rec['uid'],
00108 'swapIntoWS' => $doSwap ? 1 : 0
00109 );
00110 }
00111 }
00112 }
00113 return $cmd;
00114 }
00115
00127 function selectVersionsInWorkspace($wsid,$filter=0,$stage=-99,$pageId=-1) {
00128 global $TCA;
00129
00130 $wsid = intval($wsid);
00131 $filter = intval($filter);
00132 $output = array();
00133
00134
00135 foreach($TCA as $table => $cfg) {
00136 if ($TCA[$table]['ctrl']['versioningWS']) {
00137
00138
00139
00140 $output[$table] = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows (
00141 'A.uid, A.t3ver_oid,'.($table==='pages' ? ' A.t3ver_swapmode,':'').' B.pid AS realpid',
00142 $table.' A,'.$table.' B',
00143 'A.pid=-1'.
00144 ($pageId!=-1 ? ($table==='pages' ? ' AND B.uid='.intval($pageId) : ' AND B.pid='.intval($pageId)) : '').
00145 ($wsid>-98 ? ' AND A.t3ver_wsid='.$wsid : ($wsid===-98 ? ' AND A.t3ver_wsid!=0' : '')).
00146 ($filter===1 ? ' AND A.t3ver_count=0' : ($filter===2 ? ' AND A.t3ver_count>0' : '')).
00147 ($stage!=-99 ? ' AND A.t3ver_stage='.intval($stage) : '').
00148 ' AND B.pid>=0'.
00149 ' AND A.t3ver_oid=B.uid'.
00150 t3lib_BEfunc::deleteClause($table,'A').
00151 t3lib_BEfunc::deleteClause($table,'B'),
00152 '',
00153 'B.uid'
00154 );
00155 }
00156 }
00157
00158 return $output;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00183 function CLI_main() {
00184 $this->autoPublishWorkspaces();
00185 }
00186
00193 function autoPublishWorkspaces() {
00194 global $TYPO3_CONF_VARS;
00195
00196
00197 $GLOBALS['BE_USER']->user['admin'] = 1;
00198
00199
00200 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00201 'uid,swap_modes,publish_time,unpublish_time',
00202 'sys_workspace',
00203 'pid=0
00204 AND
00205 ((publish_time!=0 AND publish_time<='.intval($GLOBALS['EXEC_TIME']).')
00206 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<='.intval($GLOBALS['EXEC_TIME']).'))'.
00207 t3lib_BEfunc::deleteClause('sys_workspace')
00208 );
00209
00210
00211 if (count($workspaces)) {
00212 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
00213 }
00214
00215 foreach($workspaces as $rec) {
00216
00217
00218 $fieldArray = $rec['publish_time']!=0 ? array('publish_time'=>0) : array('unpublish_time'=>0);
00219 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace','uid='.intval($rec['uid']),$fieldArray);
00220
00221
00222 $cmd = $this->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes']==1);
00223
00224
00225 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00226 $tce->stripslashes_values = 0;
00227 $tce->start(array(),$cmd);
00228 $tce->process_cmdmap();
00229 }
00230 }
00231 }
00232
00233
00234
00235 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wslib.php']) {
00236 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wslib.php']);
00237 }
00238 ?>