MDL-39575 install: better handling of database creation error.

Implemented better handling of DML exceptions.
Added translation for cannotcreatedb exception.
This commit is contained in:
Sam Hemelryk 2013-05-10 17:28:31 +12:00
parent 8b5647b8d7
commit 1168a5f2e3
3 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -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'] = '<p>Cannot create the database.</p>
<p>The specified database does not exist and the given user does not have permission to create the database.</p>
<p>The site administrator should verify database configuration.</p>';
$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'] = '<p>A database error has occurred [{$a->errorcode}].<br />{$a->debuginfo}</p>';
$string['dmlreadexception'] = 'Error reading from database';
$string['dmltransactionexception'] = 'Database transaction error';
$string['dmlwriteexception'] = 'Error writing to database';

View File

@ -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).'<br />'.$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).'<br />'.$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).'<br />'.$ex->debuginfo;
}
// No specific translation. Deliver a generic error message.
return $stringmanager->get_string('dmlexceptiononinstall', 'error', $ex);
}
}