[TASK] Release installation procedure from LocalConfiguration file
[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 (preg_match('/^\\$TYPO3_CONF_VARS\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1) {
81 $extListAsArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $matches[1], TRUE);
82 $typo3ConfigurationVariables[] = '$TYPO3_CONF_VARS[\'EXT\'][\'extListArray\'] = ' . var_export($extListAsArray, TRUE) . ';';
83 } elseif (preg_match('/^\\$TYPO3_CONF_VARS.+;{1}/', $line, $matches) === 1) {
84 $typo3ConfigurationVariables[] = $matches[0];
85 } elseif (preg_match('/^\\$typo_db.+;{1}/', $line, $matches) === 1) {
86 eval($matches[0]);
87 if (isset($typo_db_host)) {
88 $typo3DatabaseVariables['host'] = $typo_db_host;
89 } elseif (isset($typo_db)) {
90 $typo3DatabaseVariables['database'] = $typo_db;
91 } elseif (isset($typo_db_username)) {
92 $typo3DatabaseVariables['username'] = $typo_db_username;
93 } elseif (isset($typo_db_password)) {
94 $typo3DatabaseVariables['password'] = $typo_db_password;
95 } elseif (isset($typo_db_extTableDef_script)) {
96 $typo3DatabaseVariables['extTablesDefinitionScript'] = $typo_db_extTableDef_script;
97 }
98 unset($typo_db_host, $typo_db, $typo_db_username, $typo_db_password, $typo_db_extTableDef_script);
99 } elseif (strlen($line) > 0 && preg_match('/^\\/\\/.+|^#.+|^<\\?php$|^<\\?$|^\\?>$/', $line, $matches) === 0) {
100 $additionalConfiguration[] = $line;
101 }
102 }
103
104 // Build new TYPO3_CONF_VARS array
105 $TYPO3_CONF_VARS = NULL;
106 eval(implode(LF, $typo3ConfigurationVariables));
107
108 // Add db settings to array
109 $TYPO3_CONF_VARS['DB'] = $typo3DatabaseVariables;
110 $TYPO3_CONF_VARS = \TYPO3\CMS\Core\Utility\ArrayUtility::sortByKeyRecursive($TYPO3_CONF_VARS);
111
112 // Write out new LocalConfiguration file
113 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->writeLocalConfiguration($TYPO3_CONF_VARS);
114
115 // Write out new AdditionalConfiguration file
116 if (sizeof($additionalConfiguration) > 0) {
117 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->writeAdditionalConfiguration($additionalConfiguration);
118 } else {
119 @unlink(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getAdditionalConfigurationFileLocation());
120 }
121
122 rename(PATH_site . 'typo3conf/localconf.php', PATH_site . 'typo3conf/localconf.obsolete.php');
123 $result = TRUE;
124 } catch (\Exception $e) {
125
126 }
127 return $result;
128 }
129
130 }
131
132
133 ?>