[TASK] Install Tool: Store numbers and bool values properly 45/48345/7
authorBenni Mack <benni@typo3.org>
Fri, 27 May 2016 16:27:15 +0000 (18:27 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 20 Jul 2016 09:27:15 +0000 (11:27 +0200)
The install tool ("All Configuration") does not recognize boolean
or integer values, even though they are set in the comments section
of the DefaultConfiguration.php file.

This is changed into bool and even integer numbers to be cast correctly
when using All Configuration and storing the data into LocalConfiguration.php.

Resolves: #76336
Releases: master
Change-Id: I919d2390fd9e07438f77cfd7b76b2d19b6b08000
Reviewed-on: https://review.typo3.org/48345
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/install/Classes/Controller/Action/Tool/AllConfiguration.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/AllConfiguration/SubSection.html

index 92a7f80..4076470 100644 (file)
@@ -113,6 +113,9 @@ class AllConfiguration extends Action\AbstractAction
                         $itemData['type'] = 'checkbox';
                         $itemData['value'] = $value ? '1' : '0';
                         $itemData['checked'] = (bool)$value;
+                    } elseif (preg_match('/^(<.*?>)?integer/i', $description)) {
+                        $itemData['type'] = 'number';
+                        $itemData['value'] = (int)$value;
                     } else {
                         $itemData['type'] = 'input';
                         $itemData['value'] = $value;
@@ -146,30 +149,40 @@ class AllConfiguration extends Action\AbstractAction
                 if (is_array($GLOBALS['TYPO3_CONF_VARS'][$section])) {
                     foreach ($valueArray as $valueKey => $value) {
                         if (isset($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey])) {
+                            $oldValue = $GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey];
                             $description = trim($commentArray[$section][$valueKey]);
+
                             if (preg_match('/^string \\(textarea\\)/i', $description)) {
                                 // Force Unix linebreaks in textareas
                                 $value = str_replace(CR, '', $value);
                                 // Preserve linebreaks
                                 $value = str_replace(LF, '\' . LF . \'', $value);
                             }
-                            if (preg_match('/^boolean/i', $description)) {
+
+                            if (preg_match('/^(<.*?>)?boolean/i', $description)) {
                                 // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE"
                                 // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1".
-                                // Therefore, reset the values to their boolean equivalent.
-                                if ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === false && $value === '0') {
-                                    $value = false;
-                                } elseif ($GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] === true && $value === '1') {
-                                    $value = true;
-                                }
+                                $value = $value === '1';
+                                $valueHasChanged = (bool)$oldValue !== $value;
+                            } elseif (preg_match('/^(<.*?>)?integer/i', $description)) {
+                                // Cast integer values to integers (but only for values that can not contain a string as well)
+                                $value = (int)$value;
+                                $valueHasChanged = (int)$oldValue !== $value;
+                            } else {
+                                $valueHasChanged = (string)$oldValue !== (string)$value;
                             }
+
                             // Save if value changed
-                            if ((string)$GLOBALS['TYPO3_CONF_VARS'][$section][$valueKey] !== (string)$value) {
+                            if ($valueHasChanged) {
                                 $configurationPathValuePairs[$section . '/' . $valueKey] = $value;
                                 /** @var $message \TYPO3\CMS\Install\Status\StatusInterface */
                                 $status = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Status\OkStatus::class);
                                 $status->setTitle('$GLOBALS[\'TYPO3_CONF_VARS\'][\'' . $section . '\'][\'' . $valueKey . '\']');
-                                $status->setMessage('New value = ' . $value);
+                                if (is_bool($value)) {
+                                    $status->setMessage('New value = ' . ($value ? 'true' : 'false'));
+                                } else {
+                                    $status->setMessage('New value = ' . $value);
+                                }
                                 $statusObjects[] = $status;
                             }
                         }
index 6e2d402..eaf3356 100644 (file)
@@ -17,7 +17,7 @@
                                        <strong>[{sectionName}][{item.key}] </strong>
                                        <f:if condition="{item.type} == 'checkbox'">
                                                <f:then>
-                                                       = {item.value}
+                                                       = <f:if condition="{item.value}"><f:then>true</f:then><f:else>false</f:else></f:if>
                                                </f:then>
                                                <f:else>
                                                        <f:if condition="{item.value}">
                                                </div>
                                        </f:if>
 
+                                       <f:if condition="{item.type} == 'number'">
+                                               <div class="form-group">
+                                                       <span class="help-block">{item.description -> f:format.raw()}</span>
+                                                       <input
+                                                               type="number"
+                                                               value="{item.value}"
+                                                               name="install[values][{sectionName}][{item.key}]"
+                                                               class="t3-install-form-input-text form-control"
+                                                       />
+                                               </div>
+                                       </f:if>
+
                                        <f:if condition="{item.type} == 'textarea'">
                                                <span class="help-block">{item.description -> f:format.raw()}</span>
                                                <div class="form-group">