Installer fixed, prefixes improved, moved conn settings to connect() and some more improvements. MDL-14864

This commit is contained in:
stronk7
2008-05-19 18:02:33 +00:00
parent 6395aa3f98
commit 6d5a22b208
20 changed files with 603 additions and 344 deletions
-9
View File
@@ -94,15 +94,6 @@
print_error('withoutversion', 'debug'); // without version, stop
}
/// Check DB prefix requirements are fulfilled
if (empty($CFG->prefix) && $DB->get_dbfamily() != 'mysql') { //Enforce prefixes for everybody but mysql
print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype));
}
if ($DB->get_dbfamily() == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
print_error('prefixlimit', 'debug', '', $CFG->prefix);
}
/// Check if the main tables have been installed yet or not.
if (!$tables = $DB->get_tables() ) { // No tables yet at all.
$maintables = false;
+126 -212
View File
@@ -59,7 +59,7 @@ if ( empty($INSTALL['language']) and empty($_POST['language']) ) {
$INSTALL['dbhost'] = 'localhost';
$INSTALL['dbuser'] = '';
$INSTALL['dbpass'] = '';
$INSTALL['dbtype'] = 'mysql';
$INSTALL['dbtype'] = 'mysqli_adodb';
$INSTALL['dbname'] = 'moodle';
$INSTALL['prefix'] = 'mdl_';
@@ -150,7 +150,7 @@ require_once($CFG->libdir.'/setuplib.php');
require_once($CFG->libdir.'/moodlelib.php');
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->libdir.'/deprecatedlib.php');
require_once($CFG->libdir.'/adodb/adodb.inc.php');
require_once($CFG->libdir.'/dmllib.php');
require_once($CFG->libdir.'/environmentlib.php');
require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->libdir.'/componentlib.class.php');
@@ -160,10 +160,22 @@ require_once($CFG->dirroot.'/version.php');
$INSTALL['version'] = $version;
$INSTALL['release'] = $release;
/// Have the $db object ready because we are going to use it often
define ('ADODB_ASSOC_CASE', 0); //Use lowercase fieldnames for ADODB_FETCH_ASSOC
$db = &ADONewConnection($INSTALL['dbtype']);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
/// list all supported drivers - unsupported must be installed manually ;-)
$supported = array (
'mysqli_adodb',
'mysql_adodb',
'postgres7_adodb',
'mssql_n_adodb',
'mssql_adodb',
'odbc_mssql_adodb',
'oci8po_adodb'
);
$databases = array ();
foreach($supported as $driver) {
$classname = $driver.'_moodle_database';
require_once ("$CFG->libdir/dml/$classname.php");
$databases[$driver] = new $classname ();
}
/// guess the www root
if ($INSTALL['wwwroot'] == '') {
@@ -241,31 +253,32 @@ if ($INSTALL['stage'] == DIRECTORY) {
error_reporting(0);
/// check wwwroot
if (ini_get('allow_url_fopen') && false) { /// This was not reliable
if (ini_get('allow_url_fopen') && false) { /// This was not reliable
if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) {
$errormsg .= get_string('wwwrooterror', 'install').'<br />';
$INSTALL['wwwrootform'] = $INSTALL['wwwroot'];
fclose($fh);
}
}
if ($fh) fclose($fh);
/// check dirroot
if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) {
if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false) {
$errormsg .= get_string('dirrooterror', 'install').'<br />';
$INSTALL['dirrootform'] = $INSTALL['dirroot'];
fclose($fh);
}
if ($fh) fclose($fh);
/// check dataroot
$CFG->dataroot = $INSTALL['dataroot'];
if (make_upload_directory('sessions', false) === false ) {
if (make_upload_directory('sessions', false) === false) {
$errormsg .= get_string('datarooterror', 'install').'<br />';
}
if ($fh) fclose($fh);
if (!empty($errormsg)) $nextstage = DIRECTORY;
if (!empty($errormsg)) {
$nextstage = DIRECTORY;
}
error_reporting(7);
error_reporting(38911);
}
@@ -277,87 +290,36 @@ if ($INSTALL['stage'] == DIRECTORY) {
if ($INSTALL['stage'] == DATABASE) {
/// different format for postgres7 by socket
if ($INSTALL['dbtype'] == 'postgres7' and ($INSTALL['dbhost'] == 'localhost' || $INSTALL['dbhost'] == '127.0.0.1')) {
$INSTALL['dbhost'] = "user='{$INSTALL['dbuser']}' password='{$INSTALL['dbpass']}' dbname='{$INSTALL['dbname']}'";
$INSTALL['dbuser'] = '';
$INSTALL['dbpass'] = '';
$INSTALL['dbname'] = '';
$DB = $databases[$INSTALL['dbtype']];
if ($INSTALL['prefix'] == '') { /// must have a prefix
$INSTALL['prefix'] = 'mdl_';
}
$dbfamily = $DB->get_dbfamily();
$errormsg = $DB->driver_installed();
if ($errormsg === true) {
$errormsg = '';
} else {
$nextstage = DATABASE;
}
if ($INSTALL['dbtype'] == 'mysql') { /// Check MySQL extension is present
if (!extension_loaded('mysql')) {
$errormsg = get_string('mysqlextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'mysqli') { /// Check MySQLi extension is present
if (!extension_loaded('mysqli')) {
$errormsg = get_string('mysqliextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'postgres7') { /// Check PostgreSQL extension is present
if (!extension_loaded('pgsql')) {
$errormsg = get_string('pgsqlextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'mssql') { /// Check MSSQL extension is present
if (!function_exists('mssql_connect')) {
$errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'mssql_n') { /// Check MSSQL extension is present
if (!function_exists('mssql_connect')) {
$errormsg = get_string('mssqlextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'odbc_mssql') { /// Check ODBC extension is present
if (!extension_loaded('odbc')) {
$errormsg = get_string('odbcextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if ($INSTALL['dbtype'] == 'oci8po') { /// Check OCI extension is present
if (!extension_loaded('oci8')) {
$errormsg = get_string('ociextensionisnotpresentinphp', 'install');
$nextstage = DATABASE;
}
}
if (empty($INSTALL['prefix']) && $INSTALL['dbtype'] != 'mysql' && $INSTALL['dbtype'] != 'mysqli') { // All DBs but MySQL require prefix (reserv. words)
if (empty($INSTALL['prefix']) and $dbfamily != 'mysql') { // All DBs but MySQL require prefix (reserv. words)
$errormsg = get_string('dbwrongprefix', 'install');
$nextstage = DATABASE;
}
if ($INSTALL['dbtype'] == 'oci8po' && strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
if ($dbfamily == 'oracle' and strlen($INSTALL['prefix']) > 2) { // Oracle max prefix = 2cc (30cc limit)
$errormsg = get_string('dbwrongprefix', 'install');
$nextstage = DATABASE;
}
if ($INSTALL['dbtype'] == 'oci8po' && !empty($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
if ($dbfamily == 'oracle' and !empty ($INSTALL['dbhost'])) { // Oracle host must be blank (tnsnames.ora has it)
$errormsg = get_string('dbwronghostserver', 'install');
$nextstage = DATABASE;
}
if (empty($errormsg)) {
error_reporting(0); // Hide errors
if (! $dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname'])) {
if (! $dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix'])) {
$db->database = ''; // reset database name cached by ADODB. Trick from MDL-9609
if ($dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'])) { /// Try to connect without DB
switch ($INSTALL['dbtype']) { /// Try to create a database
@@ -373,41 +335,14 @@ if ($INSTALL['stage'] == DATABASE) {
}
}
} else {
/// We have been able to connect properly, just test the database encoding now.
/// It must be Unicode for 1.8 installations.
$encoding = '';
switch ($INSTALL['dbtype']) {
case 'mysql':
case 'mysqli':
/// Get MySQL character_set_database value
$rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
if ($rs && !$rs->EOF) {
$records = $rs->GetAssoc(true);
$encoding = $records['character_set_database']['Value'];
if (strtoupper($encoding) != 'UTF8') {
/// Try to set the encoding now!
if (! $db->Metatables()) { // We have no tables so go ahead
$db->Execute("ALTER DATABASE `".$INSTALL['dbname']."` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
$rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'"); // this works
}
}
/// If conversion fails, skip, let environment testing do the job
}
break;
case 'postgres7':
/// Skip, let environment testing do the job
break;
case 'oci8po':
/// Skip, let environment testing do the job
break;
}
// TODO: db encoding checks ??
}
}
error_reporting(7);
error_reporting(38911);
if (($dbconnected === false) and (empty($errormsg)) ) {
/// Output db connection error
if ((empty($errormsg) and ($dbconnected === false)) ) {
$errormsg = get_string('dbconnectionerror', 'install');
$nextstage = DATABASE;
}
@@ -441,9 +376,11 @@ if ($nextstage == ADMIN or $INSTALL['stage'] == ADMIN) {
// Check if we can navigate from the environemt page (because it's ok)
if ($INSTALL['stage'] == ENVIRONMENT) {
$DB = $databases[$INSTALL['dbtype']];
error_reporting(0); // Hide errors
$dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
error_reporting(7); // Show errors
$dbconnected = $DB->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
error_reporting(38911); // Show errors
if ($dbconnected) {
/// Execute environment check, printing results
if (!check_moodle_environment($INSTALL['release'], $environment_results, false)) {
@@ -500,7 +437,7 @@ if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
//We shouldn't reach this point
}
error_reporting(7); // Show errors
error_reporting(38911); // Show errors
if ($downloadsuccess) {
$INSTALL['downloadlangpack'] = false;
@@ -523,28 +460,36 @@ if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) {
if ($nextstage == SAVE) {
$str = '<?php /// Moodle Configuration File '."\r\n";
$str = '<?php /// Moodle Configuration File ' . "\r\n";
$str .= "\r\n";
$str .= 'unset($CFG);'."\r\n";
$str .= '$CFG = new stdClass();'."\r\n"; // prevent PHP5 strict warnings
$str .= "\r\n";
$str .= '$CFG->dbtype = \''.$INSTALL['dbtype']."';\r\n";
$str .= '$CFG->dbhost = \''.addslashes($INSTALL['dbhost'])."';\r\n";
if (!empty($INSTALL['dbname'])) {
$str .= '$CFG->dbname = \''.$INSTALL['dbname']."';\r\n";
// support single quotes in db user/passwords
$str .= '$CFG->dbuser = \''.addsingleslashes($INSTALL['dbuser'])."';\r\n";
$str .= '$CFG->dbpass = \''.addsingleslashes($INSTALL['dbpass'])."';\r\n";
$database = $databases[$INSTALL['dbtype']];
$database->connect($INSTALL['dbhost'], $INSTALL['dbuser'], $INSTALL['dbpass'], $INSTALL['dbname'], false, $INSTALL['prefix']);
$dbconfig = $database->export_dbconfig();
$dbconfig->persistent = false;
foreach ($dbconfig as $key=>$value) {
$key = str_pad($key, 9);
if (is_bool($value)) {
if ($value) {
$str .= '$CFG->'.$key.' = true;'."\r\n";
} else {
$str .= '$CFG->'.$key.' = false;'."\r\n";
}
} else {
$str .= '$CFG->'.$key.' = \''.addsingleslashes($value)."';\r\n";
}
}
$str .= '$CFG->dbpersist = false;'."\r\n";
$str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n";
$str .= "\r\n";
$str .= '$CFG->wwwroot = \''.s($INSTALL['wwwrootform'],true)."';\r\n";
$str .= '$CFG->dirroot = \''.s($INSTALL['dirrootform'],true)."';\r\n";
$str .= '$CFG->dataroot = \''.s($INSTALL['dataroot'],true)."';\r\n";
$str .= '$CFG->admin = \''.s($INSTALL['admindirname'],true)."';\r\n";
$str .= '$CFG->wwwroot = \''.addsingleslashes($INSTALL['wwwrootform'])."';\r\n";
$str .= '$CFG->dirroot = \''.addsingleslashes($INSTALL['dirrootform'])."';\r\n";
$str .= '$CFG->dataroot = \''.addsingleslashes($INSTALL['dataroot'])."';\r\n";
$str .= '$CFG->admin = \''.addsingleslashes($INSTALL['admindirname'])."';\r\n";
$str .= "\r\n";
$str .= '$CFG->directorypermissions = 00777; // try 02777 on a server in Safe Mode'."\r\n";
@@ -577,8 +522,8 @@ if ($nextstage == SAVE) {
<link rel="shortcut icon" href="theme/standard/favicon.ico" />
<title>Moodle Install</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<?php css_styles() ?>
<?php database_js() ?>
<?php css_styles($databases) ?>
<?php database_js($databases) ?>
</head>
@@ -609,52 +554,12 @@ if (isset($_GET['help'])) {
<?php /// Exceptionaly, depending of the DB selected, we show some different text
/// from the standard one to show better instructions for each DB
if ($nextstage == DATABASE) {
echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
echo '<div id="mysql">' . get_string('databasesettingssub_mysql', 'install');
echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
echo '</div>';
echo '<div id="mysqli">' . get_string('databasesettingssub_mysqli', 'install');
echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
echo '</div>';
echo '<div id="postgres7">' . get_string('databasesettingssub_postgres7', 'install') . '</div>';
echo '<div id="mssql">' . get_string('databasesettingssub_mssql', 'install');
/// Link to mssql installation page
echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
echo ">";
echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
echo get_string('moodledocslink', 'install') . '</a></p>';
echo '</div>';
echo '<div id="mssql_n">' . get_string('databasesettingssub_mssql_n', 'install');
/// Link to mssql installation page
echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
echo ">";
echo '<img src="pix/docs.gif' . '" alt="Docs" />';
echo get_string('moodledocslink', 'install') . '</a></p>';
echo '</div>';
echo '<div id="odbc_mssql">'. get_string('databasesettingssub_odbc_mssql', 'install');
/// Link to mssql installation page
echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
echo ">";
echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
echo get_string('moodledocslink', 'install') . '</a></p>';
echo '</div>';
echo '<div id="oci8po">' . get_string('databasesettingssub_oci8po', 'install');
/// Link to oracle installation page
echo "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
echo "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
echo ">";
echo '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
echo get_string('moodledocslink', 'install') . '</a></p>';
echo '</div>';
foreach ($databases as $driver=>$database) {
echo '<script type="text/javascript" defer="defer">window.onload=toggledbinfo;</script>';
echo '<div id="'.$driver.'">' . $database->get_configuration_hints();
echo '<p style="text-align: center">' . get_string('databasesettingswillbecreated', 'install') . '</p>';
echo '</div>';
}
} else {
if (!empty($substagetext[$nextstage])) {
echo '<p class="p_subheading">' . $substagetext[$nextstage] . '</p>';
@@ -709,13 +614,13 @@ if ($nextstage == SAVE) {
echo "<hr />\n";
echo "<div style=\"text-align: ".fix_align_rtl("left")."\">\n";
echo "<pre>\n";
print_r(s($str));
p($INSTALL['config']);
echo "</pre>\n";
echo "</div>\n";
}
} else {
$formaction = (isset($_GET['configfile'])) ? "install.php?configfile=".$_GET['configfile'] : "install.php";
form_table($nextstage, $formaction);
form_table($nextstage, $formaction, $databases);
}
?>
@@ -745,7 +650,7 @@ if ($nextstage == SAVE) {
//==========================================================================//
function form_table($nextstage = WELCOME, $formaction = "install.php") {
function form_table($nextstage, $formaction, $databases) {
global $INSTALL, $db;
/// Print the standard form if we aren't in the DOWNLOADLANG page
@@ -829,14 +734,19 @@ function form_table($nextstage = WELCOME, $formaction = "install.php") {
<tr>
<td class="td_left"><p class="p_install"><?php print_string('dbtype', 'install') ?></p></td>
<td class="td_right">
<?php choose_from_menu (array('mysql' => get_string('mysql', 'install'),
'mysqli' => get_string('mysqli', 'install'),
'oci8po' => get_string('oci8po', 'install'),
'postgres7' => get_string('postgres7', 'install'),
'mssql' => get_string('mssql', 'install'),
'mssql_n' => get_string('mssql_n', 'install'),
'odbc_mssql' => get_string('odbc_mssql', 'install')),
'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();') ?>
<?php
$options = array ();
foreach ($databases as $type => $database) {
$name = $database->get_name();
if ($database->driver_installed() !== true) {
$name = "$name - driver not installed"; // TODO: improve missing driver notification
}
$options[$type] = $name;
}
choose_from_menu($options, 'dbtype', $INSTALL['dbtype'], '', 'toggledbinfo();')
?>
</td>
</tr>
<tr>
@@ -893,7 +803,7 @@ function form_table($nextstage = WELCOME, $formaction = "install.php") {
<?php
error_reporting(0); // Hide errors
$dbconnected = $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
error_reporting(7); // Show errors
error_reporting(38911); // Show errors
if ($dbconnected) {
/// Execute environment check, printing results
check_moodle_environment($INSTALL['release'], $environment_results, true);
@@ -1114,7 +1024,7 @@ function get_installer_list_of_languages() {
//==========================================================================//
function css_styles() {
function css_styles($databases) {
?>
<style type="text/css">
@@ -1194,7 +1104,7 @@ function css_styles() {
margin-bottom: 16px;
}
.p_mainheader{
text-align: right;
text-align: right;
font-size: 20pt;
font-weight: bold;
margin-top: 0px;
@@ -1228,11 +1138,11 @@ function css_styles() {
margin-bottom: 0px;
}
/* This override the p tag for every p tag in this installation script,
but not in lang\xxx\installer.php
but not in lang\xxx\installer.php
*/
.p_install {
margin-top: 0px;
margin-bottom: 0px;
margin-bottom: 0px;
}
.environmenttable {
font-size: 10pt;
@@ -1273,7 +1183,14 @@ function css_styles() {
padding:0px;
margin:0px;
}
#mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
<?php
$list = array();
foreach ($databases as $driver=>$unused) {
$list[] = '#'.$driver;
}
$list = implode(',', $list);
echo ($list);
?> {
display: none;
}
@@ -1284,7 +1201,7 @@ function css_styles() {
//==========================================================================//
function database_js() {
function database_js($databases) {
?>
<script type="text/javascript" defer="defer">
@@ -1296,37 +1213,34 @@ function toggledbinfo() {
}
if (document.getElementById) {
//Hide all the divs
document.getElementById('mysql').style.display = '';
document.getElementById('mysqli').style.display = '';
document.getElementById('postgres7').style.display = '';
document.getElementById('mssql').style.display = '';
document.getElementById('mssql_n').style.display = '';
document.getElementById('odbc_mssql').style.display = '';
document.getElementById('oci8po').style.display = '';
<?php
$list = array();
foreach ($databases as $driver=>$unused) {
echo "document.getElementById('$driver').style.display = '';";
}
?>
//Show the selected div
document.getElementById(showid).style.display = 'block';
} else if (document.all) {
//This is the way old msie versions work
//Hide all the divs
document.all['mysql'].style.display = '';
document.all['mysqli'].style.display = '';
document.all['postgres7'].style.display = '';
document.all['mssql'].style.display = '';
document.all['mssql_n'].style.display = '';
document.all['odbc_mssql'].style.display = '';
document.all['oci8po'].style.display = '';
<?php
$list = array();
foreach ($databases as $driver=>$unused) {
echo "document.all['$driver'].style.display = '';";
}
?>
//Show the selected div
document.all[showid].style.display = 'block';
} else if (document.layers) {
//This is the way nn4 works
//Hide all the divs
document.layers['mysql'].style.display = '';
document.layers['mysqli'].style.display = '';
document.layers['postgres7'].style.display = '';
document.layers['mssql'].style.display = '';
document.layers['mssql_n'].style.display = '';
document.layers['odbc_mssql'].style.display = '';
document.layers['oci8po'].style.display = '';
<?php
$list = array();
foreach ($databases as $driver=>$unused) {
echo "document.layers['$driver'].style.display = '';";
}
?>
//Show the selected div
document.layers[showid].style.display = 'block';
}
+1 -1
View File
@@ -139,7 +139,7 @@ $string['configintrosite'] = 'This page allows you to configure the front page a
$string['configintrotimezones'] = 'This page will search for new information about world timezones (including daylight savings time rules) and update your local database with this information. These locations will be checked, in order: $a This procedure is generally very safe and can not break normal installations. Do you wish to update your timezones now?';
$string['configiplookup'] = 'When you click on an IP address (such as 34.12.222.93), such as in the logs, you are shown a map with a best guess of where that IP is located. There are different plugins for this that you can choose from, each has benefits and disadvantages.';
$string['configkeeptagnamecase'] = 'Check this if you want tag names to keep the original casing as entered by users who created them';
$string['configlang'] = 'Choose a default language for the whole site. Users can override this setting later.';
$string['configlang'] = 'Choose a default language for the whole site. Users can override this setting later. You can also set \$CFG->lang=\"yourlangcode_utf8\"; in config.php if you want localised error messages for database connection problems.';
$string['configlangcache'] = 'Cache the language menu. Saves a lot of memory and processing power. If you enable this, the menu takes a few minutes to update after you have added or removed languages.';
$string['configlangdir'] = 'Most languages are printed left-to-right, but some, like Arabic and Hebrew, are printed right-to-left.';
$string['configlanglist'] = 'Leave this blank to allow users to choose from any language you have in this installation of Moodle. However, you can shorten the language menu by entering a comma-separated list of language codes that you want. For example: en,es_es,fr,it';
+2 -2
View File
@@ -24,8 +24,8 @@ $string['noreports'] = 'No reports accessible';
$string['nomodules'] = 'No modules found!!';
$string['phpvaroff'] = 'The PHP server variable \'$a[0]\' should be Off - $a[1]';
$string['phpvaron'] = 'The PHP server variable \'$a[0]\' is not turned On - $a[1]';
$string['prefixcannotbeempty'] = 'Table prefix \"$a[0]\" cannot be empty for your target DB ($a[1])';
$string['prefixlimit'] = 'Table prefix \"$a\" maximum allowed length for Oracle DBs is 2cc.';
$string['prefixcannotbeempty'] = 'Table prefix \"$a[0]\" cannot be empty for your target DB ($a[1])'; // obsoleted 2.0
$string['prefixlimit'] = 'Table prefix \"$a\" maximum allowed length for Oracle DBs is 2cc.'; // obsoleted in 2.0
$string['withoutversion'] = 'Main version.php was not readable or specified';
$string['sessionmissing'] = '$a object missing from session';
$string['siteisnotdefined'] = 'Site is not defined!';
+9
View File
@@ -117,6 +117,11 @@ $string['csvfewcolumns'] = 'Not enough columns, please verify the delimiter sett
$string['csvinvalidcolsnum'] = 'INVALID CSV FILE; Each line must include 49 or 70 fields';
$string['csvinvalidcols'] = '<b>INVALID CSV FILE:</b> First line must include "Header Fields" and the file must be type of <br />"Expanded Fields/Comma Separated"<br />or<br /> "Expanded Fields with CAVV Result Code/Comma Separated"';
$string['csvweirdcolumns'] = 'Invalid CSV file format - number of columns is not constant!';
$string['dbconnectionfailed'] = '<p>Error: Database connection failed.</p>
<p>It is possible that the database is overloaded or otherwise not running properly.</p>
<p>The site administrator should also check that the database details have been correctly specified in config.php</p>$a';
$string['dbdriverproblem'] = '<p>Error: database driver problem detected</p>
<p>The site administrator should verify server configuration</p><p>$a</p>';
$string['dbupdatefailed'] = 'Database update failed.';
$string['destinationcmnotexit'] = 'The destination course module does not exist';
$string['downloadedfilecheckfailed'] = 'Downloaded file check failed.';
@@ -255,6 +260,10 @@ $string['pagenotexist'] = 'An unusual error occurred (tried to reach a page that
$string['pathdoesnotstartslash'] = 'No valid arguments supplied, path does not start with slash!';
$string['pleasereport'] = 'If you have time, please let us know what you were trying to do when the error occurred:';
$string['pluginrequirementsnotmet'] = 'Plugin \"$a->pluginname\" ($a->pluginversion) could not be installed. It requires a newer version of Moodle (currently you are using $a->currentmoodle, you need $a->requiremoodle).';
$string['prefixcannotbeempty'] = '<p>Error: database table prefix can not be empty ($a)</p>
<p>The site administrator must fix this problem.</p>';
$string['prefixtoolong'] = '<p>Error: database table prefix is too long ($a->dbfamily)</p>
<p>The site administrator must fix this problem. Maximum length for table prefixes in $a->dbfamily is $a->maxlength characters.</p>';
$string['processingstops'] = 'Processing stops here. Remaining records ignored.';
$string['refoundtoorigi'] = 'Refunded to original amount: $a';
$string['refoundto'] = 'Can be refunded to $a';
+55 -4
View File
@@ -1,6 +1,5 @@
<?php //$Id$
require_once($CFG->libdir.'/adodb/adodb.inc.php');
require_once($CFG->libdir.'/dml/moodle_database.php');
require_once($CFG->libdir.'/dml/adodb_moodle_recordset.php');
@@ -13,11 +12,57 @@ abstract class adodb_moodle_database extends moodle_database {
protected $db;
protected $columns = array(); // I wish we had a shared memory cache for this :-(
public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
/**
* Returns localised database type name
* Note: can be used before connect()
* @return string
*/
public function get_name() {
$dbtype = $this->get_dbtype();
return get_string($dbtype, 'install');
}
public function connect() {
/**
* Returns db related part of config.php
* Note: can be used before connect()
* @return string
*/
public function export_dbconfig() {
$cfg = new stdClass();
$cfg->dbtype = $this->get_dbtype();
$cfg->library = 'adodb';
$cfg->dbhost = $this->dbhost;
$cfg->dbname = $this->dbname;
$cfg->dbuser = $this->dbuser;
$cfg->dbpass = $this->dbpass;
$cfg->prefix = $this->prefix;
return $cfg;
}
//TODO: preconfigure_dbconnection(): Decide if this should be declared as abstract because all adodb drivers will need it
/**
* Adodb preconnection routines, ususally sets up needed defines;
*/
protected function preconfigure_dbconnection() {
// empty
}
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbname = $dbname;
$this->dbpersist = $dbpersist;
$this->prefix = $prefix;
$this->dboptions = (array)$dboptions;
global $CFG;
$this->preconfigure_dbconnection();
require_once($CFG->libdir.'/adodb/adodb.inc.php');
$this->db = ADONewConnection($this->get_dbtype());
global $db; $db = $this->db; // TODO: BC only for now
@@ -39,10 +84,15 @@ abstract class adodb_moodle_database extends moodle_database {
return true;
}
//TODO: configure_dbconnection(): Decide if this should be declared as abstract because all adodb drivers will need it
/**
* Adodb post connection routines, usually sets up encoding,e tc.
*/
protected function configure_dbconnection() {
// empty
}
//TODO: make all dblibraries return this info in a structured way (new server_info class or so, like database_column_info class)
/**
* Returns database server info array
* @return array
@@ -185,6 +235,7 @@ abstract class adodb_moodle_database extends moodle_database {
return $result;
}
//TODO: do we want the *_raw() functions being public? I see the benefits but... won't that cause problems. To decide.
/**
* Insert new record into database, as fast as possible, no safety checks, lobs not supported.
* @param string $table name
+75 -41
View File
@@ -6,12 +6,7 @@
*/
abstract class moodle_database {
/**
* supports :name, "?" or both types of parameters?
* must be set in implementing class constructor
*/
protected $param_types;
// manipulates the db structure
protected $database_manager;
// db connection options
@@ -22,66 +17,105 @@ abstract class moodle_database {
protected $dbpersist;
protected $prefix;
/**
* Non-moodle external database used.
*/
protected $external;
/**
* Database or driver specific options, such as sockets or TCPIP db connections
*/
protected $dboptions;
// TODO: perf stuff goes here
// TODO: do we really need record caching??
/**
* Contructor - sets up database connection, prints error in case of problem.
* @param string $dbhost
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param string $dbpersist
* @param string $prefix table prefix
* Contructor - instantiates the database, specifying if it's external (connect to other systems) or no (Moodle DB)
* note this has effect to decide if prefix checks must be performed or no
* @param bool true means external database used
*/
public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->dbname = $dbname;
$this->dbpersist = $dbpersist;
$this->prefix = $prefix;
public function __construct($external=false) {
$this->external = $external;
}
/**
* Detects if all needed PHP stuff installed.
* Note: can be used before connect()
* @return mixed true if ok, string if something
*/
public abstract function driver_installed();
/**
* Returns database table prefix
* Note: can be used before connect()
* @return string database table prefix
*/
public function get_prefix() {
return $this->prefix;
}
/**
* Returns database family type - describes SQL dialect
* Note: can be used before connect()
* @return string db family name (mysql, postgres, mssql, oracle, etc.)
*/
public abstract function get_dbfamily();
/**
* Returns more specific database driver type
* Note: can be used before connect()
* @return string db type mysql, mysqli, postgres7
*/
protected abstract function get_dbtype();
/**
* Returns localised database type name
* Note: can be used before connect()
* @return string
*/
public abstract function get_name();
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public abstract function get_configuration_hints();
/**
* Returns db related part of config.php
* Note: can be used before connect()
* @return string
*/
public abstract function export_dbconfig();
/**
* Connect to db
* Must be called before other methods.
* @param string $dbhost
* @param string $dbuser
* @param string $dbpass
* @param string $dbname
* @param bool $dbpersist
* @param mixed $prefix string means moodle db prefix, false used for external databases where prefix not used
* @param array $dboptions driver specific options
* @return bool success
*/
public abstract function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null);
/**
* Returns database server info array
* @return array
*/
public abstract function get_server_info();
/**
* Returns database table prefix
* @return string database table prefix
*/
public function get_prefix() {
return $this->prefix;
}
/**
* Returns database type
* @return string db type mysql, mysqli, postgres7
*/
protected abstract function get_dbtype();
/**
* Returns supported query parameter types
* @return bitmask
*/
protected abstract function allowed_param_types();
/**
* Connect to db specified in constructor
* Must be called before any other methods.
* @return bool success
*/
public abstract function connect();
/**
* Returns last error reported by database engine.
*/
+38 -3
View File
@@ -8,14 +8,34 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php');
* @package dmlib
*/
class mssql_adodb_moodle_database extends adodb_moodle_database {
function __construct ($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, false, $prefix);
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily());
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
}
protected function configure_dbconnection() {
/**
* Detects if all needed PHP stuff installed.
* Do not connect to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!function_exists('mssql_connect')) {
return get_string('mssqlextensionisnotpresentinphp', 'install');
}
return true;
}
protected function preconfigure_dbconnection() {
if (!defined('ADODB_ASSOC_CASE')) {
define ('ADODB_ASSOC_CASE', 2);
}
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
/// No need to set charset. It must be specified in the driver conf
@@ -49,6 +69,21 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
return 'mssql';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
$str = get_string('databasesettingssub_mssql', 'install');
$str .= "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
$str .= "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
$str .= ">";
$str .= '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
$str .= get_string('moodledocslink', 'install') . '</a></p>';
return $str;
}
/**
* Returns supported query parameter types
* @return bitmask
+15 -3
View File
@@ -9,9 +9,6 @@ require_once($CFG->libdir.'/dml/mssql_adodb_moodle_database.php');
* @package dmlib
*/
class mssql_n_adodb_moodle_database extends mssql_adodb_moodle_database {
function __construct ($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, false, $prefix);
}
/**
* Returns database type
@@ -21,4 +18,19 @@ class mssql_n_adodb_moodle_database extends mssql_adodb_moodle_database {
return 'mssql_n';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
$str = get_string('databasesettingssub_mssql_n', 'install');
$str .= "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
$str .= "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
$str .= ">";
$str .= '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
$str .= get_string('moodledocslink', 'install') . '</a></p>';
return $str;
}
}
+20 -2
View File
@@ -9,8 +9,17 @@ require_once($CFG->libdir.'/dml/mysqli_adodb_moodle_database.php');
* @package dmlib
*/
class mysql_adodb_moodle_database extends mysqli_adodb_moodle_database {
function __construct ($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
/**
* Detects if all needed PHP stuff installed.
* Do not try to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!extension_loaded('mysql')) {
return get_string('mysqlextensionisnotpresentinphp', 'install');
}
return true;
}
/**
@@ -21,4 +30,13 @@ class mysql_adodb_moodle_database extends mysqli_adodb_moodle_database {
return 'mysql';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
return get_string('databasesettingssub_mysql', 'install');
}
}
+24 -3
View File
@@ -8,14 +8,26 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php');
* @package dmlib
*/
class mysqli_adodb_moodle_database extends adodb_moodle_database {
function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
/**
* Detects if all needed PHP stuff installed.
* Do not connect to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!extension_loaded('mysqli')) {
return get_string('mysqliextensionisnotpresentinphp', 'install');
}
return true;
}
protected function configure_dbconnection() {
protected function preconfigure_dbconnection() {
if (!defined('ADODB_ASSOC_CASE')) {
define ('ADODB_ASSOC_CASE', 2);
}
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES 'utf8'");
return true;
@@ -37,6 +49,15 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
return 'mysqli';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
return get_string('databasesettingssub_mysqli', 'install');
}
/**
* Returns supported query parameter types
* @return bitmask
+55 -10
View File
@@ -8,12 +8,34 @@ require_once($CFG->libdir.'/dml/oci8po_adodb_moodle_recordset.php');
* Oracle database class using adodb backend
* @package dmlib
*/
class oci8_adodb_moodle_database extends adodb_moodle_database {
function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
class oci8po_adodb_moodle_database extends adodb_moodle_database {
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily());
}
if (!$this->external and strlen($prefix) > 2) {
//Max prefix length for Oracle is 2cc
$a = (object)array('dbfamily'=>'oracle', 'maxlength'=>2);
print_error('prefixtoolong', 'error', '', $a);
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
}
protected function configure_dbconnection() {
/**
* Detects if all needed PHP stuff installed.
* Do not connect to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!extension_loaded('oci8')) {
return get_string('ociextensionisnotpresentinphp', 'install');
}
return true;
}
protected function preconfigure_dbconnection() {
if (!defined('ADODB_ASSOC_CASE')) {
define ('ADODB_ASSOC_CASE', 0); /// Use lowercase fieldnames for ADODB_FETCH_ASSOC
/// (only meaningful for oci8po, it's the default
@@ -25,18 +47,22 @@ class oci8_adodb_moodle_database extends adodb_moodle_database {
if (!defined('ADODB_PREFETCH_ROWS')) {
define ('ADODB_PREFETCH_ROWS', 1000);
}
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
/// No need to set charset. It must be specified by the NLS_LANG env. variable
/// Enable sybase quotes, so addslashes and stripslashes will use "'"
ini_set('magic_quotes_sybase', '1');
/// NOTE: Not 100% useful because GPC has been addslashed with the setting off
/// so IT'S MANDATORY TO ENABLE THIS UNDER php.ini or .htaccess for this DB
/// or to turn off magic_quotes to allow Moodle to do it properly
/// Now set the decimal separator to DOT, Moodle & PHP will always send floats to
/// DB using DOTS. Manually introduced floats (if using other characters) must be
/// converted back to DOTs (like gradebook does)
$this->db->Execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'");
$this->db->Execute("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,'");
/// Enable sybase quotes, so addslashes and stripslashes will use "'"
ini_set('magic_quotes_sybase', '1');
/// NOTE: Not 100% useful because GPC has been addslashed with the setting off
/// so IT'S MANDATORY TO ENABLE THIS UNDER php.ini or .htaccess for this DB
/// or to turn off magic_quotes to allow Moodle to do it properly
return true;
}
@@ -57,6 +83,21 @@ class oci8_adodb_moodle_database extends adodb_moodle_database {
return 'oci8po';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
$str = get_string('databasesettingssub_oci8po', 'install');
$str .= "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
$str .= "onclick=\"return window.open('http://docs.moodle.org/en/Installing_Oracle_for_PHP')\"";
$str .= ">";
$str .= '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
$str .= get_string('moodledocslink', 'install') . '</a></p>';
return $str;
}
/**
* Returns supported query parameter types
* @return bitmask
@@ -458,6 +499,10 @@ error('todo');
return (integer)$id;
}
public function set_field_select($table, $newfield, $newvalue, $select, array $params=null) {
error('todo');
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
* Oracle moodle recordest with special hacks
* @package dmlib
*/
class oci8po_adodb_moodle_recordset implements adodb_moodle_recordset {
class oci8po_adodb_moodle_recordset extends adodb_moodle_recordset {
private $rs;
public function __construct($rs) {
+26 -2
View File
@@ -9,8 +9,17 @@ require_once($CFG->libdir.'/dml/mssql_adodb_moodle_database.php');
* @package dmlib
*/
class odbc_mssql_adodb_moodle_database extends mssql_adodb_moodle_database {
function __construct ($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, false, $prefix);
/**
* Detects if all needed PHP stuff installed.
* Do not connect to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!extension_loaded('odbc')) {
return get_string('odbcextensionisnotpresentinphp', 'install');
}
return true;
}
/**
@@ -21,4 +30,19 @@ class odbc_mssql_adodb_moodle_database extends mssql_adodb_moodle_database {
return 'odbc_mssql';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
$str = get_string('databasesettingssub_odbc_mssql', 'install');
$str .= "<p style='text-align:right'><a href=\"javascript:void(0)\" ";
$str .= "onclick=\"return window.open('http://docs.moodle.org/en/Installing_MSSQL_for_PHP')\"";
$str .= ">";
$str .= '<img src="pix/docs.gif' . '" alt="Docs" class="iconhelp" />';
$str .= get_string('moodledocslink', 'install') . '</a></p>';
return $str;
}
}
+4 -2
View File
@@ -12,8 +12,9 @@ abstract class pdo_moodle_database extends moodle_database {
protected $pdb;
protected $columns = array(); // I wish we had a shared memory cache for this :-(
public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
//TODO: This looks incorrect now IMO. Construct should have only external and connect get all the rest of params
public function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null, $external=false) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions, $external);
}
public function connect() {
@@ -26,6 +27,7 @@ abstract class pdo_moodle_database extends moodle_database {
}
}
///TODO: not needed preconfigure_dbconnection() stuff for PDO drivers?
protected function configure_dbconnection() {
}
+66 -13
View File
@@ -8,8 +8,38 @@ require_once($CFG->libdir.'/dml/adodb_moodle_database.php');
* @package dmlib
*/
class postgres7_adodb_moodle_database extends adodb_moodle_database {
function __construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix) {
parent::__construct($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix);
public function connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, array $dboptions=null) {
if ($prefix == '' and !$this->external) {
//Enforce prefixes for everybody but mysql
print_error('prefixcannotbeempty', 'error', '', $this->get_dbfamily());
}
return parent::connect($dbhost, $dbuser, $dbpass, $dbname, $dbpersist, $prefix, $dboptions);
}
/**
* Detects if all needed PHP stuff installed.
* Do not connect to connect to db if this test fails.
* @return mixed true if ok, string if something
*/
public function driver_installed() {
if (!extension_loaded('pgsql')) {
return get_string('pgsqlextensionisnotpresentinphp', 'install');
}
return true;
}
protected function preconfigure_dbconnection() {
if (!defined('ADODB_ASSOC_CASE')) {
define ('ADODB_ASSOC_CASE', 2);
}
}
protected function configure_dbconnection() {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES 'utf8'");
return true;
}
/**
@@ -28,6 +58,40 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
return 'postgres7';
}
/**
* Returns localised database description
* Note: can be used before connect()
* @return string
*/
public function get_configuration_hints() {
return get_string('databasesettingssub_postgres7', 'install');
}
/**
* Returns db related part of config.php
* Note: can be used before connect()
* @return string
*/
public function export_dbconfig() {
$cfg = new stdClass();
$cfg->dbtype = $this->get_dbtype();
$cfg->library = 'adodb';
if ($this->dbhost == 'localhost' or $this->dbhost == '127.0.0.1') {
$cfg->dbhost = "user='{$this->dbuser}' password='{$this->dbpass}' dbname='{$this->dbname}'";
$cfg->dbname = '';
$cfg->dbuser = '';
$cfg->dbpass = '';
} else {
$cfg->dbhost = $this->dbhost;
$cfg->dbname = $this->dbname;
$cfg->dbuser = $this->dbuser;
$cfg->dbpass = $this->dbpass;
}
$cfg->prefix = $this->prefix;
return $cfg;
}
/**
* Returns supported query parameter types
* @return bitmask
@@ -67,17 +131,6 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
return $this->columns[$table];
}
protected function configure_dbconnection() {
if (!defined('ADODB_ASSOC_CASE')) {
define ('ADODB_ASSOC_CASE', 2);
}
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES 'utf8'");
return true;
}
/**
* This method will introspect inside DB to detect it it's a UTF-8 DB or no
* Used from setup.php to set correctly "set names" when the installation
+34 -25
View File
@@ -86,10 +86,14 @@ function setup_DB() {
$CFG->dblibrary = 'adodb';
}
if (!isset($CFG->dboptions)) {
$CFG->dboptions = array();
}
if ($CFG->dblibrary == 'adodb') {
$classname = $CFG->dbtype.'_adodb_moodle_database';
require_once($CFG->libdir.'/dml/'.$classname.'.php');
$DB = new $classname($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix);
$DB = new $classname();
} else {
error('Not implemented db library yet: '.$CFG->dblibrary);
@@ -97,34 +101,39 @@ function setup_DB() {
$CFG->dbfamily = $DB->get_dbfamily(); // TODO: BC only for now
$prevdebug = error_reporting(E_ALL); // do not hide errors yet
if (!$DB->connect()) {
// In the name of protocol correctness, monitoring and performance
// profiling, set the appropriate error headers for machine comsumption
if (isset($_SERVER['SERVER_PROTOCOL'])) {
// Avoid it with cron.php. Note that we assume it's HTTP/1.x
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
}
// and then for human consumption...
echo '<html><body>';
echo '<table align="center"><tr>';
echo '<td style="color:#990000; text-align:center; font-size:large; border-width:1px; '.
' border-color:#000000; border-style:solid; border-radius: 20px; border-collapse: collapse; '.
' -moz-border-radius: 20px; padding: 15px">';
echo '<p>Error: Database connection failed.</p>';
echo '<p>It is possible that the database is overloaded or otherwise not running properly.</p>';
echo '<p>The site administrator should also check that the database details have been correctly specified in config.php</p>';
echo '</td></tr></table>';
echo '</body></html>';
$driverstatus = $DB->driver_installed();
if ($driverstatus !== true) {
print_error('dbdriverproblem', 'error', '', $driverstatus);
}
if (debugging('', DEBUG_ALL)) {
// catch errors
ob_start();
} else {
$prevdebug = error_reporting(0);
}
if (!$DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->dbpersist, $CFG->prefix, $CFG->dboptions)) {
if (debugging('', DEBUG_ALL)) {
if ($dberr = ob_get_contents()) {
$dberr = '<p><em>'.$dberr.'</em></p>';
}
ob_end_clean();
} else {
$dberr = '';
}
if (empty($CFG->noemailever) and !empty($CFG->emailconnectionerrorsto)) {
mail($CFG->emailconnectionerrorsto,
'WARNING: Database connection error: '.$CFG->wwwroot,
'Connection error: '.$CFG->wwwroot);
@mail($CFG->emailconnectionerrorsto,
'WARNING: Database connection error: '.$CFG->wwwroot,
'Connection error: '.$CFG->wwwroot);
}
die;
print_error('dbconnectionfailed', 'error', '', $dberr);
}
if (debugging('', DEBUG__ALL)) {
ob_end_clean();
} else {
error_reporting($prevdebug);
}
error_reporting($prevdebug);
return true;
}
+4 -1
View File
@@ -4993,8 +4993,11 @@ function current_language() {
} else if (!empty($USER->lang)) {
$return = $USER->lang;
} else {
} else if (isset($CFG->lang)) {
$return = $CFG->lang;
} else {
$return = 'en_utf8';
}
if ($return == 'en') {
+1 -8
View File
@@ -237,14 +237,7 @@ global $HTTPSPAGEREQUIRED;
/// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
if (!empty($CFG->version) and $CFG->version < 2007101509) {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.get_string('error').'</title>
</head><body>
<div style="text-align: center; margin-top:5em;background-color:orange;">'.get_string('upgraderequires19', 'error').'</div>
</body></html>';
print_error('upgraderequires19', 'error');
die;
}
+47 -2
View File
@@ -5623,6 +5623,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
* @param string $errorcode The name of the string from error.php to print
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
* @param object $a Extra words and phrases that might be required in the error string
* @return terminates script, does not return!
*/
function print_error ($errorcode, $module='', $link='', $a=NULL) {
@@ -5635,6 +5636,13 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) {
$modulelink = $module;
}
$message = get_string($errorcode, $module, $a);
if (!isset($CFG->theme)) {
// error found before setup.php finished
print_early_error($message);
}
if (empty($link) and !defined('ADMIN_EXT_HEADER_PRINTED')) {
if ( !empty($SESSION->fromurl) ) {
$link = $SESSION->fromurl;
@@ -5652,8 +5660,6 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) {
$errordocroot = 'http://docs.moodle.org';
}
$message = get_string($errorcode, $module, $a);
if (defined('FULLME') && FULLME == 'cron') {
// Errors in cron should be mtrace'd.
mtrace($message);
@@ -5696,6 +5702,45 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) {
die;
}
/**
* Internal function - do not use directly
* This function is used if fatal error occures before the themes are fully initialised (eg. in lib/setup.php)
* @param string $errorcode The name of the string from error.php to print
* @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
* @param object $a Extra words and phrases that might be required in the error string
* @return terminates script, does not return!
*/
function print_early_error($message) {
// In the name of protocol correctness, monitoring and performance
// profiling, set the appropriate error headers for machine comsumption
if (isset($_SERVER['SERVER_PROTOCOL'])) {
// Avoid it with cron.php. Note that we assume it's HTTP/1.x
@header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
}
// better disable any caching
@header('Content-Type: text/html; charset=utf-8');
@header('Cache-Control: no-store, no-cache, must-revalidate');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
@header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" '.get_html_lang().'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.get_string('error').'</title>
</head><body>
<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px;
border-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse;
width: 80%; -moz-border-radius: 20px; padding: 15px">
'.clean_text($message, FORMAT_HTML).'
</div>
</body></html>';
die;
}
/**
* Print an error to STDOUT and exit with a non-zero code. For commandline scripts.
* Default errorcode is 1.