}
class OC_Setup {
+ static $db_setup_classes = array(
+ 'mysql' => '\OC\Setup\MySQL',
+ 'pgsql' => '\OC\Setup\PostgreSQL',
+ 'oci' => '\OC\Setup\OCI',
+ 'mssql' => '\OC\Setup\MSSQL',
+ 'sqlite' => '\OC\Setup\Sqlite',
+ 'sqlite3' => '\OC\Setup\Sqlite',
+ );
public static function getTrans(){
return OC_L10N::get('lib');
$options['directory'] = OC::$SERVERROOT."/data";
}
- if($dbtype == 'mysql' or $dbtype == 'pgsql' or $dbtype == 'oci' or $dbtype == 'mssql') { // these needs more config options
- if($dbtype == 'mysql')
- $dbprettyname = 'MySQL';
- else if($dbtype == 'pgsql')
- $dbprettyname = 'PostgreSQL';
- else if ($dbtype == 'mssql')
- $dbprettyname = 'MS SQL Server';
- else
- $dbprettyname = 'Oracle';
-
-
- if(empty($options['dbuser'])) {
- $error[] = $l->t("%s enter the database username.", array($dbprettyname));
- }
- if(empty($options['dbname'])) {
- $error[] = $l->t("%s enter the database name.", array($dbprettyname));
- }
- if(substr_count($options['dbname'], '.') >= 1) {
- $error[] = $l->t("%s you may not use dots in the database name", array($dbprettyname));
- }
- if($dbtype != 'oci' && empty($options['dbhost'])) {
- $options['dbhost'] = 'localhost';
- }
+ if (!isset(self::$db_setup_classes[$dbtype])) {
+ $dbtype = 'sqlite';
}
+ $class = self::$db_setup_classes[$dbtype];
+ $db_setup = new $class(self::getTrans());
+ $error = array_merge($error, $db_setup->validate($options));
+
if(count($error) != 0) {
return $error;
}
OC_Config::setValue('datadirectory', $datadir);
OC_Config::setValue('dbtype', $dbtype);
OC_Config::setValue('version', implode('.', OC_Util::getVersion()));
- $db_setup_classes = array(
- 'mysql' => '\OC\Setup\MySQL',
- 'pgsql' => '\OC\Setup\PostgreSQL',
- 'oci' => '\OC\Setup\OCI',
- 'mssql' => '\OC\Setup\MSSQL',
- 'sqlite' => '\OC\Setup\Sqlite',
- 'sqlite3' => '\OC\Setup\Sqlite',
- );
try {
- $class = $db_setup_classes[$dbtype];
- $db_setup = new $class(self::getTrans(), $options);
+ $db_setup->initialize($options);
$db_setup->setupDatabase($username);
} catch (DatabaseSetupException $e) {
$error[] = array(
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);