TYPO3 CMS  TYPO3_6-2
StepController.php
Go to the documentation of this file.
1 <?php
3 
18 
23 
27  protected $authenticationActions = array(
28  'environmentAndFolders',
29  'databaseConnect',
30  'databaseSelect',
31  'databaseData',
32  'defaultConfiguration',
33  );
34 
44  public function execute() {
45  $this->loadBaseExtensions();
46  $this->initializeObjectManager();
47 
48  $this->outputInstallToolNotEnabledMessageIfNeeded();
49  $this->migrateLocalconfToLocalConfigurationIfNeeded();
50  $this->outputInstallToolPasswordNotSetMessageIfNeeded();
51  $this->migrateExtensionListToPackageStatesFile();
52  $this->executeOrOutputFirstInstallStepIfNeeded();
53  $this->executeSilentConfigurationUpgradesIfNeeded();
54  $this->initializeSession();
55  $this->checkSessionToken();
56  $this->checkSessionLifetime();
57  $this->loginIfRequested();
59  $this->executeSpecificStep();
60  $this->outputSpecificStep();
61  $this->redirectToTool();
62  }
63 
72  protected function executeSpecificStep() {
73  $action = $this->getAction();
74  $postValues = $this->getPostValues();
75  if ($action && isset($postValues['set']) && $postValues['set'] === 'execute') {
76  $stepAction = $this->getActionInstance($action);
77  $stepAction->setAction($action);
78  $stepAction->setToken($this->generateTokenForAction($action));
79  $stepAction->setPostValues($this->getPostValues());
80  $messages = $stepAction->execute();
81  $this->addSessionMessages($messages);
82  $this->redirect();
83  }
84  }
85 
94  protected function outputSpecificStep() {
95  $action = $this->getAction();
96  if ($action === '') {
97  // First step action
98  list($action) = $this->authenticationActions;
99  }
100  $stepAction = $this->getActionInstance($action);
101  $stepAction->setAction($action);
102  $stepAction->setController('step');
103  $stepAction->setToken($this->generateTokenForAction($action));
104  $stepAction->setPostValues($this->getPostValues());
105 
106  $needsExecution = TRUE;
107  try {
108  // needsExecution() may throw a RedirectException to communicate that it changed
109  // configuration parameters and need an application reload.
110  $needsExecution = $stepAction->needsExecution();
111  } catch (Exception\RedirectException $e) {
112  $this->redirect();
113  }
114 
115  if ($needsExecution) {
116  if ($this->isInitialInstallationInProgress()) {
117  $currentStep = (array_search($action, $this->authenticationActions) + 1);
118  $totalSteps = count($this->authenticationActions);
119  $stepAction->setStepsCounter($currentStep, $totalSteps);
120  }
121  $stepAction->setMessages($this->session->getMessagesAndFlush());
122  $this->output($stepAction->handle());
123  } else {
124  // Redirect to next step if there are any
125  $currentPosition = array_keys($this->authenticationActions, $action, TRUE);
126  $nextAction = array_slice($this->authenticationActions, $currentPosition[0] + 1, 1);
127  if (!empty($nextAction)) {
128  $this->redirect('', $nextAction[0]);
129  }
130  }
131  }
132 
140  protected function getActionInstance($action) {
141  $this->validateAuthenticationAction($action);
142  $actionClass = ucfirst($action);
144  $stepAction = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\' . $actionClass);
145  if (!($stepAction instanceof Action\Step\StepInterface)) {
146  throw new Exception(
147  $action . ' does non implement StepInterface',
148  1371303903
149  );
150  }
151  return $stepAction;
152  }
153 
160  protected function redirectToTool() {
161  $this->redirect('tool');
162  }
163 
174  protected function migrateLocalconfToLocalConfigurationIfNeeded() {
176  $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
177 
178  $localConfigurationFileLocation = $configurationManager->getLocalConfigurationFileLocation();
179  $localConfigurationFileExists = is_file($localConfigurationFileLocation);
180  $localConfFileLocation = PATH_typo3conf . 'localconf.php';
181  $localConfFileExists = is_file($localConfFileLocation);
182 
183  if (is_dir(PATH_typo3conf) && $localConfFileExists && !$localConfigurationFileExists) {
184  $localConfContent = file($localConfFileLocation);
185 
186  // Line array for the three categories: localConfiguration, db settings, additionalConfiguration
187  $typo3ConfigurationVariables = array();
188  $typo3DatabaseVariables = array();
189  $additionalConfiguration = array();
190  foreach ($localConfContent as $line) {
191  $line = trim($line);
192  $matches = array();
193  // Convert extList to array
194  if (
195  preg_match('/^\\$TYPO3_CONF_VARS\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1
196  || preg_match('/^\\$GLOBALS\\[\'TYPO3_CONF_VARS\'\\]\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1
197  ) {
198  $extListAsArray = GeneralUtility::trimExplode(',', $matches[1], TRUE);
199  $typo3ConfigurationVariables[] = '$TYPO3_CONF_VARS[\'EXT\'][\'extListArray\'] = ' . var_export($extListAsArray, TRUE) . ';';
200  } elseif (
201  preg_match('/^\\$TYPO3_CONF_VARS.+;{1}/', $line, $matches) === 1
202  ) {
203  $typo3ConfigurationVariables[] = $matches[0];
204  } elseif (
205  preg_match('/^\\$GLOBALS\\[\'TYPO3_CONF_VARS\'\\].+;{1}/', $line, $matches) === 1
206  ) {
207  $lineWithoutGlobals = str_replace('$GLOBALS[\'TYPO3_CONF_VARS\']', '$TYPO3_CONF_VARS', $matches[0]);
208  $typo3ConfigurationVariables[] = $lineWithoutGlobals;
209  } elseif (
210  preg_match('/^\\$typo_db.+;{1}/', $line, $matches) === 1
211  ) {
212  eval($matches[0]);
213  if (isset($typo_db_host)) {
214  $typo3DatabaseVariables['host'] = $typo_db_host;
215  } elseif (isset($typo_db)) {
216  $typo3DatabaseVariables['database'] = $typo_db;
217  } elseif (isset($typo_db_username)) {
218  $typo3DatabaseVariables['username'] = $typo_db_username;
219  } elseif (isset($typo_db_password)) {
220  $typo3DatabaseVariables['password'] = $typo_db_password;
221  } elseif (isset($typo_db_extTableDef_script)) {
222  $typo3DatabaseVariables['extTablesDefinitionScript'] = $typo_db_extTableDef_script;
223  }
224  unset($typo_db_host, $typo_db, $typo_db_username, $typo_db_password, $typo_db_extTableDef_script);
225  } elseif (
226  strlen($line) > 0 && preg_match('/^\\/\\/.+|^#.+|^<\\?php$|^<\\?$|^\\?>$/', $line, $matches) === 0
227  ) {
228  $additionalConfiguration[] = $line;
229  }
230  }
231 
232  // Build new TYPO3_CONF_VARS array
233  $TYPO3_CONF_VARS = NULL;
234  // Issue #39434: Combining next two lines into one triggers a weird issue in some PHP versions
235  $evalData = implode(LF, $typo3ConfigurationVariables);
236  eval($evalData);
237 
238  // Add db settings to array
239  $TYPO3_CONF_VARS['DB'] = $typo3DatabaseVariables;
241 
242  // Write out new LocalConfiguration file
243  $configurationManager->writeLocalConfiguration($TYPO3_CONF_VARS);
244 
245  // Write out new AdditionalConfiguration file
246  if (sizeof($additionalConfiguration) > 0) {
247  $configurationManager->writeAdditionalConfiguration($additionalConfiguration);
248  } else {
249  @unlink($configurationManager->getAdditionalConfigurationFileLocation());
250  }
251 
252  // Move localconf.php to localconf.obsolete.php
253  rename($localConfFileLocation, PATH_site . 'typo3conf/localconf.obsolete.php');
254 
255  // Perform a reload to self, so bootstrap now uses new LocalConfiguration.php
256  $this->redirect();
257  }
258  }
259 
276  protected function migrateExtensionListToPackageStatesFile() {
278  $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
279  $localConfigurationFileLocation = $configurationManager->getLocalConfigurationFileLocation();
280  $localConfigurationFileExists = is_file($localConfigurationFileLocation);
281  $packageStatesFilePath = PATH_typo3conf . 'PackageStates.php';
282  $localConfigurationBackupFilePath = preg_replace(
283  '/\\.php$/',
284  '.beforePackageStatesMigration.php',
285  $configurationManager->getLocalConfigurationFileLocation()
286  );
287 
288  if (file_exists($packageStatesFilePath)
289  || (is_dir(PATH_typo3conf) && !$localConfigurationFileExists)
290  || !is_dir(PATH_typo3conf)
291  ) {
292  return;
293  }
294 
295  try {
297  $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManager');
298 
299  // Activate all packages required for a minimal usable system
300  $packages = $packageManager->getAvailablePackages();
301  foreach ($packages as $package) {
303  if ($package instanceof \TYPO3\CMS\Core\Package\PackageInterface
304  && $package->isPartOfMinimalUsableSystem()
305  ) {
306  $packageManager->activatePackage($package->getPackageKey());
307  }
308  }
309 
310  // Activate all packages from LocalConfiguration EXT/extListArray if there is such an entry during upgrading.
311  $extensionsFromExtListArray = array();
312  try {
313  $extensionsFromExtListArray = $configurationManager->getLocalConfigurationValueByPath('EXT/extListArray');
314  } catch (\RuntimeException $exception) {
315  }
316  foreach ($extensionsFromExtListArray as $loadedExtension) {
317  try {
318  $packageManager->activatePackage($loadedExtension);
319  } catch (\TYPO3\Flow\Package\Exception\UnknownPackageException $exception) {
320  // Skip unavailable packages silently
321  }
322  }
323 
324  // Backup LocalConfiguration.php
325  copy(
326  $configurationManager->getLocalConfigurationFileLocation(),
327  $localConfigurationBackupFilePath
328  );
329 
330  $packageManager->forceSortAndSavePackageStates();
331 
332  // Perform a reload to self, so bootstrap now uses new PackageStates.php
333  $this->redirect();
334  } catch (\Exception $exception) {
335  if (file_exists($packageStatesFilePath)) {
336  unlink($packageStatesFilePath);
337  }
338  if (file_exists($localConfigurationBackupFilePath)) {
339  unlink($localConfigurationBackupFilePath);
340  }
341  throw $exception;
342  }
343  }
344 
359  protected function executeOrOutputFirstInstallStepIfNeeded() {
360  $postValues = $this->getPostValues();
361 
362  $wasExecuted = FALSE;
363  $errorMessagesFromExecute = array();
364  if (isset($postValues['action'])
365  && $postValues['action'] === 'environmentAndFolders'
366  ) {
368  $action = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\EnvironmentAndFolders');
369  $errorMessagesFromExecute = $action->execute();
370  $wasExecuted = TRUE;
371  }
372 
374  $action = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\EnvironmentAndFolders');
375 
376  $needsExecution = TRUE;
377  try {
378  // needsExecution() may throw a RedirectException to communicate that it changed
379  // configuration parameters and need an application reload.
380  $needsExecution = $action->needsExecution();
381  } catch (Exception\RedirectException $e) {
382  $this->redirect();
383  }
384 
385  $testReflection = new \ReflectionMethod(get_class($this), __FUNCTION__);
386  if (!@is_dir(PATH_typo3conf)
387  || $needsExecution
388  || $testReflection->getDocComment() === FALSE
389  ) {
391  $action = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\EnvironmentAndFolders');
392  if ($this->isInitialInstallationInProgress()) {
393  $currentStep = (array_search('environmentAndFolders', $this->authenticationActions) + 1);
394  $totalSteps = count($this->authenticationActions);
395  $action->setStepsCounter($currentStep, $totalSteps);
396  }
397  $action->setController('step');
398  $action->setAction('environmentAndFolders');
399  if (count($errorMessagesFromExecute) > 0) {
400  $action->setMessages($errorMessagesFromExecute);
401  }
402  $this->output($action->handle());
403  }
404 
405  if ($wasExecuted) {
406  $this->redirect();
407  }
408  }
409 
415  protected function executeSilentConfigurationUpgradesIfNeeded() {
417  $upgradeService = $this->objectManager->get(
418  'TYPO3\\CMS\\Install\\Service\\SilentConfigurationUpgradeService'
419  );
420  try {
421  $upgradeService->execute();
422  } catch (Exception\RedirectException $e) {
423  $this->redirect();
424  }
425  }
426 }
$TYPO3_CONF_VARS['SYS']['contentTable']
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static sortByKeyRecursive(array $array)