[BUGFIX] Make environment check standalone
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Install\Status\StatusUtility;
19 use TYPO3\CMS\Install\SystemEnvironment\Check;
20 use TYPO3\CMS\Install\SystemEnvironment\SetupCheck;
21
22 /**
23 * Very first install step:
24 * - Needs execution if typo3conf/LocalConfiguration.php does not exist
25 * - Renders system environment output
26 * - Creates folders like typo3temp, see FolderStructure/DefaultFactory for details
27 * - Creates typo3conf/LocalConfiguration.php from factory
28 */
29 class EnvironmentAndFolders extends AbstractStepAction
30 {
31 /**
32 * Execute environment and folder step:
33 * - Create main folder structure
34 * - Create typo3conf/LocalConfiguration.php
35 *
36 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
37 */
38 public function execute()
39 {
40 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
41 $folderStructureFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Install\FolderStructure\DefaultFactory::class);
42 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
43 $structureFacade = $folderStructureFactory->getStructure();
44 $structureFixMessages = $structureFacade->fix();
45 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
46 $statusUtility = GeneralUtility::makeInstance(StatusUtility::class);
47 $errorsFromStructure = $statusUtility->filterBySeverity($structureFixMessages, 'error');
48
49 if (@is_dir(PATH_typo3conf)) {
50 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
51 $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
52 $configurationManager->createLocalConfigurationFromFactoryConfiguration();
53
54 // Create a PackageStates.php with all packages activated marked as "part of factory default"
55 if (!file_exists(PATH_typo3conf . 'PackageStates.php')) {
56 /** @var \TYPO3\CMS\Core\Package\FailsafePackageManager $packageManager */
57 $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
58 $packages = $packageManager->getAvailablePackages();
59 foreach ($packages as $package) {
60 /** @var $package \TYPO3\CMS\Core\Package\PackageInterface */
61 if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
62 && $package->isPartOfFactoryDefault()
63 ) {
64 $packageManager->activatePackage($package->getPackageKey());
65 }
66 }
67 $packageManager->forceSortAndSavePackageStates();
68 }
69
70 // Create enable install tool file after typo3conf & LocalConfiguration were created
71 /** @var \TYPO3\CMS\Install\Service\EnableFileService $installToolService */
72 $installToolService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\EnableFileService::class);
73 $installToolService->removeFirstInstallFile();
74 $installToolService->createInstallToolEnableFile();
75 }
76
77 return $errorsFromStructure;
78 }
79
80 /**
81 * Step needs to be executed if LocalConfiguration file does not exist.
82 *
83 * @return bool
84 */
85 public function needsExecution()
86 {
87 if (@is_file(PATH_typo3conf . 'LocalConfiguration.php')) {
88 return false;
89 } else {
90 return true;
91 }
92 }
93
94 /**
95 * Executes the step
96 *
97 * @return string Rendered content
98 */
99 protected function executeAction()
100 {
101 $statusObjects = array_merge(
102 GeneralUtility::makeInstance(Check::class)->getStatus(),
103 GeneralUtility::makeInstance(SetupCheck::class)->getStatus()
104 );
105 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
106 $statusUtility = GeneralUtility::makeInstance(StatusUtility::class);
107 $environmentStatus = $statusUtility->sortBySeverity($statusObjects);
108 $alerts = $statusUtility->filterBySeverity($statusObjects, 'alert');
109 $this->view->assign('alerts', $alerts);
110 $this->view->assign('environmentStatus', $environmentStatus);
111
112 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
113 $folderStructureFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Install\FolderStructure\DefaultFactory::class);
114 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
115 $structureFacade = $folderStructureFactory->getStructure();
116 $structureMessages = $structureFacade->getStatus();
117 /** @var $statusUtility \TYPO3\CMS\Install\Status\StatusUtility */
118 $structureErrors = $statusUtility->filterBySeverity($structureMessages, 'error');
119 $this->view->assign('structureErrors', $structureErrors);
120
121 if (!empty($environmentStatus['error']) || !empty($environmentStatus['warning']) || !empty($structureErrors)) {
122 $this->view->assign('errorsOrWarningsFromStatus', true);
123 }
124 $this->assignSteps();
125
126 return $this->view->render();
127 }
128 }