[TASK] Get rid of ObjectManager 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 * 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
19 /**
20 * Very first install step:
21 * - Needs execution if typo3conf/LocalConfiguration.php does not exist
22 * - Renders system environment output
23 * - Creates folders like typo3temp, see FolderStructure/DefaultFactory for details
24 * - Creates typo3conf/LocalConfiguration.php from factory
25 */
26 class EnvironmentAndFolders extends AbstractStepAction
27 {
28 /**
29 * Execute environment and folder step:
30 * - Create main folder structure
31 * - Create typo3conf/LocalConfiguration.php
32 *
33 * @return array<\TYPO3\CMS\Install\Status\StatusInterface>
34 */
35 public function execute()
36 {
37 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
38 $folderStructureFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Install\FolderStructure\DefaultFactory::class);
39 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
40 $structureFacade = $folderStructureFactory->getStructure();
41 $structureFixMessages = $structureFacade->fix();
42 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
43 $statusUtility = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\StatusUtility::class);
44 $errorsFromStructure = $statusUtility->filterBySeverity($structureFixMessages, 'error');
45
46 if (@is_dir(PATH_typo3conf)) {
47 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
48 $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
49 $configurationManager->createLocalConfigurationFromFactoryConfiguration();
50
51 // Create a PackageStates.php with all packages activated marked as "part of factory default"
52 if (!file_exists(PATH_typo3conf . 'PackageStates.php')) {
53 /** @var \TYPO3\CMS\Core\Package\FailsafePackageManager $packageManager */
54 $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
55 $packages = $packageManager->getAvailablePackages();
56 foreach ($packages as $package) {
57 /** @var $package \TYPO3\CMS\Core\Package\PackageInterface */
58 if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
59 && $package->isPartOfFactoryDefault()
60 ) {
61 $packageManager->activatePackage($package->getPackageKey());
62 }
63 }
64 $packageManager->forceSortAndSavePackageStates();
65 }
66
67 // Create enable install tool file after typo3conf & LocalConfiguration were created
68 /** @var \TYPO3\CMS\Install\Service\EnableFileService $installToolService */
69 $installToolService = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\EnableFileService::class);
70 $installToolService->removeFirstInstallFile();
71 $installToolService->createInstallToolEnableFile();
72 }
73
74 return $errorsFromStructure;
75 }
76
77 /**
78 * Step needs to be executed if LocalConfiguration file does not exist.
79 *
80 * @return bool
81 */
82 public function needsExecution()
83 {
84 if (@is_file(PATH_typo3conf . 'LocalConfiguration.php')) {
85 return false;
86 } else {
87 return true;
88 }
89 }
90
91 /**
92 * Executes the step
93 *
94 * @return string Rendered content
95 */
96 protected function executeAction()
97 {
98 /** @var \TYPO3\CMS\Install\SystemEnvironment\Check $statusCheck */
99 $statusCheck = GeneralUtility::makeInstance(\TYPO3\CMS\Install\SystemEnvironment\Check::class);
100 $statusObjects = $statusCheck->getStatus();
101 /** @var \TYPO3\CMS\Install\Status\StatusUtility $statusUtility */
102 $statusUtility = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\StatusUtility::class);
103 $environmentStatus = $statusUtility->sortBySeverity($statusObjects);
104 $alerts = $statusUtility->filterBySeverity($statusObjects, 'alert');
105 $this->view->assign('alerts', $alerts);
106 $this->view->assign('environmentStatus', $environmentStatus);
107
108 /** @var $folderStructureFactory \TYPO3\CMS\Install\FolderStructure\DefaultFactory */
109 $folderStructureFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Install\FolderStructure\DefaultFactory::class);
110 /** @var $structureFacade \TYPO3\CMS\Install\FolderStructure\StructureFacade */
111 $structureFacade = $folderStructureFactory->getStructure();
112 $structureMessages = $structureFacade->getStatus();
113 /** @var $statusUtility \TYPO3\CMS\Install\Status\StatusUtility */
114 $structureErrors = $statusUtility->filterBySeverity($structureMessages, 'error');
115 $this->view->assign('structureErrors', $structureErrors);
116
117 if (!empty($environmentStatus['error']) || !empty($environmentStatus['warning']) || !empty($structureErrors)) {
118 $this->view->assign('errorsOrWarningsFromStatus', true);
119 }
120 $this->assignSteps();
121
122 return $this->view->render();
123 }
124 }