13e7c0f64e6a7e496199753b3d7c1d543d38634b
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / BackendModuleController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install\Controller;
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;
20 use TYPO3\CMS\Core\Http\RedirectResponse;
21 use TYPO3\CMS\Install\Service\SessionService;
22
23 /**
24 * Backend module controller to the install tool. Sets an install tool session
25 * marked as "initialized by a valid system administrator backend user" and
26 * redirects to the install tool entry point.
27 *
28 * This is a classic backend module that does not interfere with other code
29 * within the install tool, it can be seen as a facade around install tool just
30 * to embed the install tool in backend.
31 */
32 class BackendModuleController
33 {
34 /**
35 * Initialize session and redirect to "maintenance"
36 *
37 * @param ServerRequestInterface $request
38 * @param ResponseInterface $response
39 * @return ResponseInterface
40 */
41 public function maintenanceAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
42 {
43 return $this->setAuthorizedAndRedirect('maintenance');
44 }
45
46 /**
47 * Initialize session and redirect to "settings"
48 *
49 * @param ServerRequestInterface $request
50 * @param ResponseInterface $response
51 * @return ResponseInterface
52 */
53 public function settingsAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
54 {
55 return $this->setAuthorizedAndRedirect('settings');
56 }
57
58 /**
59 * Initialize session and redirect to "upgrade"
60 *
61 * @param ServerRequestInterface $request
62 * @param ResponseInterface $response
63 * @return ResponseInterface
64 */
65 public function upgradeAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
66 {
67 return $this->setAuthorizedAndRedirect('upgrade');
68 }
69
70 /**
71 * Initialize session and redirect to "environment"
72 *
73 * @param ServerRequestInterface $request
74 * @param ResponseInterface $response
75 * @return ResponseInterface
76 */
77 public function environmentAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
78 {
79 return $this->setAuthorizedAndRedirect('environment');
80 }
81
82 /**
83 * Starts / updates the session and redirects to the install tool
84 * with given action.
85 *
86 * @param $controller
87 * @return ResponseInterface
88 */
89 protected function setAuthorizedAndRedirect(string $controller): ResponseInterface
90 {
91 $sessionService = new SessionService();
92 $sessionService->setAuthorizedBackendSession();
93 $redirectLocation = 'install.php?install[controller]=' . $controller . '&install[context]=backend';
94 return new RedirectResponse($redirectLocation, 303);
95 }
96 }