summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/base.php2
-rw-r--r--lib/private/setup.php103
-rw-r--r--lib/private/util.php9
3 files changed, 106 insertions, 8 deletions
diff --git a/lib/base.php b/lib/base.php
index 23f0e594510..22916c259fc 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -716,7 +716,7 @@ class OC {
// Check if ownCloud is installed or in maintenance (update) mode
if (!OC_Config::getValue('installed', false)) {
- $controller = new OC\Core\Setup\Controller();
+ $controller = new OC\Core\Setup\Controller(\OC::$server->getConfig());
$controller->run($_POST);
exit();
}
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 {
diff --git a/lib/private/util.php b/lib/private/util.php
index 858138f58fe..dd131e41310 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -436,12 +436,9 @@ class OC_Util {
}
$webServerRestart = false;
- //check for database drivers
- if (!(is_callable('sqlite_open') or class_exists('SQLite3'))
- and !is_callable('mysql_connect')
- and !is_callable('pg_connect')
- and !is_callable('oci_connect')
- ) {
+ $setup = new OC_Setup($config);
+ $availableDatabases = $setup->getSupportedDatabases();
+ if (empty($availableDatabases)) {
$errors[] = array(
'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'),
'hint' => '' //TODO: sane hint