diff options
author | Sean Comeau <sean@ftlnetworks.ca> | 2013-01-10 14:43:08 -0800 |
---|---|---|
committer | Sean Comeau <sean@ftlnetworks.ca> | 2013-01-10 14:43:08 -0800 |
commit | ba9c967435ce62bb418c5c67eeb22184b009b24f (patch) | |
tree | 4fe48ace31ac1b85382b077bc30f93784cd5d32e | |
parent | 23dd7f1beaf9b567c1f3ec1438858cffc304dc13 (diff) | |
download | nextcloud-server-ba9c967435ce62bb418c5c67eeb22184b009b24f.tar.gz nextcloud-server-ba9c967435ce62bb418c5c67eeb22184b009b24f.zip |
Throw an exception when creating a MySQL user fails and display exception error text to user
-rw-r--r-- | lib/setup.php | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/setup.php b/lib/setup.php index fdd10be6824..9fa6aaf10b8 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -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) { |