‪TYPO3CMS  10.4
SimpleDataHandlerController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
33 
43 {
49  protected ‪$flags;
50 
56  protected ‪$data;
57 
64  protected ‪$cmd;
65 
71  protected ‪$mirror;
72 
78  protected ‪$cacheCmd;
79 
85  protected ‪$redirect;
86 
92  protected ‪$CB;
93 
99  protected ‪$tce;
100 
108  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
109  {
110  ‪$GLOBALS['SOBE'] = $this;
111  $this->‪init($request);
112 
113  $this->‪initializeClipboard();
114  $this->‪processRequest();
115 
116  // Write errors to flash message queue
117  $this->tce->printLogErrorMessages();
118  if ($this->redirect) {
119  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($this->redirect), 303);
120  }
121  return new ‪HtmlResponse('');
122  }
123 
130  public function ‪processAjaxRequest(ServerRequestInterface $request): ResponseInterface
131  {
132  ‪$GLOBALS['SOBE'] = $this;
133  $this->‪init($request);
134 
135  // do the regular / main logic
136  $this->‪initializeClipboard();
137  $this->‪processRequest();
138 
140  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
141 
142  $content = [
143  'redirect' => ‪$this->redirect,
144  'messages' => [],
145  'hasErrors' => false
146  ];
147 
148  // Prints errors (= write them to the message queue)
149  $this->tce->printLogErrorMessages();
150 
151  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
152  if (!empty($messages)) {
153  foreach ($messages as $message) {
154  $content['messages'][] = [
155  'title' => $message->getTitle(),
156  'message' => $message->getMessage(),
157  'severity' => $message->getSeverity()
158  ];
159  if ($message->getSeverity() === ‪AbstractMessage::ERROR) {
160  $content['hasErrors'] = true;
161  }
162  }
163  }
164  return new ‪JsonResponse($content);
165  }
166 
172  protected function ‪init(ServerRequestInterface $request): void
173  {
174  $beUser = $this->‪getBackendUser();
175 
176  $parsedBody = $request->getParsedBody();
177  $queryParams = $request->getQueryParams();
178 
179  // GPvars:
180  $this->flags = $parsedBody['flags'] ?? $queryParams['flags'] ?? null;
181  $this->data = $parsedBody['data'] ?? $queryParams['data'] ?? null;
182  $this->cmd = $parsedBody['cmd'] ?? $queryParams['cmd'] ?? null;
183  $this->mirror = $parsedBody['mirror'] ?? $queryParams['mirror'] ?? null;
184  $this->cacheCmd = $parsedBody['cacheCmd'] ?? $queryParams['cacheCmd'] ?? null;
185  ‪$redirect = $parsedBody['redirect'] ?? $queryParams['redirect'] ?? '';
186  $this->redirect = GeneralUtility::sanitizeLocalUrl(‪$redirect);
187  $this->CB = $parsedBody['CB'] ?? $queryParams['CB'] ?? null;
188  // Creating DataHandler object
189  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
190  // Configuring based on user prefs.
191  if ($beUser->uc['recursiveDelete']) {
192  // TRUE if the delete Recursive flag is set.
193  $this->tce->deleteTree = 1;
194  }
195  if ($beUser->uc['copyLevels']) {
196  // Set to number of page-levels to copy.
197  $this->tce->copyTree = ‪MathUtility::forceIntegerInRange($beUser->uc['copyLevels'], 0, 100);
198  }
199  if ($beUser->uc['neverHideAtCopy']) {
200  $this->tce->neverHideAtCopy = 1;
201  }
202  // Reverse order.
203  if ($this->flags['reverseOrder']) {
204  $this->tce->reverseOrder = 1;
205  }
206  }
207 
211  protected function ‪initializeClipboard(): void
212  {
213  if (is_array($this->CB)) {
214  $clipObj = GeneralUtility::makeInstance(Clipboard::class);
215  $clipObj->initializeClipboard();
216  if ($this->CB['paste']) {
217  $clipObj->setCurrentPad($this->CB['pad']);
218  $this->cmd = $clipObj->makePasteCmdArray(
219  $this->CB['paste'],
220  $this->cmd,
221  $this->CB['update'] ?? null
222  );
223  }
224  if ($this->CB['delete']) {
225  $clipObj->setCurrentPad($this->CB['pad']);
226  $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
227  }
228  }
229  }
230 
234  protected function ‪processRequest(): void
235  {
236  // LOAD DataHandler with data and cmd arrays:
237  $this->tce->start($this->data, $this->cmd);
238  if (is_array($this->mirror)) {
239  $this->tce->setMirror($this->mirror);
240  }
241  // Execute actions:
242  $this->tce->process_datamap();
243  $this->tce->process_cmdmap();
244  // Clearing cache:
245  if (!empty($this->cacheCmd)) {
246  $this->tce->clear_cacheCmd($this->cacheCmd);
247  }
248  // Update page tree?
249  if (isset($this->data['pages']) || isset($this->cmd['pages'])) {
250  ‪BackendUtility::setUpdateSignal('updatePageTree');
251  }
252  }
253 
259  protected function ‪getBackendUser(): ‪BackendUserAuthentication
260  {
261  return ‪$GLOBALS['BE_USER'];
262  }
263 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$data
‪array $data
Definition: SimpleDataHandlerController.php:54
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:43
‪TYPO3\CMS\Backend\Utility\BackendUtility\setUpdateSignal
‪static setUpdateSignal($set='', $params='')
Definition: BackendUtility.php:2798
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$cmd
‪array $cmd
Definition: SimpleDataHandlerController.php:61
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: SimpleDataHandlerController.php:100
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$cacheCmd
‪string $cacheCmd
Definition: SimpleDataHandlerController.php:73
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$redirect
‪string $redirect
Definition: SimpleDataHandlerController.php:79
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\init
‪init(ServerRequestInterface $request)
Definition: SimpleDataHandlerController.php:164
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$flags
‪array $flags
Definition: SimpleDataHandlerController.php:48
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\processAjaxRequest
‪ResponseInterface processAjaxRequest(ServerRequestInterface $request)
Definition: SimpleDataHandlerController.php:122
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController
Definition: SimpleDataHandlerController.php:43
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$tce
‪TYPO3 CMS Core DataHandling DataHandler $tce
Definition: SimpleDataHandlerController.php:91
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: SimpleDataHandlerController.php:251
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\initializeClipboard
‪initializeClipboard()
Definition: SimpleDataHandlerController.php:203
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\processRequest
‪processRequest()
Definition: SimpleDataHandlerController.php:226
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:26
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$mirror
‪array $mirror
Definition: SimpleDataHandlerController.php:67
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$CB
‪array $CB
Definition: SimpleDataHandlerController.php:85