]> source.dussan.org Git - nextcloud-server.git/commitdiff
Remove duplicate database connect logic in mysql setup
authorRobin Appelman <icewind@owncloud.com>
Tue, 12 Jul 2016 11:11:44 +0000 (13:11 +0200)
committerRobin Appelman <icewind@owncloud.com>
Tue, 12 Jul 2016 12:38:24 +0000 (14:38 +0200)
lib/private/AllConfig.php
lib/private/Setup/AbstractDatabase.php
lib/private/Setup/MySQL.php

index c8b2009fcc7178513278a119cd34177f8f4e7128..b50fc0f42ced0a7e3d0bf68a431ea65cd286d2cf 100644 (file)
@@ -428,4 +428,8 @@ class AllConfig implements \OCP\IConfig {
 
                return $userIDs;
        }
+
+       public function getSystemConfig() {
+               return $this->systemConfig;
+       }
 }
index 08ed741f51ccb4579b5520a70e5a2b5d586fd5fc..62e9b2e823ff46ecef3fb0c6ca220d81001de80f 100644 (file)
@@ -23,6 +23,8 @@
  */
 namespace OC\Setup;
 
+use OC\AllConfig;
+use OC\DB\ConnectionFactory;
 use OCP\IConfig;
 use OCP\ILogger;
 use OCP\Security\ISecureRandom;
@@ -45,7 +47,7 @@ abstract class AbstractDatabase {
        protected $dbPort;
        /** @var string */
        protected $tablePrefix;
-       /** @var IConfig */
+       /** @var AllConfig */
        protected $config;
        /** @var ILogger */
        protected $logger;
@@ -98,6 +100,24 @@ abstract class AbstractDatabase {
                $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
         */
index 1ff7b278b863742f976800509a9ae1074f1e29af..03a1421f428efd82012984974f8e2dc71f80aa2d 100644 (file)
@@ -87,41 +87,6 @@ class MySQL extends AbstractDatabase {
                $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