[TASK] Refactor install tool enable file checks
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / BackendModuleController.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Backend module controller
32 *
33 * Embeds in backend an only shows the 'enable install tool button' or redirects
34 * to step installer if install tool is enabled.
35 *
36 * This is a classic extbase module that does not interfere with the other code
37 * within the install tool.
38 */
39 class BackendModuleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
40
41 /**
42 * @var \TYPO3\CMS\Install\Service\EnableFileService
43 * @inject
44 */
45 protected $enableFileService;
46
47 /**
48 * @var \TYPO3\CMS\Core\FormProtection\AbstractFormProtection
49 */
50 protected $formProtection;
51
52 /**
53 * Set formprotection property
54 */
55 public function initializeAction() {
56 $this->formProtection = \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get();
57 }
58
59 /**
60 * Index action shows install tool / step installer or redirect to action to enable install tool
61 *
62 * @return void
63 */
64 public function indexAction() {
65 if ($this->enableFileService->checkInstallToolEnableFile()) {
66 $this->redirect('sysext/install/Start/Install.php?install[context]=backend');
67 } else {
68 $this->forward('showEnableInstallToolButton');
69 }
70 }
71
72 /**
73 * Show enable install tool
74 *
75 * @return void
76 */
77 public function showEnableInstallToolButtonAction() {
78 $token = $this->formProtection->generateToken('installTool');
79 $this->view->assign('installToolEnableToken', $token);
80 }
81
82 /**
83 * Enable the install tool
84 *
85 * @param string $installToolEnableToken
86 * @throws \RuntimeException
87 */
88 public function enableInstallToolAction($installToolEnableToken) {
89 if (!$this->formProtection->validateToken($installToolEnableToken, 'installTool')) {
90 throw new \RuntimeException('Given form token was not valid', 1369161225);
91 }
92 $this->enableFileService->createInstallToolEnableFile();
93 $this->forward('index');
94 }
95
96 /**
97 * Redirect to specified URI
98 *
99 * @param string $uri
100 */
101 protected function redirect($uri) {
102 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($uri);
103 }
104 }