From 2faccaee0d22efa6b23586b65f222e8cc5404366 Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Wed, 3 Apr 2013 08:31:47 +0200
Subject: [PATCH] Change database creation to use array to select db setup
 class

---
 lib/setup.php        | 36 +++++++++++-------------------------
 lib/setup/sqlite.php | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 25 deletions(-)
 create mode 100644 lib/setup/sqlite.php

diff --git a/lib/setup.php b/lib/setup.php
index 30975ae8ff6..e73ba6cdf4f 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -91,32 +91,18 @@ class OC_Setup {
 		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 {
-			if ($dbtype == 'mysql') {
-				$db_setup = new \OC\Setup\MySQL(self::getTrans(), $options);
-				$db_setup->setupDatabase($username);
-			}
-			elseif($dbtype == 'pgsql') {
-				$db_setup = new \OC\Setup\PostgreSQL(self::getTrans(), $options);
-				$db_setup->setupDatabase($username);
-			}
-			elseif($dbtype == 'oci') {
-				$db_setup = new \OC\Setup\OCI(self::getTrans(), $options);
-				$db_setup->setupDatabase($username);
-			}
-			elseif ($dbtype == 'mssql') {
-				$db_setup = new \OC\Setup\MSSQL(self::getTrans(), $options);
-				$db_setup->setupDatabase($username);
-			}
-			else { // sqlite
-				//delete the old sqlite database first, might cause infinte loops otherwise
-				if(file_exists("$datadir/owncloud.db")) {
-					unlink("$datadir/owncloud.db");
-				}
-				//in case of sqlite, we can always fill the database
-				error_log("creating sqlite db");
-				OC_DB::createDbFromStructure('db_structure.xml');
-			}
+			$class = $db_setup_classes[$dbtype];
+			$db_setup = new $class(self::getTrans(), $options);
+			$db_setup->setupDatabase($username);
 		} catch (DatabaseSetupException $e) {
 			$error[] = array(
 				'error' => $e->getMessage(),
diff --git a/lib/setup/sqlite.php b/lib/setup/sqlite.php
new file mode 100644
index 00000000000..b1785ce1b0b
--- /dev/null
+++ b/lib/setup/sqlite.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace OC\Setup;
+
+class Sqlite extends AbstractDatabase {
+	public function initialize($config) {
+	}
+
+	public function setupDatabase($username) {
+		$datadir = \OC_Config::getValue('datadirectory');
+
+		//delete the old sqlite database first, might cause infinte loops otherwise
+		if(file_exists("$datadir/owncloud.db")) {
+			unlink("$datadir/owncloud.db");
+		}
+		//in case of sqlite, we can always fill the database
+		error_log("creating sqlite db");
+		\OC_DB::createDbFromStructure('db_structure.xml');
+	}
+}
-- 
GitLab