TYPO3 CMS  TYPO3_8-7
SimpleDataHandlerController.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 
26 
36 {
42  public $flags;
43 
49  public $data;
50 
57  public $cmd;
58 
64  public $mirror;
65 
71  public $cacheCmd;
72 
78  public $redirect;
79 
85  public $prErr;
86 
92  public $CB;
93 
99  public $uPT;
100 
106  public $tce;
107 
111  public function __construct()
112  {
113  $GLOBALS['SOBE'] = $this;
114  $this->init();
115  }
116 
120  public function init()
121  {
122  $beUser = $this->getBackendUser();
123  // GPvars:
124  $this->flags = GeneralUtility::_GP('flags');
125  $this->data = GeneralUtility::_GP('data');
126  $this->cmd = GeneralUtility::_GP('cmd');
127  $this->mirror = GeneralUtility::_GP('mirror');
128  $this->cacheCmd = GeneralUtility::_GP('cacheCmd');
129  $this->redirect = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('redirect'));
130  $this->prErr = GeneralUtility::_GP('prErr');
131  $this->CB = GeneralUtility::_GP('CB');
132  $this->uPT = GeneralUtility::_GP('uPT');
133  // Creating DataHandler object
134  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
135  // Configuring based on user prefs.
136  if ($beUser->uc['recursiveDelete']) {
137  // TRUE if the delete Recursive flag is set.
138  $this->tce->deleteTree = 1;
139  }
140  if ($beUser->uc['copyLevels']) {
141  // Set to number of page-levels to copy.
142  $this->tce->copyTree = MathUtility::forceIntegerInRange($beUser->uc['copyLevels'], 0, 100);
143  }
144  if ($beUser->uc['neverHideAtCopy']) {
145  $this->tce->neverHideAtCopy = 1;
146  }
147  $TCAdefaultOverride = $beUser->getTSConfigProp('TCAdefaults');
148  if (is_array($TCAdefaultOverride)) {
149  $this->tce->setDefaultsFromUserTS($TCAdefaultOverride);
150  }
151  // Reverse order.
152  if ($this->flags['reverseOrder']) {
153  $this->tce->reverseOrder = 1;
154  }
155  }
156 
160  public function initClipboard()
161  {
162  if (is_array($this->CB)) {
163  $clipObj = GeneralUtility::makeInstance(Clipboard::class);
164  $clipObj->initializeClipboard();
165  if ($this->CB['paste']) {
166  $clipObj->setCurrentPad($this->CB['pad']);
167  $this->cmd = $clipObj->makePasteCmdArray(
168  $this->CB['paste'],
169  $this->cmd,
170  isset($this->CB['update']) ? $this->CB['update'] : null
171  );
172  }
173  if ($this->CB['delete']) {
174  $clipObj->setCurrentPad($this->CB['pad']);
175  $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
176  }
177  }
178  }
179 
183  public function main()
184  {
185  // LOAD DataHandler with data and cmd arrays:
186  $this->tce->start($this->data, $this->cmd);
187  if (is_array($this->mirror)) {
188  $this->tce->setMirror($this->mirror);
189  }
190  // Register uploaded files
191  $this->tce->process_uploads($_FILES);
192  // Execute actions:
193  $this->tce->process_datamap();
194  $this->tce->process_cmdmap();
195  // Clearing cache:
196  if (!empty($this->cacheCmd)) {
197  $this->tce->clear_cacheCmd($this->cacheCmd);
198  }
199  // Update page tree?
200  if ($this->uPT && (isset($this->data['pages']) || isset($this->cmd['pages']))) {
201  BackendUtility::setUpdateSignal('updatePageTree');
202  }
203  }
204 
213  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
214  {
215  $this->initClipboard();
216  $this->main();
217 
218  // Write errors to flash message queue (if not explicitly disabled)
219  if ($this->prErr || $this->prErr === null) {
220  $this->tce->printLogErrorMessages();
221  }
222  if ($this->redirect) {
223  $response = $response
224  ->withHeader('Location', GeneralUtility::locationHeaderUrl($this->redirect))
225  ->withStatus(303);
226  }
227  return $response;
228  }
229 
237  public function processAjaxRequest(ServerRequestInterface $request, ResponseInterface $response)
238  {
239  // do the regular / main logic
240  $this->initClipboard();
241  $this->main();
242 
244  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
245 
246  $content = [
247  'redirect' => $this->redirect,
248  'messages' => [],
249  'hasErrors' => false
250  ];
251 
252  // Prints errors (= write them to the message queue, if not explicitly disabled)
253  if ($this->prErr || $this->prErr === null) {
254  $content['hasErrors'] = !empty($this->tce->errorLog);
255  $this->tce->printLogErrorMessages();
256  }
257 
258  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
259  if (!empty($messages)) {
260  foreach ($messages as $message) {
261  $content['messages'][] = [
262  'title' => $message->getTitle(),
263  'message' => $message->getMessage(),
264  'severity' => $message->getSeverity()
265  ];
266  if ($message->getSeverity() === AbstractMessage::ERROR) {
267  $content['hasErrors'] = true;
268  }
269  }
270  }
271 
272  $response->getBody()->write(json_encode($content));
273  return $response;
274  }
275 
281  protected function getBackendUser()
282  {
283  return $GLOBALS['BE_USER'];
284  }
285 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
mainAction(ServerRequestInterface $request, ResponseInterface $response)
static makeInstance($className,... $constructorArguments)
static setUpdateSignal($set='', $params='')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']