From 233c49f4b9fc90f5bd023420ed899439fb413db0 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 27 Oct 2014 12:51:26 +0100 Subject: 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". --- lib/private/setup.php | 103 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) (limited to 'lib/private/setup.php') 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 @@ + * 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 { -- cgit v1.2.3