Feature #10439 » 10439.patch

Marco Bresch, 2011-01-16 22:26

View differences:

ext_tables.sql (working copy)
48 48
	PRIMARY KEY (uid),
49 49
	KEY parent (pid)
50 50
);
51

  
52

  
53
#
54
# Table structure for table 'sys_workspace_cache'
55
#
56
CREATE TABLE sys_workspace_cache (
57
    id int(11) unsigned NOT NULL auto_increment,
58
    identifier varchar(32) DEFAULT '' NOT NULL,
59
    content mediumblob(16777215) NOT NULL,
60
    crdate int(11) DEFAULT '0' NOT NULL,
61
    lifetime int(11) DEFAULT '0' NOT NULL,    
62
      PRIMARY KEY (id),
63
      KEY cache_id (identifier)
64
) ENGINE=InnoDB;
65

  
66

  
67
#
68
# Table structure for table 'sys_workspace_cache_tags'
69
#
70
CREATE TABLE sys_workspace_cache_tags (
71
  id int(11) unsigned NOT NULL auto_increment,
72
  identifier varchar(128) DEFAULT '' NOT NULL,
73
  tag varchar(128) DEFAULT '' NOT NULL,
74
  PRIMARY KEY (id),
75
  KEY cache_id (identifier),
76
  KEY cache_tag (tag)
77
) ENGINE=InnoDB;
Classes/Service/GridData.php (working copy)
31 31
 * @subpackage Service
32 32
 */
