[TASK] Remove legacy handling of new content element wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Controller / ClearPageCacheController.php
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
18 namespace TYPO3\CMS\Recordlist\Controller;
19
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
24 use TYPO3\CMS\Core\DataHandling\DataHandler;
25 use TYPO3\CMS\Core\Http\JsonResponse;
26 use TYPO3\CMS\Core\Localization\LanguageService;
27 use TYPO3\CMS\Core\Type\Bitmask\Permission;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30 /**
31 * Class ClearPageCacheController
32 *
33 * Allows to clear the page cache of a given page uid
34 */
35 class ClearPageCacheController
36 {
37 /**
38 * @var DataHandler
39 */
40 protected $dataHandler;
41
42 /**
43 * ClearPageCacheController constructor.
44 */
45 public function __construct()
46 {
47 $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class);
48 }
49
50 /**
51 * Clear page cache
52 *
53 * @param ServerRequestInterface $request
54 * @return ResponseInterface
55 */
56 public function mainAction(ServerRequestInterface $request): ResponseInterface
57 {
58 $parsedBody = $request->getParsedBody();
59 $queryParams = $request->getQueryParams();
60 $pageUid = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0);
61 $message = $this->getLanguageService()->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:clearcache.message.error');
62 $success = false;
63 $permissionClause = $this->getBackendUserAuthentication()->getPagePermsClause(Permission::PAGE_SHOW);
64 $pageRow = BackendUtility::readPageAccess($pageUid, $permissionClause);
65 if ($pageUid !== 0 && $this->getBackendUserAuthentication()->doesUserHaveAccess($pageRow, Permission::PAGE_SHOW)) {
66 $this->dataHandler->start([], []);
67 $this->dataHandler->clear_cacheCmd($pageUid);
68 $message = $this->getLanguageService()->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:clearcache.message.success');
69 $success = true;
70 }
71 return new JsonResponse([
72 'success' => $success,
73 'title' => $this->getLanguageService()->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:clearcache.title'),
74 'message' => $message
75 ]);
76 }
77
78 /**
79 * @return BackendUserAuthentication
80 */
81 protected function getBackendUserAuthentication(): BackendUserAuthentication
82 {
83 return $GLOBALS['BE_USER'];
84 }
85
86 /**
87 * Returns LanguageService
88 *
89 * @return \TYPO3\CMS\Core\Localization\LanguageService
90 */
91 protected function getLanguageService(): LanguageService
92 {
93 return $GLOBALS['LANG'];
94 }
95 }