MDL-22306 PHP_EOL is used when creating config.php

This commit is contained in:
David Mudrak 2010-05-10 12:51:49 +00:00
parent d7bd9acd9c
commit 6189e63d52

View File

@ -125,52 +125,53 @@ function install_db_validate($database, $dbhost, $dbuser, $dbpass, $dbname, $pre
/**
* Returns content of config.php file.
*
* Uses PHP_EOL for generating proper end of lines for the given platform.
*
* @param moodle_database $database database instance
* @param object $cfg copy of $CFG
* @param bool $userealpath allows symbolic links in dirroot
* @return string
*/
function install_generate_configphp($database, $cfg, $userealpath=false) {
$configphp = '<?php // Moodle Configuration File ' . "\r\n\r\n";
$configphp = '<?php // Moodle Configuration File ' . PHP_EOL . PHP_EOL;
$configphp .= 'unset($CFG);'."\r\n";
$configphp .= '$CFG = new stdClass();'."\r\n\r\n"; // prevent PHP5 strict warnings
$configphp .= 'unset($CFG);' . PHP_EOL;
$configphp .= '$CFG = new stdClass();' . PHP_EOL . PHP_EOL; // prevent PHP5 strict warnings
$dbconfig = $database->export_dbconfig();
foreach ($dbconfig as $key=>$value) {
$key = str_pad($key, 9);
$configphp .= '$CFG->'.$key.' = '.var_export($value, true).";\r\n";
$configphp .= '$CFG->'.$key.' = '.var_export($value, true) . ';' . PHP_EOL;
}
$configphp .= "\r\n";
$configphp .= PHP_EOL;
$configphp .= '$CFG->wwwroot = '.var_export($cfg->wwwroot, true).";\r\n";
$configphp .= '$CFG->wwwroot = '.var_export($cfg->wwwroot, true) . ';' . PHP_EOL ;
if ($userealpath) {
$dirroot = str_replace('\\', '/', $cfg->dirroot); // win32 fix
$dirroot = rtrim($dirroot, '/'); // no trailing /
$configphp .= '$CFG->dirroot = realpath('.var_export($dirroot, true).");\r\n"; // fix for sym links
$configphp .= '$CFG->dirroot = realpath('.var_export($dirroot, true).');' . PHP_EOL; // fix for sym links
} else {
$dirroot = str_replace('\\', '/', $cfg->dirroot); // win32 fix
$dirroot = rtrim($dirroot, '/'); // no trailing /
$configphp .= '$CFG->dirroot = '.var_export($dirroot, true).";\r\n";
$configphp .= '$CFG->dirroot = '.var_export($dirroot, true) . ';' . PHP_EOL;
}
$dataroot = str_replace('\\', '/', $cfg->dataroot); // win32 fix
$dataroot = rtrim($dataroot, '/'); // no trailing /
$configphp .= '$CFG->dataroot = '.var_export($dataroot, true).";\r\n";
$configphp .= '$CFG->dataroot = '.var_export($dataroot, true) . ';' . PHP_EOL;
$configphp .= '$CFG->admin = '.var_export($cfg->admin, true).";\r\n\r\n";
$configphp .= '$CFG->admin = '.var_export($cfg->admin, true) . ';' . PHP_EOL . PHP_EOL;
$configphp .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
$configphp .= "\r\n";
$configphp .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode' . PHP_EOL . PHP_EOL;
$configphp .= '$CFG->passwordsaltmain = '.var_export(complex_random_string(), true).";\r\n";
$configphp .= "\r\n";
$configphp .= '$CFG->passwordsaltmain = '.var_export(complex_random_string(), true) . ';' . PHP_EOL . PHP_EOL;
$configphp .= 'require_once("$CFG->dirroot/lib/setup.php");'."\r\n\r\n";
$configphp .= '// There is no php closing tag in this file,'."\r\n";
$configphp .= '// it is intentional because it prevents trailing whitespace problems!'."\r\n";
$configphp .= 'require_once("$CFG->dirroot/lib/setup.php");' . PHP_EOL . PHP_EOL;
$configphp .= '// There is no php closing tag in this file,' . PHP_EOL;
$configphp .= '// it is intentional because it prevents trailing whitespace problems!' . PHP_EOL;
return $configphp;
}