[BUGFIX] Introduce failsafe view in install tool
[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 $installToolService = $this->objectManager->get('TYPO3\\CMS\\Install\\Service\\EnableFileService');
76 $installToolService->createInstallToolEnableFile();
77 }
78
79 return $errorsFromStructure;
80 }
81
82 /**
83 * Step needs to be executed if LocalConfiguration file does not exist.
84 *
85 * @return boolean
86 */
87 public function needsExecution() {
88 if (@is_file(PATH_typo3conf . 'LocalConfiguration.php')) {
89 return FALSE;
90 } else {
91 return TRUE;
92 }
93 }
94
95 /**
96 * Executes the step
97 *
98 * @return string Rendered content
99 */
100 protected function executeAction() {
101 /** @var \TYPO3\CMS\Install\SystemEnvironment\Check $statusCheck */
102 $statusCheck = $this->objectManager->get('TYPO3\\CMS\\Install\\SystemEnvironment\\Check');
103 $statusObjects = $statusCheck->getStatus();
104 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
105 $statusUtility = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\StatusUtility');
106 $environmentStatus = $statusUtility->sortBySeverity($statusObjects);
107 $alerts = $statusUtility->filterBySeverity($statusObjects, 'alert');
108 $this->view->assign('alerts', $alerts);
109 $this->view->assign('environmentStatus', $environmentStatus);
110
111 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
112 $folderStructureFactory = $this->objectManager->get('TYPO3\\CMS\\Install\\FolderStructure\\DefaultFactory');
113 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
114 $structureFacade = $folderStructureFactory->getStructure();
115 $structureMessages = $structureFacade->getStatus();
116 /** @var $statusUtility \TYPO3\CMS\Install\Status\StatusUtility */
117 $structureErrors = $statusUtility->filterBySeverity($structureMessages, 'error');
118 $this->view->assign('structureErrors', $structureErrors);
119
120 if (count($environmentStatus['error']) > 0
121 || count($environmentStatus['warning']) > 0
122 || count($structureErrors) > 0
123 ) {
124 $this->view->assign('errorsOrWarningsFromStatus', TRUE);
125 }
126
127 return $this->view->render(!empty($alerts));
128 }
129 }