TYPO3 CMS  TYPO3_6-2
MassActionHandler.php
Go to the documentation of this file.
1 <?php
3 
23 
30  private $pathToLocallang = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf';
31 
38  public function getMassStageActions($parameter) {
39  $actions = array();
40  $currentWorkspace = $this->getCurrentWorkspace();
41  $massActionsEnabled = $GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.enableMassActions') !== '0';
42  // in case we're working within "All Workspaces" we can't provide Mass Actions
43  if ($currentWorkspace != \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES && $massActionsEnabled) {
44  $publishAccess = $GLOBALS['BE_USER']->workspacePublishAccess($currentWorkspace);
45  if ($publishAccess && !($GLOBALS['BE_USER']->workspaceRec['publish_access'] & 1)) {
46  $actions[] = array('action' => 'publish', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_publish'));
47  if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
48  $actions[] = array('action' => 'swap', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_swap'));
49  }
50  }
51  if ($currentWorkspace !== \TYPO3\CMS\Workspaces\Service\WorkspaceService::LIVE_WORKSPACE_ID) {
52  $actions[] = array('action' => 'discard', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_discard'));
53  }
54  }
55  $result = array(
56  'total' => count($actions),
57  'data' => $actions
58  );
59  return $result;
60  }
61 
68  public function publishWorkspace(\stdclass $parameters) {
69  $result = array(
70  'init' => FALSE,
71  'total' => 0,
72  'processed' => 0,
73  'error' => FALSE
74  );
75  try {
76  if ($parameters->init) {
77  $language = $this->validateLanguageParameter($parameters);
78  $cnt = $this->initPublishData($this->getCurrentWorkspace(), $parameters->swap, $language);
79  $result['total'] = $cnt;
80  } else {
81  $result['processed'] = $this->processData($this->getCurrentWorkspace());
82  $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
83  }
84  } catch (\Exception $e) {
85  $result['error'] = $e->getMessage();
86  }
87  return $result;
88  }
89 
96  public function flushWorkspace(\stdclass $parameters) {
97  $result = array(
98  'init' => FALSE,
99  'total' => 0,
100  'processed' => 0,
101  'error' => FALSE
102  );
103  try {
104  if ($parameters->init) {
105  $language = $this->validateLanguageParameter($parameters);
106  $cnt = $this->initFlushData($this->getCurrentWorkspace(), $language);
107  $result['total'] = $cnt;
108  } else {
109  $result['processed'] = $this->processData($this->getCurrentWorkspace());
110  $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
111  }
112  } catch (\Exception $e) {
113  $result['error'] = $e->getMessage();
114  }
115  return $result;
116  }
117 
126  protected function initPublishData($workspace, $swap, $language = NULL) {
127  // workspace might be -98 a.k.a "All Workspaces but that's save here
128  $publishData = $this->getWorkspaceService()->getCmdArrayForPublishWS($workspace, $swap, 0, $language);
129  $recordCount = 0;
130  foreach ($publishData as $table => $recs) {
131  $recordCount += count($recs);
132  }
133  if ($recordCount > 0) {
134  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $publishData);
135  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
136  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
137  }
138  return $recordCount;
139  }
140 
148  protected function initFlushData($workspace, $language = NULL) {
149  // workspace might be -98 a.k.a "All Workspaces but that's save here
150  $flushData = $this->getWorkspaceService()->getCmdArrayForFlushWS($workspace, TRUE, 0, $language);
151  $recordCount = 0;
152  foreach ($flushData as $table => $recs) {
153  $recordCount += count($recs);
154  }
155  if ($recordCount > 0) {
156  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $flushData);
157  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
158  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
159  }
160  return $recordCount;
161  }
162 
169  protected function processData($workspace) {
170  $processData = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction');
171  $recordsProcessed = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_processed');
172  $limitedCmd = array();
173  $numRecs = 0;
174  foreach ($processData as $table => $recs) {
175  foreach ($recs as $key => $value) {
176  $numRecs++;
177  $limitedCmd[$table][$key] = $value;
178  if ($numRecs == self::MAX_RECORDS_TO_PROCESS) {
179  break;
180  }
181  }
182  if ($numRecs == self::MAX_RECORDS_TO_PROCESS) {
183  break;
184  }
185  }
186  if ($numRecs == 0) {
187  // All done
188  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', NULL);
189  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', 0);
190  } else {
192  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
193  $tce->stripslashes_values = 0;
194  // Execute the commands:
195  $tce->start(array(), $limitedCmd);
196  $tce->process_cmdmap();
197  $errors = $tce->errorLog;
198  if (count($errors) > 0) {
199  throw new \Exception(implode(', ', $errors));
200  } else {
201  // Unset processed records
202  foreach ($limitedCmd as $table => $recs) {
203  foreach ($recs as $key => $value) {
204  $recordsProcessed++;
205  unset($processData[$table][$key]);
206  }
207  }
208  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $processData);
209  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', $recordsProcessed);
210  }
211  }
212  return $recordsProcessed;
213  }
214 
215 }
$parameters
Definition: FileDumpEID.php:15
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
initPublishData($workspace, $swap, $language=NULL)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]