]> git.mjollnir.org Git - moodle.git/commitdiff
During installation, if the database isn't UTF and it is empty,
authormoodler <moodler>
Fri, 14 Apr 2006 11:57:11 +0000 (11:57 +0000)
committermoodler <moodler>
Fri, 14 Apr 2006 11:57:11 +0000 (11:57 +0000)
then try and set it to UTF automatically.

I did MySQL only, can someone tackle this for PostgreSQL?

install.php

index 87c0d5622a42f81a0c3058ac4364c300d888eac0..8b60494cbf174b530e069826d1a076eb52b9b421 100644 (file)
@@ -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;