|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2005-2011 Kasper Skårhøj (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 ***************************************************************/ 00027 /** 00028 * Library with Workspace related functionality 00029 * 00030 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00031 */ 00032 /** 00033 * [CLASS/FUNCTION INDEX of SCRIPT] 00034 * 00035 * 00036 * 00037 * 68: class wslib 00038 * 81: function getCmdArrayForPublishWS($wsid, $doSwap,$pageId=0) 00039 * 127: function selectVersionsInWorkspace($wsid,$filter=0,$stage=-99,$pageId=-1) 00040 * 00041 * SECTION: CLI functions 00042 * 183: function CLI_main() 00043 * 193: function autoPublishWorkspaces() 00044 * 00045 * TOTAL FUNCTIONS: 4 00046 * (This index is automatically created/updated by the extension "extdeveval") 00047 * 00048 */ 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 /** 00062 * Library with Workspace related functionality 00063 * 00064 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00065 * @package TYPO3 00066 * @subpackage core 00067 */ 00068 class wslib { 00069 00070 00071 00072 00073 /** 00074 * Building tcemain CMD-array for swapping all versions in a workspace. 00075 * 00076 * @param integer Real workspace ID, cannot be ONLINE (zero). 00077 * @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. 00078 * @param [type] $pageId: ... 00079 * @return array Command array for tcemain 00080 */ 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 00116 /** 00117 * Select all records from workspace pending for publishing 00118 * Used from backend to display workspace overview 00119 * User for auto-publishing for selecting versions for publication 00120 * 00121 * @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 00122 * @param integer Lifecycle filter: 1 = select all drafts (never-published), 2 = select all published one or more times (archive/multiple), anything else selects all. 00123 * @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" 00124 * @param integer Page id: Live page for which to find versions in workspace! 00125 * @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" 00126 */ 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 $recs = $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 if (count($recs)) { 00156 $output[$table] = $recs; 00157 } 00158 } 00159 } 00160 00161 return $output; 00162 } 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 /**************************** 00176 * 00177 * Scheduler methods 00178 * 00179 ****************************/ 00180 00181 /** 00182 * Main function to call from cli-script 00183 * 00184 * @return void 00185 * @deprecated since TYPO3 4.5, will be removed in TYPO3 4.7 - This was meant for an obsolete CLI script. You shouldn't be calling this. 00186 */ 00187 function CLI_main() { 00188 t3lib_div::logDeprecatedFunction(); 00189 $this->autoPublishWorkspaces(); 00190 } 00191 00192 /** 00193 * This method is called by the Scheduler task that triggers 00194 * the autopublication process 00195 * It searches for workspaces whose publication date is in the past 00196 * and publishes them 00197 * 00198 * @return void 00199 */ 00200 function autoPublishWorkspaces() { 00201 global $TYPO3_CONF_VARS; 00202 00203 // Temporarily set admin rights 00204 // FIXME: once workspaces are cleaned up a better solution should be implemented 00205 $currentAdminStatus = $GLOBALS['BE_USER']->user['admin']; 00206 $GLOBALS['BE_USER']->user['admin'] = 1; 00207 00208 // Select all workspaces that needs to be published / unpublished: 00209 $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00210 'uid,swap_modes,publish_time,unpublish_time', 00211 'sys_workspace', 00212 'pid=0 00213 AND 00214 ((publish_time!=0 AND publish_time<='.intval($GLOBALS['EXEC_TIME']).') 00215 OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<='.intval($GLOBALS['EXEC_TIME']).'))'. 00216 t3lib_BEfunc::deleteClause('sys_workspace') 00217 ); 00218 00219 foreach($workspaces as $rec) { 00220 00221 // First, clear start/end time so it doesn't get select once again: 00222 $fieldArray = $rec['publish_time']!=0 ? array('publish_time'=>0) : array('unpublish_time'=>0); 00223 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace','uid='.intval($rec['uid']),$fieldArray); 00224 00225 // Get CMD array: 00226 $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. 00227 00228 // Execute CMD array: 00229 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00230 $tce->stripslashes_values = 0; 00231 $tce->start(array(),$cmd); 00232 $tce->process_cmdmap(); 00233 } 00234 00235 // Restore admin status 00236 $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus; 00237 } 00238 } 00239 00240 00241 00242 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wslib.php'])) { 00243 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/mod/user/ws/class.wslib.php']); 00244 } 00245 ?>
1.8.0