*/
namespace OC\Setup;
+use OC\AllConfig;
+use OC\DB\ConnectionFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
protected $dbPort;
/** @var string */
protected $tablePrefix;
- /** @var IConfig */
+ /** @var AllConfig */
protected $config;
/** @var ILogger */
protected $logger;
$this->tablePrefix = $dbTablePrefix;
}
+ /**
+ * @return \OC\DB\Connection
+ * @throws \OC\DatabaseSetupException
+ */
+ protected function connect() {
+ $systemConfig = $this->config->getSystemConfig();
+ $cf = new ConnectionFactory();
+ $connectionParams = $cf->createConnectionParams($systemConfig);
+ // we don't save username/password to the config immediately so this might not be set
+ if (!$connectionParams['user']) {
+ $connectionParams['user'] = $this->dbUser;
+ }
+ if (!$connectionParams['password']) {
+ $connectionParams['password'] = $this->dbPassword;
+ }
+ return $cf->getConnection($systemConfig->getValue('dbtype', 'sqlite'), $connectionParams);
+ }
+
/**
* @param string $userName
*/
$connection->executeUpdate($query);
}
- /**
- * @return \OC\DB\Connection
- * @throws \OC\DatabaseSetupException
- */
- private function connect() {
-
- $connectionParams = array(
- 'host' => $this->dbHost,
- 'user' => $this->dbUser,
- 'password' => $this->dbPassword,
- 'tablePrefix' => $this->tablePrefix,
- );
-
- // adding port support through installer
- if(!empty($this->dbPort)) {
- if (ctype_digit($this->dbPort)) {
- $connectionParams['port'] = $this->dbPort;
- } else {
- $connectionParams['unix_socket'] = $this->dbPort;
- }
- } else if (strpos($this->dbHost, ':')) {
- // Host variable may carry a port or socket.
- list($host, $portOrSocket) = explode(':', $this->dbHost, 2);
- if (ctype_digit($portOrSocket)) {
- $connectionParams['port'] = $portOrSocket;
- } else {
- $connectionParams['unix_socket'] = $portOrSocket;
- }
- $connectionParams['host'] = $host;
- }
-
- $cf = new ConnectionFactory();
- return $cf->getConnection('mysql', $connectionParams);
- }
-
/**
* @param $username
* @param IDBConnection $connection