diff options
Diffstat (limited to 'lib/private/setup.php')
-rw-r--r-- | lib/private/setup.php | 103 |
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 { |