TYPO3 CMS  TYPO3_7-6
MassActionHandler.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
23 
29  private $pathToLocallang = 'LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf';
30 
37  public function getMassStageActions($parameter)
38  {
39  $actions = [];
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[] = ['action' => 'publish', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_publish')];
47  if ($GLOBALS['BE_USER']->workspaceSwapAccess()) {
48  $actions[] = ['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[] = ['action' => 'discard', 'title' => $GLOBALS['LANG']->sL($this->pathToLocallang . ':label_doaction_discard')];
53  }
54  }
55  $result = [
56  'total' => count($actions),
57  'data' => $actions
58  ];
59  return $result;
60  }
61 
68  public function publishWorkspace(\stdclass $parameters)
69  {
70  $result = [
71  'init' => false,
72  'total' => 0,
73  'processed' => 0,
74  'error' => false
75  ];
76  try {
77  if ($parameters->init) {
78  $language = $this->validateLanguageParameter($parameters);
79  $cnt = $this->initPublishData($this->getCurrentWorkspace(), $parameters->swap, $language);
80  $result['total'] = $cnt;
81  } else {
82  $result['processed'] = $this->processData($this->getCurrentWorkspace());
83  $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
84  }
85  } catch (\Exception $e) {
86  $result['error'] = $e->getMessage();
87  }
88  return $result;
89  }
90 
97  public function flushWorkspace(\stdclass $parameters)
98  {
99  $result = [
100  'init' => false,
101  'total' => 0,
102  'processed' => 0,
103  'error' => false
104  ];
105  try {
106  if ($parameters->init) {
107  $language = $this->validateLanguageParameter($parameters);
108  $cnt = $this->initFlushData($this->getCurrentWorkspace(), $language);
109  $result['total'] = $cnt;
110  } else {
111  $result['processed'] = $this->processData($this->getCurrentWorkspace());
112  $result['total'] = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_total');
113  }
114  } catch (\Exception $e) {
115  $result['error'] = $e->getMessage();
116  }
117  return $result;
118  }
119 
128  protected function initPublishData($workspace, $swap, $language = null)
129  {
130  // workspace might be -98 a.k.a "All Workspaces but that's save here
131  $publishData = $this->getWorkspaceService()->getCmdArrayForPublishWS($workspace, $swap, 0, $language);
132  $recordCount = 0;
133  foreach ($publishData as $table => $recs) {
134  $recordCount += count($recs);
135  }
136  if ($recordCount > 0) {
137  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $publishData);
138  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
139  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
140  }
141  return $recordCount;
142  }
143 
151  protected function initFlushData($workspace, $language = null)
152  {
153  // workspace might be -98 a.k.a "All Workspaces but that's save here
154  $flushData = $this->getWorkspaceService()->getCmdArrayForFlushWS($workspace, true, 0, $language);
155  $recordCount = 0;
156  foreach ($flushData as $table => $recs) {
157  $recordCount += count($recs);
158  }
159  if ($recordCount > 0) {
160  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $flushData);
161  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', $recordCount);
162  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', 0);
163  }
164  return $recordCount;
165  }
166 
173  protected function processData($workspace)
174  {
175  $processData = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction');
176  $recordsProcessed = $GLOBALS['BE_USER']->getSessionData('workspaceMassAction_processed');
177  $limitedCmd = [];
178  $numRecs = 0;
179  foreach ($processData as $table => $recs) {
180  foreach ($recs as $key => $value) {
181  $numRecs++;
182  $limitedCmd[$table][$key] = $value;
183  if ($numRecs == self::MAX_RECORDS_TO_PROCESS) {
184  break;
185  }
186  }
187  if ($numRecs == self::MAX_RECORDS_TO_PROCESS) {
188  break;
189  }
190  }
191  if ($numRecs == 0) {
192  // All done
193  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', null);
194  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_total', 0);
195  } else {
197  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
198  $tce->stripslashes_values = 0;
199  // Execute the commands:
200  $tce->start([], $limitedCmd);
201  $tce->process_cmdmap();
202  $errors = $tce->errorLog;
203  if (!empty($errors)) {
204  throw new \Exception(implode(', ', $errors));
205  }
206  // Unset processed records
207  foreach ($limitedCmd as $table => $recs) {
208  foreach ($recs as $key => $value) {
209  $recordsProcessed++;
210  unset($processData[$table][$key]);
211  }
212  }
213  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction', $processData);
214  $GLOBALS['BE_USER']->setAndSaveSessionData('workspaceMassAction_processed', $recordsProcessed);
215  }
216  return $recordsProcessed;
217  }
218 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
initPublishData($workspace, $swap, $language=null)