[TASK] Remove extList from LocalConfiguration
[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 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 // Line array for the three categories: localConfiguration, db settings, additionalConfiguration
72 $typo3ConfigurationVariables = array();
73 $typo3DatabaseVariables = array();
74 $additionalConfiguration = array();
75 foreach ($localConfigurationContent as $line) {
76 $line = trim($line);
77 $matches = array();
78 // Convert extList to array
79 if (preg_match('/^\\$TYPO3_CONF_VARS\\[\'EXT\'\\]\\[\'extList\'\\] *={1} *\'(.+)\';{1}/', $line, $matches) === 1) {
80 $extListAsArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $matches[1], TRUE);
81 $typo3ConfigurationVariables[] = '$TYPO3_CONF_VARS[\'EXT\'][\'extListArray\'] = ' . var_export($extListAsArray, TRUE) . ';';
82 } elseif (preg_match('/^\\$TYPO3_CONF_VARS.+;{1}/', $line, $matches) === 1) {
83 $typo3ConfigurationVariables[] = $matches[0];
84 } elseif (preg_match('/^\\$typo_db.+;{1}/', $line, $matches) === 1) {
85 eval($matches[0]);
86 if (isset($typo_db_host)) {
87 $typo3DatabaseVariables['host'] = $typo_db_host;
88 } elseif (isset($typo_db)) {
89 $typo3DatabaseVariables['database'] = $typo_db;
90 } elseif (isset($typo_db_username)) {
91 $typo3DatabaseVariables['username'] = $typo_db_username;
92 } elseif (isset($typo_db_password)) {
93 $typo3DatabaseVariables['password'] = $typo_db_password;
94 } elseif (isset($typo_db_extTableDef_script)) {
95 $typo3DatabaseVariables['extTablesDefinitionScript'] = $typo_db_extTableDef_script;
96 }
97 unset($typo_db_host, $typo_db, $typo_db_username, $typo_db_password, $typo_db_extTableDef_script);
98 } elseif (strlen($line) > 0 && preg_match('/^\\/\\/.+|^#.+|^<\\?php$|^<\\?$|^\\?>$/', $line, $matches) === 0) {
99 $additionalConfiguration[] = $line;
100 }
101 }
102 // Build new TYPO3_CONF_VARS array
103 $TYPO3_CONF_VARS = NULL;
104 eval(implode(LF, $typo3ConfigurationVariables));
105 // Add db settings to array
106 $TYPO3_CONF_VARS['DB'] = $typo3DatabaseVariables;
107 $TYPO3_CONF_VARS = \TYPO3\CMS\Core\Utility\ArrayUtility::sortByKeyRecursive($TYPO3_CONF_VARS);
108 // Build new (empty) LocalConfiguration file if not exists as the function writeLocalConfiguration depends on it
109 \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(
110 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->getLocalConfigurationFileResource(),
111 ''
112 );
113 // Write out new LocalConfiguration file
114 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager')->writeLocalConfiguration($TYPO3_CONF_VARS);
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')->getAdditionalConfigurationFileResource());
120 }
121 rename(PATH_site . 'typo3conf/localconf.php', PATH_site . 'typo3conf/localconf.obsolete.php');
122 $result = TRUE;
123 } catch (\Exception $e) {
124
125 }
126 return $result;
127 }
128
129 }
130
131
132 ?>