diff options
author | Frank Karlitschek <frank@owncloud.org> | 2013-01-16 22:38:57 -0800 |
---|---|---|
committer | Frank Karlitschek <frank@owncloud.org> | 2013-01-16 22:38:57 -0800 |
commit | d85e440aa174c06f805b2e25a80609d82399e147 (patch) | |
tree | ac158db1def4bea08dc33cd790c89701601c0293 | |
parent | 433fa192683764f909b73cabe73755c5dc503712 (diff) | |
parent | 0132a0b2cf1af95b4d56475dc80b576bccfab0d0 (diff) | |
download | nextcloud-server-d85e440aa174c06f805b2e25a80609d82399e147.tar.gz nextcloud-server-d85e440aa174c06f805b2e25a80609d82399e147.zip |
Merge pull request #1148 from seancomeau/topic/setup
Fix issue #108
-rw-r--r-- | lib/setup.php | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/lib/setup.php b/lib/setup.php index b88bc4b52ce..28882b6bede 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -1,5 +1,23 @@ <?php +class DatabaseSetupException extends Exception +{ + private $hint; + + public function __construct($message, $hint, $code = 0, Exception $previous = null) { + $this->hint = $hint; + parent::__construct($message, $code, $previous); + } + + public function __toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; + } + + public function getHint() { + return $this->hint; + } +} + class OC_Setup { public static function install($options) { $error = array(); @@ -19,9 +37,9 @@ class OC_Setup { if($dbtype=='mysql') $dbprettyname = 'MySQL'; else if($dbtype=='pgsql') - $dbprettyname = 'PostgreSQL'; + $dbprettyname = 'PostgreSQL'; else - $dbprettyname = 'Oracle'; + $dbprettyname = 'Oracle'; if(empty($options['dbuser'])) { @@ -69,10 +87,16 @@ class OC_Setup { try { self::setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username); + } catch (DatabaseSetupException $e) { + $error[] = array( + 'error' => $e->getMessage(), + 'hint' => $e->getHint() + ); + return($error); } catch (Exception $e) { $error[] = array( - 'error' => 'MySQL username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' + 'error' => $e->getMessage(), + 'hint' => '' ); return($error); } @@ -166,7 +190,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 DatabaseSetupException('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 +253,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 DatabaseSetupException("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 DatabaseSetupException("MySQL user '" . "$name" . "'@'%' already exists","Delete this user from MySQL."); + } } private static function setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) { |