Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 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 // Define stage to select: 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 // Select all versions to swap: 00098 $versions = $this->selectVersionsInWorkspace($wsid,0,$stage,($pageId?$pageId:-1)); 00099 00100 // Traverse the selection to build CMD array: 00101 foreach($versions as $table => $records) { 00102 foreach($records as $rec) { 00103 00104 // Build the cmd Array: 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 // Traversing all tables supporting versioning: 00135 foreach($TCA as $table => $cfg) { 00136 if ($TCA[$table]['ctrl']['versioningWS']) { 00137 00138 // Select all records from this table in the database from the workspace 00139 // This joins the online version with the offline version as tables A and B 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'. // Table A is the offline version and pid=-1 defines offline 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' : '')). // 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! 00146 ($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) 00147 ($stage!=-99 ? ' AND A.t3ver_stage='.intval($stage) : ''). 00148 ' AND B.pid>=0'. // Table B (online) must have PID >= 0 to signify being online. 00149 ' AND A.t3ver_oid=B.uid'. // ... and finally the join between the two tables. 00150 t3lib_BEfunc::deleteClause($table,'A'). 00151 t3lib_BEfunc::deleteClause($table,'B'), 00152 '', 00153 'B.uid' // Order by UID, mostly to have a sorting in the backend overview module which doesn't "jump around" when swapping. 00154 ); 00155 } 00156 } 00157 00158 return $output; 00159 } 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 /**************************** 00173 * 00174 * CLI functions 00175 * 00176 ****************************/ 00177 00183 function CLI_main() { 00184 $this->autoPublishWorkspaces(); 00185 } 00186 00193 function autoPublishWorkspaces() { 00194 global $TYPO3_CONF_VARS; 00195 00196 // Temporarily set high power... 00197 $GLOBALS['BE_USER']->user['admin'] = 1; 00198 00199 // Select all workspaces that needs to be published / unpublished: 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 // If any workspaces was selected: 00211 if (count($workspaces)) { 00212 require_once(PATH_t3lib.'class.t3lib_tcemain.php'); // Including it here because we want to load a 1-minute cronjob with inclusion only if needed! 00213 } 00214 00215 foreach($workspaces as $rec) { 00216 00217 // First, clear start/end time so it doesn't get select once again: 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 // Get CMD array: 00222 $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. 00223 00224 // Execute CMD array: 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 ?>