[FEATURE] Add autofocus attribute to BE login
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / CoreUpdates / LocalConfigurationUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\CoreUpdates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Helge Funk <helge.funk@e-net.info>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Move localconf.php to LocalConfiguration.php
28 *
29 * @author Helge Funk <helge.funk@e-net.info>
30 */
31 class LocalConfigurationUpdate extends \TYPO3\CMS\Install\Updates\AbstractUpdate {
32
33 /**
34 * @var string The title
35 */
36 protected $title = 'Update LocalConfiguration';
37
38 /**
39 * Checks if localconf.php is available. If so, the update should be done
40 *
41 * @param string &$description: The description for the update
42 * @return boolean TRUE if update should be done
43 */
44 public function checkForUpdate(&$description) {
45 $description = 'The localconfiguration file typo3conf/localconf.php is deprecated and ' . ' unused since TYPO3 6.0. This wizard migrates the content of the file to the new ' . ' format.';
46 $description .= '<br /><strong>It is strongly recommended to run this wizard now.</strong><br />';
47 $description .= 'The old localconf.php file is renamed to localconf.obsolete.php and can' . ' be manually removed if everything works.';
48 $result = FALSE;
49 if (@is_file((PATH_typo3conf . 'localconf.php'))) {
50 $result = TRUE;
51 }
52 return $result;
53 }
54
55 /**
56 * Performs the update action.
57 *
58 * The methods reads localconf.php line by line and classifies every line
59 * to be either part of LocalConfiguration (everything that starts with TYPO3_CONF_VARS),
60 * belongs to the database settings (those will be merged to TYPO3_CONF_VARS),
61 * and everything else (those will be moved to the AdditionalConfiguration file.
62 *
63 * @param array &$dbQueries: Queries done in this update
64 * @param mixed &$customMessages: Custom messages
65 * @return boolean TRUE if everything went well
66 */
67 public function performUpdate(array &$dbQueries, &$customMessages) {
68 $result = FALSE;
69 try {
70 $localConfigurationContent = file(PATH_typo3conf . 'localconf.php');
71
72 // Line array for the three categories: localConfiguration, db settings, additionalConfiguration
73 $typo3ConfigurationVariables = array();
74 $typo3DatabaseVariables = array();
75 $additionalConfiguration = array();
76 foreach ($localConfigurationContent as $line) {
77 $line = trim($line);
78 $matches = array();
79 // Convert extList to array
80 if (
81 preg_match('/^\\$TYPO3_CONF_VARS\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1
82 || preg_match('/^\\$GLOBALS\\[\'TYPO3_CONF_VARS\'\\]\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1
83 ) {
84 $extListAsArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $matches[1], TRUE);
85 $typo3ConfigurationVariables[] = '$TYPO3_CONF_VARS[\'EXT\'][\'extListArray\'] = ' . var_export($extListAsArray, TRUE) . ';';
86 } elseif (
87 preg_match('/^\\$TYPO3_CONF_VARS.+;{1}/', $line, $matches) === 1
88 ) {
89 $typo3ConfigurationVariables[] = $matches[0];
90 } elseif (
91 preg_match('/^\\$GLOBALS\\[\'TYPO3_CONF_VARS\'\\].+;{1}/', $line, $matches) === 1
92 ) {
93 $lineWithoutGlobals = str_replace('$GLOBALS[\'TYPO3_CONF_VARS\']', '$TYPO3_CONF_VARS', $matches[0]);
94 $typo3ConfigurationVariables[] = $lineWithoutGlobals;
95 } elseif (
96 preg_match('/^\\$typo_db.+;{1}/', $line, $matches) === 1
97 ) {
98 eval($matches[0]);
99 if (isset($typo_db_host)) {
100 $typo3DatabaseVariables['host'] = $typo_db_host;
101 } elseif (isset($typo_db)) {
102 $typo3DatabaseVariables['database'] = $typo_db;
103 } elseif (isset($typo_db_username)) {
104 $typo3DatabaseVariables['username'] = $typo_db_username;
105 } elseif (isset($typo_db_password)) {
106 $typo3DatabaseVariables['password'] = $typo_db_password;
107 } elseif (isset($typo_db_extTableDef_script)) {
108 $typo3DatabaseVariables['extTablesDefinitionScript'] = $typo_db_extTableDef_script;
109 }
110 unset($typo_db_host, $typo_db, $typo_db_username, $typo_db_password, $typo_db_extTableDef_script);
111 } elseif (
112 strlen($line) > 0 && preg_match('/^\\/\\/.+|^#.+|^<\\?php$|^<\\?$|^\\?>$/', $line, $matches) === 0
113 ) {
114 $additionalConfiguration[] = $line;
115 }
116 }
117
118 // Build new TYPO3_CONF_VARS array
119 $TYPO3_CONF_VARS = NULL;
120 eval(implode(LF, $typo3ConfigurationVariables));
121
122 // Add db settings to array
123 $TYPO3_CONF_VARS['DB'] = $typo3DatabaseVariables;
124 $TYPO3_CONF_VARS = \TYPO3\CMS\Core\Utility\ArrayUtility::sortByKeyRecursive($TYPO3_CONF_VARS);
125
126 // Write out new LocalConfiguration file
127 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->writeLocalConfiguration($TYPO3_CONF_VARS);
128
129 // Write out new AdditionalConfiguration file
130 if (sizeof($additionalConfiguration) > 0) {
131 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->writeAdditionalConfiguration($additionalConfiguration);
132 } else {
133 @unlink(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getAdditionalConfigurationFileLocation());
134 }
135
136 rename(PATH_site . 'typo3conf/localconf.php', PATH_site . 'typo3conf/localconf.obsolete.php');
137 $result = TRUE;
138 } catch (\Exception $e) {
139
140 }
141 return $result;
142 }
143
144 }
145
146
147 ?>