TYPO3 CMS  TYPO3_8-7
StepController.php
Go to the documentation of this file.
1 <?php
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 
19 
24 {
28  protected $authenticationActions = [
29  'environmentAndFolders',
30  'databaseConnect',
31  'databaseSelect',
32  'databaseData',
33  'defaultConfiguration',
34  ];
35 
44  public function execute()
45  {
46  $this->loadBaseExtensions();
47  $this->outputInstallToolNotEnabledMessageIfNeeded();
48  $this->outputInstallToolPasswordNotSetMessageIfNeeded();
49  $this->recreatePackageStatesFileIfNotExisting();
50  $this->executeOrOutputFirstInstallStepIfNeeded();
51  $this->adjustTrustedHostsPatternIfNeeded();
52  $this->executeSilentConfigurationUpgradesIfNeeded();
53  $this->initializeSession();
54  $this->checkSessionToken();
55  $this->checkSessionLifetime();
56  $this->loginIfRequested();
58  $this->executeSpecificStep();
59  $this->outputSpecificStep();
60  $this->redirectToTool();
61  }
62 
70  protected function executeSpecificStep()
71  {
72  $action = $this->getAction();
73  $postValues = $this->getPostValues();
74  if ($action && isset($postValues['set']) && $postValues['set'] === 'execute') {
75  $stepAction = $this->getActionInstance($action);
76  $stepAction->setAction($action);
77  $stepAction->setToken($this->generateTokenForAction($action));
78  $stepAction->setPostValues($this->getPostValues());
79  $messages = $stepAction->execute();
80  $this->addSessionMessages($messages);
81  $this->redirect();
82  }
83  }
84 
91  protected function outputSpecificStep()
92  {
93  $action = $this->getAction();
94  if ($action === '') {
95  // First step action
96  list($action) = $this->authenticationActions;
97  }
98  $stepAction = $this->getActionInstance($action);
99  $stepAction->setAction($action);
100  $stepAction->setController('step');
101  $stepAction->setToken($this->generateTokenForAction($action));
102  $stepAction->setPostValues($this->getPostValues());
103 
104  $needsExecution = true;
105  try {
106  // needsExecution() may throw a RedirectException to communicate that it changed
107  // configuration parameters and need an application reload.
108  $needsExecution = $stepAction->needsExecution();
109  } catch (Exception\RedirectException $e) {
110  $this->redirect();
111  }
112 
113  if ($needsExecution) {
114  if ($this->isInitialInstallationInProgress()) {
115  $currentStep = (array_search($action, $this->authenticationActions) + 1);
116  $totalSteps = count($this->authenticationActions);
117  $stepAction->setStepsCounter($currentStep, $totalSteps);
118  }
119  $stepAction->setMessages($this->session->getMessagesAndFlush());
120  $this->output($stepAction->handle());
121  } else {
122  // Redirect to next step if there are any
123  $currentPosition = array_keys($this->authenticationActions, $action, true);
124  $nextAction = array_slice($this->authenticationActions, $currentPosition[0] + 1, 1);
125  if (!empty($nextAction)) {
126  $this->redirect('', $nextAction[0]);
127  }
128  }
129  }
130 
138  protected function getActionInstance($action)
139  {
140  $this->validateAuthenticationAction($action);
141  $actionClass = ucfirst($action);
143  $stepAction = GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\' . $actionClass);
144  if (!($stepAction instanceof Action\Step\StepInterface)) {
145  throw new Exception(
146  $action . ' does non implement StepInterface',
147  1371303903
148  );
149  }
150  return $stepAction;
151  }
152 
157  protected function redirectToTool()
158  {
159  $this->redirect('tool');
160  }
161 
174  protected function recreatePackageStatesFileIfNotExisting()
175  {
177  $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
178  $localConfigurationFileLocation = $configurationManager->getLocalConfigurationFileLocation();
179  $localConfigurationFileExists = is_file($localConfigurationFileLocation);
180  $packageStatesFilePath = PATH_typo3conf . 'PackageStates.php';
181  $localConfigurationBackupFilePath = preg_replace(
182  '/\\.php$/',
183  '.beforePackageStatesMigration.php',
184  $configurationManager->getLocalConfigurationFileLocation()
185  );
186 
187  if (file_exists($packageStatesFilePath)
188  || (is_dir(PATH_typo3conf) && !$localConfigurationFileExists)
189  || !is_dir(PATH_typo3conf)
190  ) {
191  return;
192  }
193 
194  try {
196  $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
197 
198  // Activate all packages required for a minimal usable system
199  $packages = $packageManager->getAvailablePackages();
200  foreach ($packages as $package) {
202  if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
203  && $package->isPartOfMinimalUsableSystem()
204  ) {
205  $packageManager->activatePackage($package->getPackageKey());
206  }
207  }
208 
209  // Backup LocalConfiguration.php
210  copy(
211  $configurationManager->getLocalConfigurationFileLocation(),
212  $localConfigurationBackupFilePath
213  );
214 
215  $packageManager->forceSortAndSavePackageStates();
216 
217  // Perform a reload to self, so bootstrap now uses new PackageStates.php
218  $this->redirect();
219  } catch (\Exception $exception) {
220  if (file_exists($packageStatesFilePath)) {
221  unlink($packageStatesFilePath);
222  }
223  if (file_exists($localConfigurationBackupFilePath)) {
224  unlink($localConfigurationBackupFilePath);
225  }
226  throw $exception;
227  }
228  }
229 
242  protected function executeOrOutputFirstInstallStepIfNeeded()
243  {
244  $postValues = $this->getPostValues();
245 
246  $wasExecuted = false;
247  $errorMessagesFromExecute = [];
248  if (isset($postValues['action'])
249  && $postValues['action'] === 'environmentAndFolders'
250  ) {
252  $action = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
253  $errorMessagesFromExecute = $action->execute();
254  $wasExecuted = true;
255  }
256 
258  $action = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
259 
260  $needsExecution = true;
261  try {
262  // needsExecution() may throw a RedirectException to communicate that it changed
263  // configuration parameters and need an application reload.
264  $needsExecution = $action->needsExecution();
265  } catch (Exception\RedirectException $e) {
266  $this->redirect();
267  }
268 
269  if (!@is_dir(PATH_typo3conf) || $needsExecution) {
271  $action = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
272  if ($this->isInitialInstallationInProgress()) {
273  $currentStep = (array_search('environmentAndFolders', $this->authenticationActions) + 1);
274  $totalSteps = count($this->authenticationActions);
275  $action->setStepsCounter($currentStep, $totalSteps);
276  }
277  $action->setController('step');
278  $action->setAction('environmentAndFolders');
279  if (!empty($errorMessagesFromExecute)) {
280  $action->setMessages($errorMessagesFromExecute);
281  }
282  $this->output($action->handle());
283  }
284 
285  if ($wasExecuted) {
286  $this->redirect();
287  }
288  }
289 
293  protected function adjustTrustedHostsPatternIfNeeded()
294  {
296  return;
297  }
298 
300  $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
301  $configurationManager->setLocalConfigurationValueByPath('SYS/trustedHostsPattern', '.*');
302  $this->redirect();
303  }
304 
308  protected function executeSilentConfigurationUpgradesIfNeeded()
309  {
311  $upgradeService = GeneralUtility::makeInstance(SilentConfigurationUpgradeService::class);
312  try {
313  $upgradeService->execute();
314  } catch (Exception\RedirectException $e) {
315  $this->redirect();
316  }
317  }
318 }
static makeInstance($className,... $constructorArguments)
static hostHeaderValueMatchesTrustedHostsPattern($hostHeaderValue)