‪TYPO3CMS  9.5
SimpleDataHandlerController.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
32 
42 {
44 
50  protected ‪$deprecatedPublicProperties = [
51  'flags' => 'Using $flags of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
52  'data' => 'Using $data of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
53  'cmd' => 'Using $cmd of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
54  'mirror' => 'Using $mirror of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
55  'cacheCmd' => 'Using $cacheCmd of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
56  'redirect' => 'Using $redirect of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
57  'CB' => 'Using $CB of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
58  'tce' => 'Using $tce of class SimpleDataHandlerController from the outside is discouraged, as this variable is only used for internal storage.',
59  ];
60 
66  protected ‪$flags;
67 
73  protected ‪$data;
74 
81  protected ‪$cmd;
82 
88  protected ‪$mirror;
89 
95  protected ‪$cacheCmd;
96 
102  protected ‪$redirect;
103 
109  protected ‪$CB;
110 
116  protected ‪$tce;
117 
121  public function ‪__construct()
122  {
123  // @deprecated since TYPO3 v9, will be obsolete in TYPO3 v10.0 with removal of init()
124  $request = ‪$GLOBALS['TYPO3_REQUEST'];
125  ‪$GLOBALS['SOBE'] = $this;
126  // @deprecated since TYPO3 v9, will be moved out of __construct() in TYPO3 v10.0
127  $this->‪init($request);
128  }
129 
137  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
138  {
139  $this->‪initializeClipboard();
140  $this->‪processRequest();
141 
142  // Write errors to flash message queue
143  $this->tce->printLogErrorMessages();
144  if ($this->redirect) {
145  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($this->redirect), 303);
146  }
147  return new ‪HtmlResponse('');
148  }
149 
156  public function ‪processAjaxRequest(ServerRequestInterface $request): ResponseInterface
157  {
158  // do the regular / main logic
159  $this->‪initializeClipboard();
160  $this->‪processRequest();
161 
163  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
164 
165  $content = [
166  'redirect' => ‪$this->redirect,
167  'messages' => [],
168  'hasErrors' => false
169  ];
170 
171  // Prints errors (= write them to the message queue)
172  $this->tce->printLogErrorMessages();
173 
174  $messages = $flashMessageService->getMessageQueueByIdentifier()->getAllMessagesAndFlush();
175  if (!empty($messages)) {
176  foreach ($messages as $message) {
177  $content['messages'][] = [
178  'title' => $message->getTitle(),
179  'message' => $message->getMessage(),
180  'severity' => $message->getSeverity()
181  ];
182  if ($message->getSeverity() === ‪AbstractMessage::ERROR) {
183  $content['hasErrors'] = true;
184  }
185  }
186  }
187  return new JsonResponse($content);
188  }
189 
195  public function ‪init(ServerRequestInterface $request = null): void
196  {
197  if ($request === null) {
198  // Method signature in TYPO3 v10.0: protected function init(ServerRequestInterface $request)
199  trigger_error('SimpleDataHandlerController->init() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
200  $request = ‪$GLOBALS['TYPO3_REQUEST'];
201  }
202 
203  $beUser = $this->‪getBackendUser();
204 
205  $parsedBody = $request->getParsedBody();
206  $queryParams = $request->getQueryParams();
207 
208  // GPvars:
209  $this->flags = $parsedBody['flags'] ?? $queryParams['flags'] ?? null;
210  $this->data = $parsedBody['data'] ?? $queryParams['data'] ?? null;
211  $this->cmd = $parsedBody['cmd'] ?? $queryParams['cmd'] ?? null;
212  $this->mirror = $parsedBody['mirror'] ?? $queryParams['mirror'] ?? null;
213  $this->cacheCmd = $parsedBody['cacheCmd'] ?? $queryParams['cacheCmd'] ?? null;
214  ‪$redirect = $parsedBody['redirect'] ?? $queryParams['redirect'] ?? '';
215  $this->redirect = GeneralUtility::sanitizeLocalUrl(‪$redirect);
216  $this->CB = $parsedBody['CB'] ?? $queryParams['CB'] ?? null;
217  // Creating DataHandler object
218  $this->tce = GeneralUtility::makeInstance(DataHandler::class);
219  // Configuring based on user prefs.
220  if ($beUser->uc['recursiveDelete']) {
221  // TRUE if the delete Recursive flag is set.
222  $this->tce->deleteTree = 1;
223  }
224  if ($beUser->uc['copyLevels']) {
225  // Set to number of page-levels to copy.
226  $this->tce->copyTree = ‪MathUtility::forceIntegerInRange($beUser->uc['copyLevels'], 0, 100);
227  }
228  if ($beUser->uc['neverHideAtCopy']) {
229  $this->tce->neverHideAtCopy = 1;
230  }
231  // Reverse order.
232  if ($this->flags['reverseOrder']) {
233  $this->tce->reverseOrder = 1;
234  }
235  }
236 
242  public function ‪initClipboard()
243  {
244  trigger_error('SimpleDataHandlerController->initClipboard() will be replaced by protected method initializeClipboard() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
245  $this->‪initializeClipboard();
246  }
247 
253  public function ‪main()
254  {
255  trigger_error('SimpleDataHandlerController->main() will be replaced by protected method processRequest() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
256  $this->‪processRequest();
257  }
258 
262  protected function ‪initializeClipboard(): void
263  {
264  if (is_array($this->CB)) {
265  $clipObj = GeneralUtility::makeInstance(Clipboard::class);
266  $clipObj->initializeClipboard();
267  if ($this->CB['paste']) {
268  $clipObj->setCurrentPad($this->CB['pad']);
269  $this->cmd = $clipObj->makePasteCmdArray(
270  $this->CB['paste'],
271  $this->cmd,
272  $this->CB['update'] ?? null
273  );
274  }
275  if ($this->CB['delete']) {
276  $clipObj->setCurrentPad($this->CB['pad']);
277  $this->cmd = $clipObj->makeDeleteCmdArray($this->cmd);
278  }
279  }
280  }
281 
285  protected function ‪processRequest(): void
286  {
287  // LOAD DataHandler with data and cmd arrays:
288  $this->tce->start($this->data, $this->cmd);
289  if (is_array($this->mirror)) {
290  $this->tce->setMirror($this->mirror);
291  }
292  // Register uploaded files
293  $this->tce->process_uploads($_FILES);
294  // Execute actions:
295  $this->tce->process_datamap();
296  $this->tce->process_cmdmap();
297  // Clearing cache:
298  if (!empty($this->cacheCmd)) {
299  $this->tce->clear_cacheCmd($this->cacheCmd);
300  }
301  // Update page tree?
302  if (isset($this->data['pages']) || isset($this->cmd['pages'])) {
303  ‪BackendUtility::setUpdateSignal('updatePageTree');
304  }
305  }
306 
312  protected function ‪getBackendUser(): ‪BackendUserAuthentication
313  {
314  return ‪$GLOBALS['BE_USER'];
315  }
316 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$data
‪array $data
Definition: SimpleDataHandlerController.php:69
‪TYPO3\CMS\Core\Messaging\AbstractMessage
Definition: AbstractMessage.php:24
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$deprecatedPublicProperties
‪array $deprecatedPublicProperties
Definition: SimpleDataHandlerController.php:48
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:38
‪TYPO3\CMS\Backend\Utility\BackendUtility\setUpdateSignal
‪static setUpdateSignal($set='', $params='')
Definition: BackendUtility.php:3164
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$cmd
‪array $cmd
Definition: SimpleDataHandlerController.php:76
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: SimpleDataHandlerController.php:127
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$cacheCmd
‪string $cacheCmd
Definition: SimpleDataHandlerController.php:88
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\__construct
‪__construct()
Definition: SimpleDataHandlerController.php:111
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\init
‪init(ServerRequestInterface $request=null)
Definition: SimpleDataHandlerController.php:185
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$redirect
‪string $redirect
Definition: SimpleDataHandlerController.php:94
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\initClipboard
‪initClipboard()
Definition: SimpleDataHandlerController.php:232
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\main
‪main()
Definition: SimpleDataHandlerController.php:243
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$flags
‪array $flags
Definition: SimpleDataHandlerController.php:63
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\processAjaxRequest
‪ResponseInterface processAjaxRequest(ServerRequestInterface $request)
Definition: SimpleDataHandlerController.php:146
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController
Definition: SimpleDataHandlerController.php:42
‪$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:106
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: SimpleDataHandlerController.php:302
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait
Definition: PublicPropertyDeprecationTrait.php:66
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\initializeClipboard
‪initializeClipboard()
Definition: SimpleDataHandlerController.php:252
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\processRequest
‪processRequest()
Definition: SimpleDataHandlerController.php:275
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Core\Http\HtmlResponse
Definition: HtmlResponse.php:25
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$mirror
‪array $mirror
Definition: SimpleDataHandlerController.php:82
‪TYPO3\CMS\Backend\Controller\SimpleDataHandlerController\$CB
‪array $CB
Definition: SimpleDataHandlerController.php:100