Commit 9f517cc4 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Display a useful error message when PL/pgSQL is not available



Change-Id: Ib9a72a9e36bb24da5907720242b23e991bb7bf9a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 9276eed7
......@@ -70,6 +70,7 @@ The error received was:
';
$string['dbnotutf8'] = 'You are not using a UTF-8 database. Mahara stores all data as UTF-8 internally. Please drop and re-create your database using UTF-8 encoding.';
$string['dbversioncheckfailed'] = 'Your database server version is not new enough to successfully run Mahara. Your server is %s %s, but Mahara requires at least version %s.';
$string['plpgsqlnotavailable'] = 'The PL/pgSQL language is not enabled in your Postgres installation, and Mahara cannot enable it. Please install PL/pgSQL using the CREATE LANGUAGE command, or the createlang program.';
// general exception error messages
$string['blocktypenametaken'] = "Block type %s is already taken by another plugin (%s)";
......
......@@ -1688,3 +1688,23 @@ function db_interval($s) {
return "INTERVAL $s SECOND";
}
}
function postgres_language_exists($language) {
if (!is_postgres()) {
throw new SQLException('postgres_language_exists() expects a postgres database');
}
return get_field_sql('SELECT 1 FROM pg_catalog.pg_language WHERE lanname = ?', array($language)) == 1;
}
function postgres_create_language($language) {
if (!is_postgres()) {
throw new SQLException('postgres_create_language() expects a postgres database');
}
// CREATE LANGUAGE fails if the language already exists
if (postgres_language_exists($language)) {
return true;
}
execute_sql("CREATE LANGUAGE $language;");
return postgres_language_exists($language);
}
......@@ -180,6 +180,9 @@ function ensure_install_sanity() {
if (!db_is_utf8()) {
throw new ConfigSanityException(get_string('dbnotutf8', 'error'));
}
if (is_postgres() && !postgres_create_language('plpgsql')) {
throw new ConfigSanityException(get_string('plpgsqlnotavailable', 'error'));
}
}
function ensure_upgrade_sanity() {
......@@ -192,6 +195,9 @@ function ensure_upgrade_sanity() {
}
}
}
if (is_postgres() && !postgres_create_language('plpgsql')) {
throw new ConfigSanityException(get_string('plpgsqlnotavailable', 'error'));
}
}
/**
......
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