[!!!][SECURITY] Allow first install only with FIRST_INSTALL file
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Step / EnvironmentAndFolders.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Step;
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 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Very first install step:
29 * - Needs execution if typo3conf/LocalConfiguration.php does not exist
30 * - Renders system environment output
31 * - Creates folders like typo3temp, see FolderStructure/DefaultFactory for details
32 * - Creates typo3conf/LocalConfiguration.php from factory
33 */
34 class EnvironmentAndFolders extends AbstractStepAction {
35
36 /**
37 * Execute environment and folder step:
38 * - Create main folder structure
39 * - Create typo3conf/LocalConfiguration.php
40 *
41 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
42 */
43 public function execute() {
44 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
45 $folderStructureFactory = $this->objectManager->get('TYPO3\\CMS\\Install\\FolderStructure\\DefaultFactory');
46 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
47 $structureFacade = $folderStructureFactory->getStructure();
48 $structureFixMessages = $structureFacade->fix();
49 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
50 $statusUtility = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\StatusUtility');
51 $errorsFromStructure = $statusUtility->filterBySeverity($structureFixMessages, 'error');
52
53 if (@is_dir(PATH_typo3conf)) {
54 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
55 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
56 $configurationManager->createLocalConfigurationFromFactoryConfiguration();
57
58 // Create a PackageStates.php with all packages activated marked as "part of factory default"
59 if (!file_exists(PATH_typo3conf . 'PackageStates.php')) {
60 /** @var \TYPO3\CMS\Core\Package\FailsafePackageManager $packageManager */
61 $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManager');
62 $packages = $packageManager->getAvailablePackages();
63 foreach ($packages as $package) {
64 /** @var $package \TYPO3\CMS\Core\Package\PackageInterface */
65 if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
66 && $package->isPartOfFactoryDefault()
67 ) {
68 $packageManager->activatePackage($package->getPackageKey());
69 }
70 }
71 $packageManager->forceSortAndSavePackageStates();
72 }
73
74 // Create enable install tool file after typo3conf & LocalConfiguration were created
75 /** @var \TYPO3\CMS\Install\Service\EnableFileService $installToolService */
76 $installToolService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\EnableFileService');
77 $installToolService->removeFirstInstallFile();
78 $installToolService->createInstallToolEnableFile();
79 }
80
81 return $errorsFromStructure;
82 }
83
84 /**
85 * Step needs to be executed if LocalConfiguration file does not exist.
86 *
87 * @return boolean
88 */
89 public function needsExecution() {
90 if (@is_file(PATH_typo3conf . 'LocalConfiguration.php')) {
91 return FALSE;
92 } else {
93 return TRUE;
94 }
95 }
96
97 /**
98 * Executes the step
99 *
100 * @return string Rendered content
101 */
102 protected function executeAction() {
103 /** @var \TYPO3\CMS\Install\SystemEnvironment\Check $statusCheck */
104 $statusCheck = $this->objectManager->get('TYPO3\\CMS\\Install\\SystemEnvironment\\Check');
105 $statusObjects = $statusCheck->getStatus();
106 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
107 $statusUtility = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\StatusUtility');
108 $environmentStatus = $statusUtility->sortBySeverity($statusObjects);
109 $alerts = $statusUtility->filterBySeverity($statusObjects, 'alert');
110 $this->view->assign('alerts', $alerts);
111 $this->view->assign('environmentStatus', $environmentStatus);
112
113 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
114 $folderStructureFactory = $this->objectManager->get('TYPO3\\CMS\\Install\\FolderStructure\\DefaultFactory');
115 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
116 $structureFacade = $folderStructureFactory->getStructure();
117 $structureMessages = $structureFacade->getStatus();
118 /** @var $statusUtility \TYPO3\CMS\Install\Status\StatusUtility */
119 $structureErrors = $statusUtility->filterBySeverity($structureMessages, 'error');
120 $this->view->assign('structureErrors', $structureErrors);
121
122 if (count($environmentStatus['error']) > 0
123 || count($environmentStatus['warning']) > 0
124 || count($structureErrors) > 0
125 ) {
126 $this->view->assign('errorsOrWarningsFromStatus', TRUE);
127 }
128
129 return $this->view->render(!empty($alerts));
130 }
131 }