2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
30 * Class encapsulates all actions which are triggered for all elements within the current workspace.
32 * @author Kasper Skårhøj (kasperYYYY@typo3.com)
33 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
35 * @subpackage ExtDirect
37 class tx_Workspaces_ExtDirect_MassActionHandler
extends tx_Workspaces_ExtDirect_AbstractHandler
{
38 const MAX_RECORDS_TO_PROCESS
= 30;
41 * Path to the locallang file
44 private $pathToLocallang = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xml';
47 * Get list of available mass workspace actions.
49 * @param object $parameter
52 public function getMassStageActions($parameter) {
54 $currentWorkspace = $this->getCurrentWorkspace();
56 // in case we're working within "All Workspaces" we can't provide Mass Actions
57 if ($currentWorkspace != tx_Workspaces_Service_Workspaces
::SELECT_ALL_WORKSPACES
) {
58 $publishAccess = $GLOBALS['BE_USER']->workspacePublishAccess($currentWorkspace);
59 if ($publishAccess && !($GLOBALS['BE_USER']->workspaceRec
['publish_access'] & 1)) {
60 $actions[] = array('action' => 'publish', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang
. ':label_doaction_publish')
62 if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
63 $actions[] = array('action' => 'swap', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang
. ':label_doaction_swap')
68 if ($currentWorkspace !== tx_Workspaces_Service_Workspaces
::LIVE_WORKSPACE_ID
) {
69 $actions[] = array('action' => 'discard', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang
. ':label_doaction_discard')
75 'total' => count($actions),
82 * Publishes the current workspace.
84 * @param stdclass $parameters
87 public function publishWorkspace(stdclass
$parameters) {
96 if ($parameters->init
) {
97 $cnt = $this->initPublishData($this->getCurrentWorkspace(), $parameters->swap
);
98 $result['total'] = $cnt;
100 $result['processed'] = $this->processData($this->getCurrentWorkspace());
101 $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
103 } catch (Exception
$e) {
104 $result['error'] = $e->getMessage();
110 * Flushes the current workspace.
112 * @param stdclass $parameters
115 public function flushWorkspace(stdclass
$parameters) {
124 if ($parameters->init
) {
125 $cnt = $this->initFlushData($this->getCurrentWorkspace());
126 $result['total'] = $cnt;
128 $result['processed'] = $this->processData($this->getCurrentWorkspace());
129 $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
131 } catch (Exception
$e) {
132 $result['error'] = $e->getMessage();
138 * Initializes the command map to be used for publishing.
140 * @param integer $workspace
141 * @param boolean $swap
144 protected function initPublishData($workspace, $swap) {
145 $workspaceService = t3lib_div
::makeInstance('tx_Workspaces_Service_Workspaces');
146 // workspace might be -98 a.k.a "All Workspaces but that's save here
147 $publishData = $workspaceService->getCmdArrayForPublishWS($workspace, $swap);
149 foreach ($publishData as $table => $recs) {
150 $recordCount +
= count($recs);
152 if ($recordCount > 0) {
153 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $publishData);
154 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
155 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
161 * Initializes the command map to be used for flushing.
163 * @param integer $workspace
166 protected function initFlushData($workspace) {
167 $workspaceService = t3lib_div
::makeInstance('tx_Workspaces_Service_Workspaces');
168 // workspace might be -98 a.k.a "All Workspaces but that's save here
169 $flushData = $workspaceService->getCmdArrayForFlushWS($workspace);
171 foreach ($flushData as $table => $recs) {
172 $recordCount +
= count($recs);
174 if ($recordCount > 0) {
175 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $flushData);
176 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
177 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
183 * Processes the data.
185 * @param integer $workspace
188 protected function processData($workspace) {
189 $processData = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction');
190 $recordsProcessed = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_processed');
191 $limitedCmd = array();
194 foreach ($processData as $table => $recs) {
195 foreach ($recs as $key => $value) {
197 $limitedCmd[$table][$key] = $value;
198 if ($numRecs == self
::MAX_RECORDS_TO_PROCESS
) {
202 if ($numRecs == self
::MAX_RECORDS_TO_PROCESS
) {
209 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', null);
210 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', 0);
212 // Execute the commands:
213 $tce = t3lib_div
::makeInstance('t3lib_TCEmain');
214 $tce->stripslashes_values
= 0;
215 $tce->start(array(), $limitedCmd);
216 $tce->process_cmdmap();
218 $errors = $tce->errorLog
;
219 if (count($errors) > 0) {
220 throw new Exception(implode(', ', $errors));
222 // Unset processed records
223 foreach ($limitedCmd as $table => $recs) {
224 foreach ($recs as $key => $value) {
226 unset($processData[$table][$key]);
229 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $processData);
230 $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', $recordsProcessed);
234 return $recordsProcessed;
239 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/ExtDirect/MassActionHandler.php'])) {
240 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['ext/workspaces/Classes/ExtDirect/MassActionHandler.php']);