Commit 624363ca authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add check for db collation mismatches (bug #489023)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 7478a05a
...@@ -45,6 +45,7 @@ else { ...@@ -45,6 +45,7 @@ else {
global $SESSION; global $SESSION;
$SESSION->add_error_msg(get_string('dbnotutf8warning', 'admin')); $SESSION->add_error_msg(get_string('dbnotutf8warning', 'admin'));
} }
ensure_upgrade_sanity();
$smarty->assign('upgradeheading', get_string('performingupgrades', 'admin')); $smarty->assign('upgradeheading', get_string('performingupgrades', 'admin'));
} }
......
...@@ -61,6 +61,7 @@ $string['youcanupgrade'] = 'You can upgrade Mahara from %s (%s) to %s (%s)!'; ...@@ -61,6 +61,7 @@ $string['youcanupgrade'] = 'You can upgrade Mahara from %s (%s) to %s (%s)!';
$string['Plugin'] = 'Plugin'; $string['Plugin'] = 'Plugin';
$string['jsrequiredforupgrade'] = 'You must enable javascript to perform an install or upgrade.'; $string['jsrequiredforupgrade'] = 'You must enable javascript to perform an install or upgrade.';
$string['dbnotutf8warning'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. You may still attempt this upgrade but it is recommended that you convert your database to UTF-8.'; $string['dbnotutf8warning'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. You may still attempt this upgrade but it is recommended that you convert your database to UTF-8.';
$string['dbcollationmismatch'] = 'A column of your database is using a collation that is not the same as the database default. Please ensure all columns use the same collation as the database.';
// Admin navigation menu // Admin navigation menu
$string['adminhome'] = 'Admin home'; $string['adminhome'] = 'Admin home';
......
...@@ -83,6 +83,23 @@ function db_is_utf8() { ...@@ -83,6 +83,23 @@ function db_is_utf8() {
return false; return false;
} }
function column_collation_is_default($table, $column) {
global $db;
if (!is_a($db, 'ADOConnection')) {
throw new SQLException('Database connection is not available ');
}
if (is_mysql()) {
$result = $db->Execute("SHOW VARIABLES LIKE 'collation_database'");
$defaultcollation = $result->fields['Value'];
$command = 'SHOW FULL COLUMNS FROM ' . db_table_name($table) . ' WHERE field = ?';
$stmt = $db->Prepare($command);
$result = $db->Execute($stmt, array($column));
return $result->fields['Collation'] == $defaultcollation;
}
return true;
}
/** /**
* Execute a given sql command string * Execute a given sql command string
* *
......
...@@ -172,6 +172,18 @@ function ensure_install_sanity() { ...@@ -172,6 +172,18 @@ function ensure_install_sanity() {
} }
} }
function ensure_upgrade_sanity() {
// Check column collation is equal to the default
if (is_mysql()) {
require_once('ddl.php');
if (table_exists(new XMLDBTable('event_type'))) {
if (!column_collation_is_default('event_type', 'name')) {
throw new ConfigSanityException(get_string('dbcollationmismatch', 'admin'));
}
}
}
}
/** /**
* Check to see if the internal plugins are installed. Die if they are not. * Check to see if the internal plugins are installed. Die if they are not.
*/ */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment