diff --git a/install/stringnames.txt b/install/stringnames.txt index 68507dc7955..0e94de5b2cc 100644 --- a/install/stringnames.txt +++ b/install/stringnames.txt @@ -1,5 +1,6 @@ admindirname,install availablelangs,install +cannotcreatedboninstall,error cannotcreatelangdir,error cannotcreatetempdir,error cannotdownloadcomponents,error @@ -28,6 +29,7 @@ databasetypehead,install dataroot,install datarootpermission,install dbprefix,install +dmlexceptiononinstall,error dirroot,install downloadedfilecheckfailed,error environmenthead,install diff --git a/lang/en/error.php b/lang/en/error.php index 76a2d752b55..3ad6125b4f2 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -46,6 +46,9 @@ $string['cannotcallscript'] = 'You cannot call this script in that way'; $string['cannotcallusgetselecteduser'] = 'You cannot call user_selector::get_selected_user if multi select is true.'; $string['cannotcreatebackupdir'] = 'Could not create backupdata folder. The site administrator needs to fix the file permissions'; $string['cannotcreatecategory'] = 'The category was not inserted'; +$string['cannotcreatedboninstall'] = '

Cannot create the database.

+

The specified database does not exist and the given user does not have permission to create the database.

+

The site administrator should verify database configuration.

'; $string['cannotcreategroup'] = 'Error creating group'; $string['cannotcreatelangbase'] = 'Error: Could not create base lang directory'; $string['cannotcreatelangdir'] = 'Cannot create lang directory'; @@ -203,6 +206,7 @@ $string['ddlunknownerror'] = 'Unknown DDL library error'; $string['ddlxmlfileerror'] = 'XML database file errors found'; $string['destinationcmnotexit'] = 'The destination course module does not exist'; $string['detectedbrokenplugin'] = 'Plugin "{$a}" is defective or outdated, can not continue, sorry.'; +$string['dmlexceptiononinstall'] = '

A database error has occurred [{$a->errorcode}].
{$a->debuginfo}

'; $string['dmlreadexception'] = 'Error reading from database'; $string['dmltransactionexception'] = 'Database transaction error'; $string['dmlwriteexception'] = 'Error writing to database'; diff --git a/lib/installlib.php b/lib/installlib.php index 30e129770f1..4bf474ea7dc 100644 --- a/lib/installlib.php +++ b/lib/installlib.php @@ -192,7 +192,20 @@ function install_db_validate($database, $dbhost, $dbuser, $dbpass, $dbname, $pre } return ''; } catch (dml_exception $ex) { - return get_string($ex->errorcode, $ex->module, $ex->a).'
'.$ex->debuginfo; + $stringmanager = get_string_manager(); + $errorstring = $ex->errorcode.'oninstall'; + $legacystring = $ex->errorcode; + if ($stringmanager->string_exists($errorstring, $ex->module)) { + // By using a different string id from the error code we are separating exception handling and output. + return $stringmanager->get_string($errorstring, $ex->module, $ex->a).'
'.$ex->debuginfo; + } else if ($stringmanager->string_exists($legacystring, $ex->module)) { + // There are some DML exceptions that may be thrown here as well as during normal operation. + // If we have a translated message already we still want to serve it here. + // However it is not the preferred way. + return $stringmanager->get_string($legacystring, $ex->module, $ex->a).'
'.$ex->debuginfo; + } + // No specific translation. Deliver a generic error message. + return $stringmanager->get_string('dmlexceptiononinstall', 'error', $ex); } }