diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-04-03 17:52:18 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-06-29 21:15:05 +0200 |
commit | 6831b78597ae38ed03343e274448dfb210af817b (patch) | |
tree | 04ca627fc599517765fd4b73c6aa7f9eae71773c /lib/setup | |
parent | 2faccaee0d22efa6b23586b65f222e8cc5404366 (diff) | |
download | nextcloud-server-6831b78597ae38ed03343e274448dfb210af817b.tar.gz nextcloud-server-6831b78597ae38ed03343e274448dfb210af817b.zip |
Use db setup class for option validation
Diffstat (limited to 'lib/setup')
-rw-r--r-- | lib/setup/abstractdatabase.php | 17 | ||||
-rw-r--r-- | lib/setup/mssql.php | 2 | ||||
-rw-r--r-- | lib/setup/mysql.php | 2 | ||||
-rw-r--r-- | lib/setup/oci.php | 2 | ||||
-rw-r--r-- | lib/setup/postgresql.php | 2 | ||||
-rw-r--r-- | lib/setup/sqlite.php | 5 |
6 files changed, 28 insertions, 2 deletions
diff --git a/lib/setup/abstractdatabase.php b/lib/setup/abstractdatabase.php index cef64ee7ebb..07a679f2112 100644 --- a/lib/setup/abstractdatabase.php +++ b/lib/setup/abstractdatabase.php @@ -12,14 +12,27 @@ abstract class AbstractDatabase { public function __construct($trans, $config) { $this->trans = $trans; - $this->initialize($config); + } + + public function validate($config) { + $errors = array(); + if(empty($config['dbuser'])) { + $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); + } + if(empty($config['dbname'])) { + $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); + } + if(substr_count($config['dbname'], '.') >= 1) { + $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname)); + } + return $errors; } public function initialize($config) { $dbuser = $config['dbuser']; $dbpass = $config['dbpass']; $dbname = $config['dbname']; - $dbhost = isset($config['dbhost']) ? $config['dbhost'] : ''; // dbhost contents is checked earlier + $dbhost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; $dbtableprefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; \OC_Config::setValue('dbname', $dbname); diff --git a/lib/setup/mssql.php b/lib/setup/mssql.php index a1414a9ac57..74ac8f294a9 100644 --- a/lib/setup/mssql.php +++ b/lib/setup/mssql.php @@ -3,6 +3,8 @@ namespace OC\Setup; class MSSQL extends AbstractDatabase { + public $dbprettyname = 'MS SQL Server'; + public function setupDatabase() { //check if the database user has admin right $masterConnectionInfo = array( "Database" => "master", "UID" => $this->dbuser, "PWD" => $this->dbpassword); diff --git a/lib/setup/mysql.php b/lib/setup/mysql.php index 790b8e82257..aa0344f686c 100644 --- a/lib/setup/mysql.php +++ b/lib/setup/mysql.php @@ -3,6 +3,8 @@ namespace OC\Setup; class MySQL extends AbstractDatabase { + public $dbprettyname = 'MySQL'; + public function setupDatabase($username) { //check if the database user has admin right $connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword); diff --git a/lib/setup/oci.php b/lib/setup/oci.php index 3bb625c557d..a3e2ccc8da7 100644 --- a/lib/setup/oci.php +++ b/lib/setup/oci.php @@ -3,6 +3,8 @@ namespace OC\Setup; class OCI extends AbstractDatabase { + public $dbprettyname = 'Oracle'; + protected $dbtablespace; public function initialize($config) { diff --git a/lib/setup/postgresql.php b/lib/setup/postgresql.php index 3fb1e6b8787..67e4f901a91 100644 --- a/lib/setup/postgresql.php +++ b/lib/setup/postgresql.php @@ -3,6 +3,8 @@ namespace OC\Setup; class PostgreSQL extends AbstractDatabase { + public $dbprettyname = 'PostgreSQL'; + public function setupDatabase($username) { $e_host = addslashes($this->dbhost); $e_user = addslashes($this->dbuser); diff --git a/lib/setup/sqlite.php b/lib/setup/sqlite.php index b1785ce1b0b..0b96ec60009 100644 --- a/lib/setup/sqlite.php +++ b/lib/setup/sqlite.php @@ -3,6 +3,11 @@ namespace OC\Setup; class Sqlite extends AbstractDatabase { + public $dbprettyname = 'Sqlite'; + + public function validate($config) { + } + public function initialize($config) { } |