summaryrefslogtreecommitdiffstats
path: root/lib/private/setup.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-10-27 12:51:26 +0100
committerLukas Reschke <lukas@owncloud.com>2014-10-27 21:39:34 +0100
commit233c49f4b9fc90f5bd023420ed899439fb413db0 (patch)
treeb0df628bd066ae1337a803b476026b5c48b2549f /lib/private/setup.php
parent25a4b5a93581800887fceef7444b0d3702e4f018 (diff)
downloadnextcloud-server-233c49f4b9fc90f5bd023420ed899439fb413db0.tar.gz
nextcloud-server-233c49f4b9fc90f5bd023420ed899439fb413db0.zip
Make supported DBs configurable within config.php
This commit will make the supported DBs for installation configurable within config.php. By default the following databases are tested: "sqlite", "mysql", "pgsql". The reason behind this is that there might be instances where we want to prevent SQLite to be used by mistake. To test this play around with the new configuration parameter "supportedDatabases".
Diffstat (limited to 'lib/private/setup.php')
-rw-r--r--lib/private/setup.php103
1 files changed, 102 insertions, 1 deletions
diff --git a/lib/private/setup.php b/lib/private/setup.php
index 75dc1987ee6..8945c2c03f1 100644
--- a/lib/private/setup.php
+++ b/lib/private/setup.php
@@ -1,9 +1,27 @@
<?php
+/**
+ * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+use OCP\IConfig;
class DatabaseSetupException extends \OC\HintException {
}
class OC_Setup {
+ /** @var IConfig */
+ protected $config;
+
+ /**
+ * @param IConfig $config
+ */
+ function __construct(IConfig $config) {
+ $this->config = $config;
+ }
+
static $dbSetupClasses = array(
'mysql' => '\OC\Setup\MySQL',
'pgsql' => '\OC\Setup\PostgreSQL',
@@ -13,10 +31,93 @@ class OC_Setup {
'sqlite3' => '\OC\Setup\Sqlite',
);
+ /**
+ * @return OC_L10N
+ */
public static function getTrans(){
return \OC::$server->getL10N('lib');
}
+ /**
+ * Wrapper around the "class_exists" PHP function to be able to mock it
+ * @param string $name
+ * @return bool
+ */
+ public function class_exists($name) {
+ return class_exists($name);
+ }
+
+ /**
+ * Wrapper around the "is_callable" PHP function to be able to mock it
+ * @param string $name
+ * @return bool
+ */
+ public function is_callable($name) {
+ return is_callable($name);
+ }
+
+ /**
+ * Get the available and supported databases of this instance
+ *
+ * @throws Exception
+ * @return array
+ */
+ public function getSupportedDatabases() {
+ $availableDatabases = array(
+ 'sqlite' => array(
+ 'type' => 'class',
+ 'call' => 'SQLite3',
+ 'name' => 'SQLite'
+ ),
+ 'mysql' => array(
+ 'type' => 'function',
+ 'call' => 'mysql_connect',
+ 'name' => 'MySQL/MariaDB'
+ ),
+ 'pgsql' => array(
+ 'type' => 'function',
+ 'call' => 'oci_connect',
+ 'name' => 'PostgreSQL'
+ ),
+ 'oci' => array(
+ 'type' => 'function',
+ 'call' => 'oci_connect',
+ 'name' => 'Oracle'
+ ),
+ 'mssql' => array(
+ 'type' => 'function',
+ 'call' => 'sqlsrv_connect',
+ 'name' => 'MS SQL'
+ )
+ );
+ $configuredDatabases = $this->config->getSystemValue('supportedDatabases', array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql'));
+ if(!is_array($configuredDatabases)) {
+ throw new Exception('Supported databases are not properly configured.');
+ }
+
+ $supportedDatabases = array();
+
+ foreach($configuredDatabases as $database) {
+ if(array_key_exists($database, $availableDatabases)) {
+ $working = false;
+ if($availableDatabases[$database]['type'] === 'class') {
+ $working = $this->class_exists($availableDatabases[$database]['call']);
+ } elseif ($availableDatabases[$database]['type'] === 'function') {
+ $working = $this->is_callable($availableDatabases[$database]['call']);
+ }
+ if($working) {
+ $supportedDatabases[$database] = $availableDatabases[$database]['name'];
+ }
+ }
+ }
+
+ return $supportedDatabases;
+ }
+
+ /**
+ * @param $options
+ * @return array
+ */
public static function install($options) {
$l = self::getTrans();
@@ -59,7 +160,7 @@ class OC_Setup {
}
//no errors, good
- if( isset($options['trusted_domains'])
+ if(isset($options['trusted_domains'])
&& is_array($options['trusted_domains'])) {
$trustedDomains = $options['trusted_domains'];
} else {