33 33
class tx_Workspaces_Service_GridData {
34
	protected $currentWorkspace = NULL;
34 35
	protected $dataArray = array();
35 36
	protected $sort = '';
36 37
	protected $sortDir = '';
38
	protected $workspacesCache = NULL;
37 39

  
38 40
	/**
39 41
	 * Generates grid list array from given versions.
......
41 43
	 * @param array $versions 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 pid of the online record is found as "livepid" the pid of the offline record is found in "wspid"
42 44
	 * @param object $parameter
43 45
	 * @return array
46
	 * @throws InvalidArgumentException
44 47
	 */
45
	public function generateGridListFromVersions($versions, $parameter) {
48
	public function generateGridListFromVersions($versions, $parameter, $currentWorkspace) {
46 49

  
47 50
			// Read the given parameters from grid. If the parameter is not set use default values.
48 51
		$filterTxt = isset($parameter->filterTxt) ? $parameter->filterTxt : '';
......
50 53
		$limit = isset($parameter->limit) ? intval($parameter->limit) : 10;
51 54
		$this->sort = isset($parameter->sort) ? $parameter->sort : 't3ver_oid';
52 55
		$this->sortDir = isset($parameter->dir) ? $parameter->dir : 'ASC';
56
		
57
		if (is_int($currentWorkspace)) {
58
			$this->currentWorkspace = $currentWorkspace;
59
		} else {
60
			throw new InvalidArgumentException('No such workspace defined');
61
		}
53 62

  
54 63
		$data = array();
55 64
		$data['data'] = array();
......
77 86
		$workspacesObj = t3lib_div::makeInstance('Tx_Workspaces_Service_Workspaces');
78 87
		$availableWorkspaces = $workspacesObj->getAvailableWorkspaces();
79 88

  
80
		foreach ($versions as $table => $records) {
81
			$versionArray = array('table' => $table);
89
		$this->initializeWorkspacesCachingFramework();
82 90

  
83
			foreach ($records as $record) {
84

  
85
				$origRecord = t3lib_BEFunc::getRecord($table, $record['t3ver_oid']);
86
				$versionRecord = t3lib_BEFunc::getRecord($table, $record['uid']);
87

  
88
				// check the given version is from an available workspace
89
				if (array_key_exists($versionRecord['t3ver_wsid'], $availableWorkspaces)) {
90
					
91
		// check for dataArray in cache
92
		if ($this->getDataArrayFromCache($versions, $filterTxt) == FALSE) {
93
			$stagesObj = t3lib_div::makeInstance('Tx_Workspaces_Service_Stages');
94
	
95
			foreach ($versions as $table => $records) {
96
				$versionArray = array('table' => $table);
97
	
98
				foreach ($records as $record) {
99
	
100
					$origRecord = t3lib_BEFunc::getRecord($table, $record['t3ver_oid']);
101
					$versionRecord = t3lib_BEFunc::getRecord($table, $record['uid']);
102
	
91 103
					if (isset($GLOBALS['TCA'][$table]['columns']['hidden'])) {
92 104
						$recordState = $this->workspaceState($versionRecord['t3ver_state'], $origRecord['hidden'], $versionRecord['hidden']);
93 105
					} else {
......
131 143
					}
132 144
				}
133 145
			}
146
			$this->sortDataArray();
147
			
148
			$this->setDataArrayIntoCache($versions, $filterTxt);
134 149
		}
135 150
		$this->sortDataArray();
136 151
	}
......
153 168
		return $dataArrayPart;
154 169
	}
155 170

  
171

  
172
	/**
173
	 * Initialize the workspace cache
174
	 * 
175
	 * @return void
176
	 */
177
	protected function initializeWorkspacesCachingFramework() {
178
		try {
179
			$GLOBALS['typo3CacheFactory']->create(
180
				'workspaces_cache',
181
				't3lib_cache_frontend_StringFrontend',
182
				$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['backend'],
183
				$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['options']);
184
		} catch (t3lib_cache_exception_DuplicateIdentifier $e) {
185
			// do nothing, a workspace cache already exists
186
		}
187

  
188
		$this->workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
189

  
190
	}
191

  
192

  
193
	/**
194
	 * Put the generated dataArray into the workspace cache.
195
	 * 
196
	 * @param array $versions 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 pid of the online record is found as "livepid" the pid of the offline record is found in "wspid"
197
	 * @param string $filterTxt The given filter text from the grid.
198
	 */
199
	protected function setDataArrayIntoCache (array $versions, $filterTxt) {
200
		$hash = $this->calculateHash($versions, $filterTxt);
201
		$content = serialize($this->dataArray);
202
		
203
		$this->workspacesCache->set($hash, $content, array($this->currentWorkspace));
204
	}
205
	
206
	
207
	/**
208
	 * Checks if a cache entry is given for given versions and filter text and tries to load the data array from cache.
209
	 * 
210
	 * @param array $versions 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 pid of the online record is found as "livepid" the pid of the offline record is found in "wspid"
211
	 * @param string $filterTxt The given filter text from the grid.
212
	 */
213
	protected function getDataArrayFromCache (array $versions, $filterTxt) {
214
		$cacheEntry = FALSE;
215
		
216
		$hash = $this->calculateHash($versions, $filterTxt);
217
		
218
		$content = $this->workspacesCache->get($hash);
219
		
220
		if ($content != FALSE) {
221
			$this->dataArray = unserialize($content);
222
			$cacheEntry = TRUE;
223
		}
224
		
225
		return $cacheEntry;
226
	}
227
	
228
	/**
229
	 * Calculate the hash value of the used workspace, the user id, the versions array, the filter text, the sorting attribute, the workspace selected in grid and the sorting direction.
230
	 * 
231
	 * @param array $versions 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 pid of the online record is found as "livepid" the pid of the offline record is found in "wspid"
232
	 * @param string $filterTxt The given filter text from the grid.
233
	 */
234
	protected function calculateHash (array $versions, $filterTxt) {
235
		$hashArray = array(
236
			$GLOBALS['BE_USER']->workspace,
237
			$GLOBALS['BE_USER']->user['uid'],
238
			$versions,
239
			$filterTxt,
240
			$this->sort,
241
			$this->sortDir,
242
			$this->currentWorkspace);
243
		$hash = md5(serialize($hashArray));
244
		
245
		return $hash;
246
	}
247

  
248

  
156 249
	/**
157 250
	 * Performs sorting on the data array accordant to the
158 251
	 * selected column in the grid view to be used for sorting.
Classes/Service/Tcemain.php (working copy)
56 56
	}
57 57

  
58 58
	/**
59
	 * hook that is called AFTER all commands of the commandmap was 
60
	 * executed
61
	 *
62
	 * @param t3lib_TCEmain $tcemainObj reference to the main tcemain object
63
	 * @return	void
64
	 */
65
	public function processCmdmap_afterFinish(t3lib_TCEmain $tcemainObj) {
66
		$this->flushWorkspaceCacheEntriesByWorkspaceId($tcemainObj->BE_USER->workspace);
67
	}
68

  
69
	/**
59 70
	 * In case a sys_workspace_stage record is deleted we do a hard reset
60 71
	 * for all existing records in that stage to avoid that any of these end up
61 72
	 * as orphan records.
......
129 140
		return $tceMain;
130 141
	}
131 142

  
143
	/**
144
	 * Flushes the workspace cache for current workspace and for the virtual "all workspaces" too.
145
	 * 
146
	 * @param integer $workspaceId The workspace to be flushed in cache
147
	 * @return void
148
	 */
149
	protected function flushWorkspaceCacheEntriesByWorkspaceId($workspaceId) {
150
		try {
151
			$GLOBALS['typo3CacheFactory']->create(
152
				'workspaces_cache',
153
				't3lib_cache_frontend_StringFrontend',
154
				$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['backend'],
155
				$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['options']);
156
		} catch (t3lib_cache_exception_DuplicateIdentifier $e) {
157
			// do nothing, a workspace cache already exists
158
		}
159

  
160
		$workspacesCache = $GLOBALS['typo3CacheManager']->getCache('workspaces_cache');
161

  
162
		$workspacesCache->flushByTag($workspaceId);
163
		$workspacesCache->flushByTag(tx_Workspaces_Service_Workspaces::SELECT_ALL_WORKSPACES);
164
	}
132 165
}
133 166

  
134 167

  
Classes/ExtDirect/Server.php (working copy)
45 45
		$versions = $wslibObj->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, $pageId, $parameter->depth);
46 46

  
47 47
		$workspacesService = t3lib_div::makeInstance('tx_Workspaces_Service_GridData');
48
		$data = $workspacesService->generateGridListFromVersions($versions, $parameter);
48
		$data = $workspacesService->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace());
49 49
		return $data;
50 50
	}
51 51

  
ext_localconf.php (working copy)
20 20
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']['workspaces'] = 'EXT:workspaces/Classes/Service/Tcemain.php:tx_Workspaces_Service_Befunc';
21 21
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_eofe']['workspaces'] = 'EXT:workspaces/Classes/Service/Fehooks.php:tx_Workspaces_Service_Fehooks->hook_eofe';
22 22

  
23
	// Initialize the caching framework. The caching framework is asking it self if it is initialized already before initializing.
24
t3lib_cache::initializeCachingFramework();
25

  
26
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['backend'] = 't3lib_cache_backend_DbBackend';
27
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['sys_workspace_cache']['options'] = array(
28
	'cacheTable' => 'sys_workspace_cache',
29
	'tagsTable' => 'sys_workspace_cache_tags'
30
);
31

  
32

  
23 33
?>
(1-1/4)