Improved OC_CONFIG::saveConfiguration()

* Support numeric types too
  * $WEBROOT variable was not necessary
remotes/origin/stable
Aldo "xoen" Giambelluca 15 years ago
parent fa9deac833
commit 47674cb473
  1. 11
      inc/lib_config.php

@ -113,23 +113,24 @@ class OC_CONFIG{
/** /**
* Write the configuration to the `config.php` file * Write the configuration to the `config.php` file
* *
* $configuration contains key/value * $configuration contains key/value pairs
* - the key is the option name without the 'CONFIG_' prefix * - the key is the option name without the 'CONFIG_' prefix
* - the value is a string or a boolean * - the value is a string, a boolean or a number
* *
* @param array $configuration is an associative array * @param array $configuration is an associative array
*/ */
protected static function saveConfiguration($configuration) { protected static function saveConfiguration($configuration) {
global $SERVERROOT; global $SERVERROOT;
global $WEBROOT;
$configContent = '<?php'; $configContent = '<?php';
foreach ( $configuration as $key => $value ) { foreach ( $configuration as $key => $value ) {
if ( is_string($value) ) { if ( is_string($value) ) {
$configContent .= "\n\$CONFIG_$key = '$value';"; $configContent .= "\n\$CONFIG_$key = '$value';"; // e.g. $CONFIG_DBTYPE = 'mysql';
} else if ( is_bool($value) ) { } else if ( is_bool($value) ) {
$value = $value ? 'true' : 'false'; $value = $value ? 'true' : 'false';
$configContent .= "\n\$CONFIG_$key = $value;"; $configContent .= "\n\$CONFIG_$key = $value;"; // e.g. $CONFIG_INSTALLED = true;
} else if ( is_numeric($value) ) {
$configContent .= "\n\$CONFIG_$key = $value;"; // e.g. $CONFIG_PI = 3.14;
} }
} }
$filename = "$SERVERROOT/config/config.php"; $filename = "$SERVERROOT/config/config.php";

Loading…
Cancel
Save