Skip to content
Snippets Groups Projects
Commit ba9c9674 authored by Sean Comeau's avatar Sean Comeau
Browse files

Throw an exception when creating a MySQL user fails and display exception error text to user

parent 23dd7f1b
No related branches found
No related tags found
No related merge requests found
......@@ -70,9 +70,10 @@ class OC_Setup {
try {
self::setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username);
} catch (Exception $e) {
$msgs = explode('|', $e->getMessage());
$error[] = array(
'error' => 'MySQL username and/or password not valid',
'hint' => 'You need to enter either an existing account or the administrator.'
'error' => $msgs[0],
'hint' => $msgs[1]
);
return($error);
}
......@@ -166,7 +167,7 @@ class OC_Setup {
//check if the database user has admin right
$connection = @mysql_connect($dbhost, $dbuser, $dbpass);
if(!$connection) {
throw new Exception('MySQL username and/or password not valid');
throw new Exception('MySQL username and/or password not valid|You need to enter either an existing account or the administrator.');
}
$oldUser=OC_Config::getValue('dbuser', false);
......@@ -229,8 +230,14 @@ class OC_Setup {
// the anonymous user would take precedence when there is one.
$query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
throw new Exception("MySQL user '" . "$name" . "'@'localhost' already exists|Delete this user from MySQL.");
}
$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
throw new Exception("MySQL user '" . "$name" . "'@'%' already exists|Delete this user from MySQL.");
}
}
private static function setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment