[!!!][TASK] Rewrite install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Tool / AllConfiguration.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Tool;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
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 use TYPO3\CMS\Install\Controller\Action;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30 /**
31 * Show system environment check results
32 */
33 class AllConfiguration extends Action\AbstractAction implements Action\ActionInterface {
34
35 /**
36 * Handle this action
37 *
38 * @return string content
39 */
40 public function handle() {
41 $this->initialize();
42
43 if (isset($this->postValues['set']['write'])) {
44 $this->view->assign('configurationValuesSaved', TRUE);
45 $this->view->assign('savedConfigurationValueMessages', $this->updateLocalConfigurationValues());
46 } else {
47 $this->view->assign('data', $this->setUpConfigurationData());
48 }
49
50 return $this->view->render();
51 }
52
53 /**
54 * Set up configuration data
55 *
56 * @return array Configuration data
57 */
58 protected function setUpConfigurationData() {
59 $data = array();
60 foreach ($GLOBALS['TYPO3_CONF_VARS'] as $sectionName => $sectionData) {
61 $data[$sectionName] = array();
62
63 foreach ($sectionData as $key => $value) {
64 if (isset($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key])) {
65 // Don't allow editing stuff which is added by extensions
66 // Make sure we fix potentially duplicated entries from older setups
67 $potentialValue = str_replace(array('\'.chr(10).\'', '\' . LF . \''), array(LF, LF), $value);
68 while (preg_match('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue)) {
69 $potentialValue = preg_replace('/' . preg_quote($GLOBALS['TYPO3_CONF_VARS_extensionAdded'][$sectionName][$key], '/') . '$/', '', $potentialValue);
70 }
71 $value = $potentialValue;
72 }
73
74 $commentArray = $this->getDefaultConfigArrayComments();
75 $description = trim($commentArray[$sectionName][$key]);
76 $isTextarea = preg_match('/^(<.*?>)?string \\(textarea\\)/i', $description) ? TRUE : FALSE;
77 $doNotRender = preg_match('/^(<.*?>)?string \\(exclude\\)/i', $description) ? TRUE : FALSE;
78
79 if (!is_array($value) && !$doNotRender && (!preg_match('/[' . LF . CR . ']/', $value) || $isTextarea)) {
80 $itemData = array();
81 $itemData['key'] = $key;
82 $itemData['description'] = $description;
83 if ($isTextarea) {
84 $itemData['type'] = 'textarea';
85 $itemData['value'] = str_replace(array('\'.chr(10).\'', '\' . LF . \''), array(LF, LF), $value);
86 } elseif (preg_match('/^(<.*?>)?boolean/i', $description)) {
87 $itemData['type'] = 'checkbox';
88 $itemData['value'] = $value && strcmp($value, '0') ? $value : 1;
89 $itemData['checked'] = $value ? TRUE : FALSE;
90 } else {
91 $itemData['type'] = 'input';
92 $itemData['value'] = $value;
93 }
94 $data[$sectionName][] = $itemData;
95 }
96 }
97 }
98 return $data;
99 }
100
101 /**
102 * Store changed values in LocalConfiguration
103 *
104 * @return string Status messages of changed values
105 */
106 protected function updateLocalConfigurationValues() {
107 $statusObjects = array();
108 if (isset($this->postValues['values']) && is_array($this->postValues['values'])) {
109 $configurationPathValuePairs = array();
110 $commentArray = $this->getDefaultConfigArrayComments();
111 $formValues = $this->postValues['values'];
112 foreach ($formValues as $section => $valueArray) {
113 if (is_array($GLOBALS['TYPO3_CONF_VARS'][$section])) {
114 foreach ($valueArray as $valueKey => $value) {
115 if (isset($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey])) {
116 $description = trim($commentArray[$section][$valueKey]);
117 if (preg_match('/^string \\(textarea\\)/i', $description)) {
118 // Force Unix linebreaks in textareas
119 $value = str_replace(CR, '', $value);
120 // Preserve linebreaks
121 $value = str_replace(LF, '\' . LF . \'', $value);
122 }
123 if (preg_match('/^boolean/i', $description)) {
124 // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE"
125 // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1".
126 // Therefore, reset the values to their boolean equivalent.
127 if ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === FALSE && $value === '0') {
128 $value = FALSE;
129 } elseif ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === TRUE && $value === '1') {
130 $value = TRUE;
131 }
132 }
133 // Save if value changed
134 if (strcmp($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey], $value)) {
135 $configurationPathValuePairs[$section . '/' . $valueKey] = $value;
136 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
137 $status = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\OkStatus');
138 $status->setTitle('$TYPO3_CONF_VARS[\'' . $section . '\'][\'' . $valueKey . '\']');
139 $status->setMessage('New value = ' . $value);
140 $statusObjects[] = $status;
141 }
142 }
143 }
144 }
145 }
146 if (count($statusObjects)) {
147 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
148 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
149 $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationPathValuePairs);
150 }
151 }
152 return $statusObjects;
153 }
154
155 /**
156 * Make an array of the comments in the EXT:core/Configuration/DefaultConfiguration.php file
157 *
158 * @return array
159 */
160 protected function getDefaultConfigArrayComments() {
161 /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
162 $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
163 $string = GeneralUtility::getUrl($configurationManager->getDefaultConfigurationFileLocation());
164
165 $commentArray = array();
166 $lines = explode(LF, $string);
167 $in = 0;
168 $mainKey = '';
169 foreach ($lines as $lc) {
170 $lc = trim($lc);
171 if ($in) {
172 if (!strcmp($lc, ');')) {
173 $in = 0;
174 } else {
175 if (preg_match('/["\']([[:alnum:]_-]*)["\'][[:space:]]*=>(.*)/i', $lc, $reg)) {
176 preg_match('/,[\\t\\s]*\\/\\/(.*)/i', $reg[2], $creg);
177 $theComment = trim($creg[1]);
178 if (substr(strtolower(trim($reg[2])), 0, 5) == 'array' && !strcmp($reg[1], strtoupper($reg[1]))) {
179 $mainKey = trim($reg[1]);
180 } elseif ($mainKey) {
181 $commentArray[$mainKey][$reg[1]] = $theComment;
182 }
183 }
184 }
185 }
186 if (!strcmp($lc, 'return array(')) {
187 $in = 1;
188 }
189 }
190 return $commentArray;
191 }
192 }
193 ?>