From: moodler Date: Fri, 14 Apr 2006 11:57:11 +0000 (+0000) Subject: During installation, if the database isn't UTF and it is empty, X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b1e64385dc591b48d56d0c01eab1810887f34064;p=moodle.git During installation, if the database isn't UTF and it is empty, then try and set it to UTF automatically. I did MySQL only, can someone tackle this for PostgreSQL? --- diff --git a/install.php b/install.php index 87c0d5622a..8b60494cbf 100644 --- a/install.php +++ b/install.php @@ -294,13 +294,29 @@ if ($INSTALL['stage'] == DATABASE) { if ($rs && $rs->RecordCount() > 0) { $records = $rs->GetAssoc(true); $encoding = $records['character_set_database']['Value']; - if (strtoupper($encoding) != 'UTF8') { - $errormsg = get_string('dbwrongencoding', 'install', $encoding); - $nextstage = DATABASE; - $INSTALL['showskipdbencodingtest'] = true; - $INSTALL['dbencodingtestresults'] = false; - } else { + if (strtoupper($encoding) == 'UTF8') { $INSTALL['dbencodingtestresults'] = true; + } else { + // 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 + + $records = $rs->GetAssoc(true); + $encoding = $records['character_set_database']['Value']; + + if (strtoupper($encoding) == 'UTF8') { + $INSTALL['dbencodingtestresults'] = true; + } else { + $errormsg = get_string('dbwrongencoding', 'install', $encoding); + $nextstage = DATABASE; + $INSTALL['showskipdbencodingtest'] = true; + $INSTALL['dbencodingtestresults'] = false; + } + } else { + $INSTALL['showskipdbencodingtest'] = true; + $INSTALL['dbencodingtestresults'] = false; + } } } break;