|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /*************************************************************** 00004 * Copyright notice 00005 * 00006 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces) 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 00029 /** 00030 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces) 00031 * @package Workspaces 00032 * @subpackage Service 00033 */ 00034 class tx_Workspaces_Service_Tcemain { 00035 00036 /** 00037 * In case a sys_workspace_stage record is deleted we do a hard reset 00038 * for all existing records in that stage to avoid that any of these end up 00039 * as orphan records. 00040 * 00041 * @param string $command 00042 * @param string $table 00043 * @param string $id 00044 * @param string $value 00045 * @param t3lib_TCEmain $tcemain 00046 * @return void 00047 */ 00048 public function processCmdmap_postProcess($command, $table, $id, $value, t3lib_TCEmain $tcemain) { 00049 if ($command === 'delete') { 00050 if ($table === Tx_Workspaces_Service_Stages::TABLE_STAGE) { 00051 $this->resetStageOfElements($id); 00052 } elseif ($table === tx_Workspaces_Service_Workspaces::TABLE_WORKSPACE) { 00053 $this->flushWorkspaceElements($id); 00054 } 00055 } 00056 } 00057 00058 /** 00059 * hook that is called AFTER all commands of the commandmap was 00060 * executed 00061 * 00062 * @param t3lib_TCEmain $tcemainObj reference to the main tcemain object 00063 * @return void 00064 */ 00065 public function processCmdmap_afterFinish(t3lib_TCEmain $tcemainObj) { 00066 if (TYPO3_UseCachingFramework) { 00067 $this->flushWorkspaceCacheEntriesByWorkspaceId($tcemainObj->BE_USER->workspace); 00068 } 00069 } 00070 00071 /** 00072 * In case a sys_workspace_stage record is deleted we do a hard reset 00073 * for all existing records in that stage to avoid that any of these end up 00074 * as orphan records. 00075 * 00076 * @param integer $stageId Elements with this stage are resetted 00077 * @return void 00078 */ 00079 protected function resetStageOfElements($stageId) { 00080 $fields = array('t3ver_stage' => Tx_Workspaces_Service_Stages::STAGE_EDIT_ID); 00081 00082 foreach ($this->getTcaTables() as $tcaTable) { 00083 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) { 00084 00085 $where = 't3ver_stage = ' . intval($stageId); 00086 $where .= ' AND t3ver_wsid > 0 AND pid=-1'; 00087 $where .= t3lib_BEfunc::deleteClause($tcaTable); 00088 00089 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tcaTable, $where, $fields); 00090 } 00091 } 00092 } 00093 00094 /** 00095 * Flushes elements of a particular workspace to avoid orphan records. 00096 * 00097 * @param integer $workspaceId The workspace to be flushed 00098 * @return void 00099 */ 00100 protected function flushWorkspaceElements($workspaceId) { 00101 $command = array(); 00102 00103 foreach ($this->getTcaTables() as $tcaTable) { 00104 if (t3lib_BEfunc::isTableWorkspaceEnabled($tcaTable)) { 00105 $where = '1=1'; 00106 $where .= t3lib_BEfunc::getWorkspaceWhereClause($tcaTable, $workspaceId); 00107 $where .= t3lib_BEfunc::deleteClause($tcaTable); 00108 00109 $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $tcaTable, $where, '', '', '', 'uid'); 00110 if (is_array($records)) { 00111 foreach (array_keys($records) as $recordId) { 00112 $command[$tcaTable][$recordId]['version']['action'] = 'flush'; 00113 } 00114 } 00115 } 00116 } 00117 00118 if (count($command)) { 00119 $tceMain = $this->getTceMain(); 00120 $tceMain->start(array(), $command); 00121 $tceMain->process_cmdmap(); 00122 } 00123 } 00124 00125 /** 00126 * Gets all defined TCA tables. 00127 * 00128 * @return array 00129 */ 00130 protected function getTcaTables() { 00131 return array_keys($GLOBALS['TCA']); 00132 } 00133 00134 /** 00135 * Gets a new instance of t3lib_TCEmain. 00136 * 00137 * @return t3lib_TCEmain 00138 */ 00139 protected function getTceMain() { 00140 $tceMain = t3lib_div::makeInstance('t3lib_TCEmain'); 00141 $tceMain->stripslashes_values = 0; 00142 return $tceMain; 00143 } 00144 00145 /** 00146 * Flushes the workspace cache for current workspace and for the virtual "all workspaces" too. 00147 * 00148 * @param integer $workspaceId The workspace to be flushed in cache 00149 * @return void 00150 */ 00151 protected function flushWorkspaceCacheEntriesByWorkspaceId($workspaceId) { 00152 if (TYPO3_UseCachingFramework === TRUE) { 00153 try { 00154 $GLOBALS['typo3CacheFactory']->create( 00155 'workspaces_cache', 00156 't3lib_cache_frontend_StringFrontend', 00157 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['backend'], 00158 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['options']); 00159 } catch (t3lib_cache_exception_DuplicateIdentifier $e) { 00160 // do nothing, a workspace cache already exists 00161 } 00162 00163 $workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache'); 00164 00165 $workspacesCache->flushByTag($workspaceId); 00166 $workspacesCache->flushByTag(tx_Workspaces_Service_Workspaces::SELECT_ALL_WORKSPACES); 00167 } 00168 } 00169 } 00170 00171 00172 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php'])) { 00173 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Tcemain.php']); 00174 } 00175 ?>
1.8.0