Commit c3038f1a authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Show useful message on install/upgrade without triggers (bug #967001)

If the MySQL user doesn't have trigger permission, an SQLException was
thrown along with an unhelpful generic error message.  This privilege
is now checked before beginning the install/upgrade, and the message
is now informative.

Change-Id: If35750610cdc84e97bf8f2974d496dea43b8b991
Signed-off-by: default avatarRichard Mansfield <>
parent 6bb50530
......@@ -71,6 +71,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 in your database manually. For instructions on how to do this, see\'s_Guide/Enabling_Plpgsql';
$string['mysqlnotriggerprivilege'] = 'Mahara requires permission to create database triggers, but is unable to do so. Please ensure that the trigger privilege has been granted to the appropriate user in your MySQL installation. For instructions on how to do this, see\'s_Guide/Granting_Trigger_Privilege';
// general exception error messages
$string['blocktypenametaken'] = "Block type %s is already taken by another plugin (%s)";
......@@ -1718,6 +1718,29 @@ function postgres_create_language($language) {
return postgres_language_exists($language);
function mysql_has_trigger_privilege() {
// Finding out whether the current user has trigger permission
// seems to be quite hard. It would require parsing the output
// from SHOW GRANTS. It's much easier to try and create one.
execute_sql("CREATE TABLE {testtable} (testcolumn INT);");
try {
execute_sql("CREATE TRIGGER {testtrigger} BEFORE INSERT ON {testtable} FOR EACH ROW BEGIN END;");
execute_sql("DROP TRIGGER {testtrigger};");
$success = true;
catch (SQLException $e) {
// Instead of dying with a generic SQLException, return false below and
// let the caller decide what to do when the trigger cannot be created,
// e.g. throw a ConfigSanityException with a useful error message.
$success = false;
execute_sql("DROP TABLE {testtable};");
return $success;
* Creates a database row trigger
......@@ -183,6 +183,9 @@ function ensure_install_sanity() {
if (is_postgres() && !postgres_create_language('plpgsql')) {
throw new ConfigSanityException(get_string('plpgsqlnotavailable', 'error'));
if (is_mysql() && !mysql_has_trigger_privilege()) {
throw new ConfigSanityException(get_string('mysqlnotriggerprivilege', 'error'));
function ensure_upgrade_sanity() {
......@@ -194,6 +197,9 @@ function ensure_upgrade_sanity() {
throw new ConfigSanityException(get_string('dbcollationmismatch', 'admin'));
if (!mysql_has_trigger_privilege()) {
throw new ConfigSanityException(get_string('mysqlnotriggerprivilege', 'error'));
if (is_postgres() && !postgres_create_language('plpgsql')) {
throw new ConfigSanityException(get_string('plpgsqlnotavailable', 'error'));
Supports Markdown
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