TYPO3 CMS  TYPO3_7-6
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 
45  public function execute()
46  {
47  $this->loadBaseExtensions();
48  $this->initializeObjectManager();
49 
50  $this->outputInstallToolNotEnabledMessageIfNeeded();
51  $this->outputInstallToolPasswordNotSetMessageIfNeeded();
52  $this->recreatePackageStatesFileIfNotExisting();
53  $this->executeOrOutputFirstInstallStepIfNeeded();
54  $this->adjustTrustedHostsPatternIfNeeded();
55  $this->executeSilentConfigurationUpgradesIfNeeded();
56  $this->initializeSession();
57  $this->checkSessionToken();
58  $this->checkSessionLifetime();
59  $this->loginIfRequested();
61  $this->executeSpecificStep();
62  $this->outputSpecificStep();
63  $this->redirectToTool();
64  }
65 
74  protected function executeSpecificStep()
75  {
76  $action = $this->getAction();
77  $postValues = $this->getPostValues();
78  if ($action && isset($postValues['set']) && $postValues['set'] === 'execute') {
79  $stepAction = $this->getActionInstance($action);
80  $stepAction->setAction($action);
81  $stepAction->setToken($this->generateTokenForAction($action));
82  $stepAction->setPostValues($this->getPostValues());
83  $messages = $stepAction->execute();
84  $this->addSessionMessages($messages);
85  $this->redirect();
86  }
87  }
88 
97  protected function outputSpecificStep()
98  {
99  $action = $this->getAction();
100  if ($action === '') {
101  // First step action
102  list($action) = $this->authenticationActions;
103  }
104  $stepAction = $this->getActionInstance($action);
105  $stepAction->setAction($action);
106  $stepAction->setController('step');
107  $stepAction->setToken($this->generateTokenForAction($action));
108  $stepAction->setPostValues($this->getPostValues());
109 
110  $needsExecution = true;
111  try {
112  // needsExecution() may throw a RedirectException to communicate that it changed
113  // configuration parameters and need an application reload.
114  $needsExecution = $stepAction->needsExecution();
115  } catch (Exception\RedirectException $e) {
116  $this->redirect();
117  }
118 
119  if ($needsExecution) {
120  if ($this->isInitialInstallationInProgress()) {
121  $currentStep = (array_search($action, $this->authenticationActions) + 1);
122  $totalSteps = count($this->authenticationActions);
123  $stepAction->setStepsCounter($currentStep, $totalSteps);
124  }
125  $stepAction->setMessages($this->session->getMessagesAndFlush());
126  $this->output($stepAction->handle());
127  } else {
128  // Redirect to next step if there are any
129  $currentPosition = array_keys($this->authenticationActions, $action, true);
130  $nextAction = array_slice($this->authenticationActions, $currentPosition[0] + 1, 1);
131  if (!empty($nextAction)) {
132  $this->redirect('', $nextAction[0]);
133  }
134  }
135  }
136 
144  protected function getActionInstance($action)
145  {
146  $this->validateAuthenticationAction($action);
147  $actionClass = ucfirst($action);
149  $stepAction = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\' . $actionClass);
150  if (!($stepAction instanceof Action\Step\StepInterface)) {
151  throw new Exception(
152  $action . ' does non implement StepInterface',
153  1371303903
154  );
155  }
156  return $stepAction;
157  }
158 
165  protected function redirectToTool()
166  {
167  $this->redirect('tool');
168  }
169 
183  protected function recreatePackageStatesFileIfNotExisting()
184  {
186  $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
187  $localConfigurationFileLocation = $configurationManager->getLocalConfigurationFileLocation();
188  $localConfigurationFileExists = is_file($localConfigurationFileLocation);
189  $packageStatesFilePath = PATH_typo3conf . 'PackageStates.php';
190  $localConfigurationBackupFilePath = preg_replace(
191  '/\\.php$/',
192  '.beforePackageStatesMigration.php',
193  $configurationManager->getLocalConfigurationFileLocation()
194  );
195 
196  if (file_exists($packageStatesFilePath)
197  || (is_dir(PATH_typo3conf) && !$localConfigurationFileExists)
198  || !is_dir(PATH_typo3conf)
199  ) {
200  return;
201  }
202 
203  try {
205  $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance(\TYPO3\CMS\Core\Package\PackageManager::class);
206 
207  // Activate all packages required for a minimal usable system
208  $packages = $packageManager->getAvailablePackages();
209  foreach ($packages as $package) {
211  if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
212  && $package->isPartOfMinimalUsableSystem()
213  ) {
214  $packageManager->activatePackage($package->getPackageKey());
215  }
216  }
217 
218  // Backup LocalConfiguration.php
219  copy(
220  $configurationManager->getLocalConfigurationFileLocation(),
221  $localConfigurationBackupFilePath
222  );
223 
224  $packageManager->forceSortAndSavePackageStates();
225 
226  // Perform a reload to self, so bootstrap now uses new PackageStates.php
227  $this->redirect();
228  } catch (\Exception $exception) {
229  if (file_exists($packageStatesFilePath)) {
230  unlink($packageStatesFilePath);
231  }
232  if (file_exists($localConfigurationBackupFilePath)) {
233  unlink($localConfigurationBackupFilePath);
234  }
235  throw $exception;
236  }
237  }
238 
253  protected function executeOrOutputFirstInstallStepIfNeeded()
254  {
255  $postValues = $this->getPostValues();
256 
257  $wasExecuted = false;
258  $errorMessagesFromExecute = [];
259  if (isset($postValues['action'])
260  && $postValues['action'] === 'environmentAndFolders'
261  ) {
263  $action = $this->objectManager->get(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
264  $errorMessagesFromExecute = $action->execute();
265  $wasExecuted = true;
266  }
267 
269  $action = $this->objectManager->get(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
270 
271  $needsExecution = true;
272  try {
273  // needsExecution() may throw a RedirectException to communicate that it changed
274  // configuration parameters and need an application reload.
275  $needsExecution = $action->needsExecution();
276  } catch (Exception\RedirectException $e) {
277  $this->redirect();
278  }
279 
280  $testReflection = new \ReflectionMethod(get_class($this), __FUNCTION__);
281  if (!@is_dir(PATH_typo3conf)
282  || $needsExecution
283  || $testReflection->getDocComment() === false
284  ) {
286  $action = $this->objectManager->get(\TYPO3\CMS\Install\Controller\Action\Step\EnvironmentAndFolders::class);
287  if ($this->isInitialInstallationInProgress()) {
288  $currentStep = (array_search('environmentAndFolders', $this->authenticationActions) + 1);
289  $totalSteps = count($this->authenticationActions);
290  $action->setStepsCounter($currentStep, $totalSteps);
291  }
292  $action->setController('step');
293  $action->setAction('environmentAndFolders');
294  if (!empty($errorMessagesFromExecute)) {
295  $action->setMessages($errorMessagesFromExecute);
296  }
297  $this->output($action->handle());
298  }
299 
300  if ($wasExecuted) {
301  $this->redirect();
302  }
303  }
304 
308  protected function adjustTrustedHostsPatternIfNeeded()
309  {
311  return;
312  }
313 
315  $configurationManager = $this->objectManager->get(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class);
316  $configurationManager->setLocalConfigurationValueByPath('SYS/trustedHostsPattern', '.*');
317  $this->redirect();
318  }
319 
325  protected function executeSilentConfigurationUpgradesIfNeeded()
326  {
328  $upgradeService = $this->objectManager->get(SilentConfigurationUpgradeService::class);
329  try {
330  $upgradeService->execute();
331  } catch (Exception\RedirectException $e) {
332  $this->redirect();
333  }
334  }
335 }
static hostHeaderValueMatchesTrustedHostsPattern($hostHeaderValue)