@@ -38,199 +38,199 @@  | 
                                                    ||
| 38 | 38 | * Takes care of creating and configuring Doctrine connections.  | 
                                                        
| 39 | 39 | */  | 
                                                        
| 40 | 40 |  class ConnectionFactory { | 
                                                        
| 41 | - /**  | 
                                                        |
| 42 | - * @var array  | 
                                                        |
| 43 | - *  | 
                                                        |
| 44 | - * Array mapping DBMS type to default connection parameters passed to  | 
                                                        |
| 45 | - * \Doctrine\DBAL\DriverManager::getConnection().  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected $defaultConnectionParams = [  | 
                                                        |
| 48 | - 'mysql' => [  | 
                                                        |
| 49 | - 'adapter' => AdapterMySQL::class,  | 
                                                        |
| 50 | - 'charset' => 'UTF8',  | 
                                                        |
| 51 | - 'driver' => 'pdo_mysql',  | 
                                                        |
| 52 | - 'wrapperClass' => Connection::class,  | 
                                                        |
| 53 | - ],  | 
                                                        |
| 54 | - 'oci' => [  | 
                                                        |
| 55 | - 'adapter' => AdapterOCI8::class,  | 
                                                        |
| 56 | - 'charset' => 'AL32UTF8',  | 
                                                        |
| 57 | - 'driver' => 'oci8',  | 
                                                        |
| 58 | - 'wrapperClass' => OracleConnection::class,  | 
                                                        |
| 59 | - ],  | 
                                                        |
| 60 | - 'pgsql' => [  | 
                                                        |
| 61 | - 'adapter' => AdapterPgSql::class,  | 
                                                        |
| 62 | - 'driver' => 'pdo_pgsql',  | 
                                                        |
| 63 | - 'wrapperClass' => Connection::class,  | 
                                                        |
| 64 | - ],  | 
                                                        |
| 65 | - 'sqlite3' => [  | 
                                                        |
| 66 | - 'adapter' => AdapterSqlite::class,  | 
                                                        |
| 67 | - 'driver' => 'pdo_sqlite',  | 
                                                        |
| 68 | - 'wrapperClass' => Connection::class,  | 
                                                        |
| 69 | - ],  | 
                                                        |
| 70 | - ];  | 
                                                        |
| 71 | -  | 
                                                        |
| 72 | - /** @var SystemConfig */  | 
                                                        |
| 73 | - private $config;  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - /**  | 
                                                        |
| 76 | - * ConnectionFactory constructor.  | 
                                                        |
| 77 | - *  | 
                                                        |
| 78 | - * @param SystemConfig $systemConfig  | 
                                                        |
| 79 | - */  | 
                                                        |
| 80 | -	public function __construct(SystemConfig $systemConfig) { | 
                                                        |
| 81 | - $this->config = $systemConfig;  | 
                                                        |
| 82 | -		if ($this->config->getValue('mysql.utf8mb4', false)) { | 
                                                        |
| 83 | - $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4';  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | - }  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - /**  | 
                                                        |
| 88 | - * @brief Get default connection parameters for a given DBMS.  | 
                                                        |
| 89 | - * @param string $type DBMS type  | 
                                                        |
| 90 | - * @throws \InvalidArgumentException If $type is invalid  | 
                                                        |
| 91 | - * @return array Default connection parameters.  | 
                                                        |
| 92 | - */  | 
                                                        |
| 93 | -	public function getDefaultConnectionParams($type) { | 
                                                        |
| 94 | - $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 95 | -		if (!isset($this->defaultConnectionParams[$normalizedType])) { | 
                                                        |
| 96 | -			throw new \InvalidArgumentException("Unsupported type: $type"); | 
                                                        |
| 97 | - }  | 
                                                        |
| 98 | - $result = $this->defaultConnectionParams[$normalizedType];  | 
                                                        |
| 99 | - // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL  | 
                                                        |
| 100 | - // driver is missing. In this case, we won't be able to connect anyway.  | 
                                                        |
| 101 | -		if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { | 
                                                        |
| 102 | - $result['driverOptions'] = array(  | 
                                                        |
| 103 | - \PDO::MYSQL_ATTR_FOUND_ROWS => true,  | 
                                                        |
| 104 | - );  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | - return $result;  | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | - /**  | 
                                                        |
| 110 | - * @brief Get default connection parameters for a given DBMS.  | 
                                                        |
| 111 | - * @param string $type DBMS type  | 
                                                        |
| 112 | - * @param array $additionalConnectionParams Additional connection parameters  | 
                                                        |
| 113 | - * @return \OC\DB\Connection  | 
                                                        |
| 114 | - */  | 
                                                        |
| 115 | -	public function getConnection($type, $additionalConnectionParams) { | 
                                                        |
| 116 | - $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 117 | - $eventManager = new EventManager();  | 
                                                        |
| 118 | -		switch ($normalizedType) { | 
                                                        |
| 119 | - case 'mysql':  | 
                                                        |
| 120 | - $eventManager->addEventSubscriber(  | 
                                                        |
| 121 | -					new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); | 
                                                        |
| 122 | - break;  | 
                                                        |
| 123 | - case 'oci':  | 
                                                        |
| 124 | - $eventManager->addEventSubscriber(new OracleSessionInit);  | 
                                                        |
| 125 | - // the driverOptions are unused in dbal and need to be mapped to the parameters  | 
                                                        |
| 126 | -				if (isset($additionalConnectionParams['driverOptions'])) { | 
                                                        |
| 127 | - $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']);  | 
                                                        |
| 128 | - }  | 
                                                        |
| 129 | - $host = $additionalConnectionParams['host'];  | 
                                                        |
| 130 | - $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null;  | 
                                                        |
| 131 | - $dbName = $additionalConnectionParams['dbname'];  | 
                                                        |
| 132 | -  | 
                                                        |
| 133 | - // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string  | 
                                                        |
| 134 | -				if ($host === '') { | 
                                                        |
| 135 | - $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name  | 
                                                        |
| 136 | -				} else { | 
                                                        |
| 137 | -					$additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; | 
                                                        |
| 138 | - }  | 
                                                        |
| 139 | - unset($additionalConnectionParams['host']);  | 
                                                        |
| 140 | - break;  | 
                                                        |
| 141 | -  | 
                                                        |
| 142 | - case 'sqlite3':  | 
                                                        |
| 143 | - $journalMode = $additionalConnectionParams['sqlite.journal_mode'];  | 
                                                        |
| 144 | - $additionalConnectionParams['platform'] = new OCSqlitePlatform();  | 
                                                        |
| 145 | - $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode));  | 
                                                        |
| 146 | - break;  | 
                                                        |
| 147 | - }  | 
                                                        |
| 148 | - /** @var Connection $connection */  | 
                                                        |
| 149 | - $connection = DriverManager::getConnection(  | 
                                                        |
| 150 | - array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams),  | 
                                                        |
| 151 | - new Configuration(),  | 
                                                        |
| 152 | - $eventManager  | 
                                                        |
| 153 | - );  | 
                                                        |
| 154 | - return $connection;  | 
                                                        |
| 155 | - }  | 
                                                        |
| 156 | -  | 
                                                        |
| 157 | - /**  | 
                                                        |
| 158 | - * @brief Normalize DBMS type  | 
                                                        |
| 159 | - * @param string $type DBMS type  | 
                                                        |
| 160 | - * @return string Normalized DBMS type  | 
                                                        |
| 161 | - */  | 
                                                        |
| 162 | -	public function normalizeType($type) { | 
                                                        |
| 163 | - return $type === 'sqlite' ? 'sqlite3' : $type;  | 
                                                        |
| 164 | - }  | 
                                                        |
| 165 | -  | 
                                                        |
| 166 | - /**  | 
                                                        |
| 167 | - * Checks whether the specified DBMS type is valid.  | 
                                                        |
| 168 | - *  | 
                                                        |
| 169 | - * @param string $type  | 
                                                        |
| 170 | - * @return bool  | 
                                                        |
| 171 | - */  | 
                                                        |
| 172 | -	public function isValidType($type) { | 
                                                        |
| 173 | - $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 174 | - return isset($this->defaultConnectionParams[$normalizedType]);  | 
                                                        |
| 175 | - }  | 
                                                        |
| 176 | -  | 
                                                        |
| 177 | - /**  | 
                                                        |
| 178 | - * Create the connection parameters for the config  | 
                                                        |
| 179 | - *  | 
                                                        |
| 180 | - * @return array  | 
                                                        |
| 181 | - */  | 
                                                        |
| 182 | -	public function createConnectionParams() { | 
                                                        |
| 183 | -		$type = $this->config->getValue('dbtype', 'sqlite'); | 
                                                        |
| 184 | -  | 
                                                        |
| 185 | - $connectionParams = [  | 
                                                        |
| 186 | -			'user' => $this->config->getValue('dbuser', ''), | 
                                                        |
| 187 | -			'password' => $this->config->getValue('dbpassword', ''), | 
                                                        |
| 188 | - ];  | 
                                                        |
| 189 | -		$name = $this->config->getValue('dbname', 'owncloud'); | 
                                                        |
| 190 | -  | 
                                                        |
| 191 | -		if ($this->normalizeType($type) === 'sqlite3') { | 
                                                        |
| 192 | -			$dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); | 
                                                        |
| 193 | - $connectionParams['path'] = $dataDir . '/' . $name . '.db';  | 
                                                        |
| 194 | -		} else { | 
                                                        |
| 195 | -			$host = $this->config->getValue('dbhost', ''); | 
                                                        |
| 196 | - $matches = [];  | 
                                                        |
| 197 | -			if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { | 
                                                        |
| 198 | - // Host variable carries a port or socket.  | 
                                                        |
| 199 | - $host = $matches[1];  | 
                                                        |
| 200 | -				if (is_numeric($matches[2])) { | 
                                                        |
| 201 | - $connectionParams['port'] = (int) $matches[2];  | 
                                                        |
| 202 | -				} else { | 
                                                        |
| 203 | - $connectionParams['unix_socket'] = $matches[2];  | 
                                                        |
| 204 | - }  | 
                                                        |
| 205 | - }  | 
                                                        |
| 206 | - $connectionParams['host'] = $host;  | 
                                                        |
| 207 | - $connectionParams['dbname'] = $name;  | 
                                                        |
| 208 | - }  | 
                                                        |
| 209 | -  | 
                                                        |
| 210 | -		$connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_'); | 
                                                        |
| 211 | -		$connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - //additional driver options, eg. for mysql ssl  | 
                                                        |
| 214 | -		$driverOptions = $this->config->getValue('dbdriveroptions', null); | 
                                                        |
| 215 | -		if ($driverOptions) { | 
                                                        |
| 216 | - $connectionParams['driverOptions'] = $driverOptions;  | 
                                                        |
| 217 | - }  | 
                                                        |
| 218 | -  | 
                                                        |
| 219 | - // set default table creation options  | 
                                                        |
| 220 | - $connectionParams['defaultTableOptions'] = [  | 
                                                        |
| 221 | - 'collate' => 'utf8_bin',  | 
                                                        |
| 222 | - 'tablePrefix' => $connectionParams['tablePrefix']  | 
                                                        |
| 223 | - ];  | 
                                                        |
| 224 | -  | 
                                                        |
| 225 | -		if ($this->config->getValue('mysql.utf8mb4', false)) { | 
                                                        |
| 226 | - $connectionParams['defaultTableOptions'] = [  | 
                                                        |
| 227 | - 'collate' => 'utf8mb4_bin',  | 
                                                        |
| 228 | - 'charset' => 'utf8mb4',  | 
                                                        |
| 229 | - 'row_format' => 'compressed',  | 
                                                        |
| 230 | - 'tablePrefix' => $connectionParams['tablePrefix']  | 
                                                        |
| 231 | - ];  | 
                                                        |
| 232 | - }  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | - return $connectionParams;  | 
                                                        |
| 235 | - }  | 
                                                        |
| 41 | + /**  | 
                                                        |
| 42 | + * @var array  | 
                                                        |
| 43 | + *  | 
                                                        |
| 44 | + * Array mapping DBMS type to default connection parameters passed to  | 
                                                        |
| 45 | + * \Doctrine\DBAL\DriverManager::getConnection().  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected $defaultConnectionParams = [  | 
                                                        |
| 48 | + 'mysql' => [  | 
                                                        |
| 49 | + 'adapter' => AdapterMySQL::class,  | 
                                                        |
| 50 | + 'charset' => 'UTF8',  | 
                                                        |
| 51 | + 'driver' => 'pdo_mysql',  | 
                                                        |
| 52 | + 'wrapperClass' => Connection::class,  | 
                                                        |
| 53 | + ],  | 
                                                        |
| 54 | + 'oci' => [  | 
                                                        |
| 55 | + 'adapter' => AdapterOCI8::class,  | 
                                                        |
| 56 | + 'charset' => 'AL32UTF8',  | 
                                                        |
| 57 | + 'driver' => 'oci8',  | 
                                                        |
| 58 | + 'wrapperClass' => OracleConnection::class,  | 
                                                        |
| 59 | + ],  | 
                                                        |
| 60 | + 'pgsql' => [  | 
                                                        |
| 61 | + 'adapter' => AdapterPgSql::class,  | 
                                                        |
| 62 | + 'driver' => 'pdo_pgsql',  | 
                                                        |
| 63 | + 'wrapperClass' => Connection::class,  | 
                                                        |
| 64 | + ],  | 
                                                        |
| 65 | + 'sqlite3' => [  | 
                                                        |
| 66 | + 'adapter' => AdapterSqlite::class,  | 
                                                        |
| 67 | + 'driver' => 'pdo_sqlite',  | 
                                                        |
| 68 | + 'wrapperClass' => Connection::class,  | 
                                                        |
| 69 | + ],  | 
                                                        |
| 70 | + ];  | 
                                                        |
| 71 | +  | 
                                                        |
| 72 | + /** @var SystemConfig */  | 
                                                        |
| 73 | + private $config;  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + /**  | 
                                                        |
| 76 | + * ConnectionFactory constructor.  | 
                                                        |
| 77 | + *  | 
                                                        |
| 78 | + * @param SystemConfig $systemConfig  | 
                                                        |
| 79 | + */  | 
                                                        |
| 80 | +    public function __construct(SystemConfig $systemConfig) { | 
                                                        |
| 81 | + $this->config = $systemConfig;  | 
                                                        |
| 82 | +        if ($this->config->getValue('mysql.utf8mb4', false)) { | 
                                                        |
| 83 | + $this->defaultConnectionParams['mysql']['charset'] = 'utf8mb4';  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | + }  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + /**  | 
                                                        |
| 88 | + * @brief Get default connection parameters for a given DBMS.  | 
                                                        |
| 89 | + * @param string $type DBMS type  | 
                                                        |
| 90 | + * @throws \InvalidArgumentException If $type is invalid  | 
                                                        |
| 91 | + * @return array Default connection parameters.  | 
                                                        |
| 92 | + */  | 
                                                        |
| 93 | +    public function getDefaultConnectionParams($type) { | 
                                                        |
| 94 | + $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 95 | +        if (!isset($this->defaultConnectionParams[$normalizedType])) { | 
                                                        |
| 96 | +            throw new \InvalidArgumentException("Unsupported type: $type"); | 
                                                        |
| 97 | + }  | 
                                                        |
| 98 | + $result = $this->defaultConnectionParams[$normalizedType];  | 
                                                        |
| 99 | + // \PDO::MYSQL_ATTR_FOUND_ROWS may not be defined, e.g. when the MySQL  | 
                                                        |
| 100 | + // driver is missing. In this case, we won't be able to connect anyway.  | 
                                                        |
| 101 | +        if ($normalizedType === 'mysql' && defined('\PDO::MYSQL_ATTR_FOUND_ROWS')) { | 
                                                        |
| 102 | + $result['driverOptions'] = array(  | 
                                                        |
| 103 | + \PDO::MYSQL_ATTR_FOUND_ROWS => true,  | 
                                                        |
| 104 | + );  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | + return $result;  | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | + /**  | 
                                                        |
| 110 | + * @brief Get default connection parameters for a given DBMS.  | 
                                                        |
| 111 | + * @param string $type DBMS type  | 
                                                        |
| 112 | + * @param array $additionalConnectionParams Additional connection parameters  | 
                                                        |
| 113 | + * @return \OC\DB\Connection  | 
                                                        |
| 114 | + */  | 
                                                        |
| 115 | +    public function getConnection($type, $additionalConnectionParams) { | 
                                                        |
| 116 | + $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 117 | + $eventManager = new EventManager();  | 
                                                        |
| 118 | +        switch ($normalizedType) { | 
                                                        |
| 119 | + case 'mysql':  | 
                                                        |
| 120 | + $eventManager->addEventSubscriber(  | 
                                                        |
| 121 | +                    new SQLSessionInit("SET SESSION AUTOCOMMIT=1")); | 
                                                        |
| 122 | + break;  | 
                                                        |
| 123 | + case 'oci':  | 
                                                        |
| 124 | + $eventManager->addEventSubscriber(new OracleSessionInit);  | 
                                                        |
| 125 | + // the driverOptions are unused in dbal and need to be mapped to the parameters  | 
                                                        |
| 126 | +                if (isset($additionalConnectionParams['driverOptions'])) { | 
                                                        |
| 127 | + $additionalConnectionParams = array_merge($additionalConnectionParams, $additionalConnectionParams['driverOptions']);  | 
                                                        |
| 128 | + }  | 
                                                        |
| 129 | + $host = $additionalConnectionParams['host'];  | 
                                                        |
| 130 | + $port = isset($additionalConnectionParams['port']) ? $additionalConnectionParams['port'] : null;  | 
                                                        |
| 131 | + $dbName = $additionalConnectionParams['dbname'];  | 
                                                        |
| 132 | +  | 
                                                        |
| 133 | + // we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string  | 
                                                        |
| 134 | +                if ($host === '') { | 
                                                        |
| 135 | + $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name  | 
                                                        |
| 136 | +                } else { | 
                                                        |
| 137 | +                    $additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; | 
                                                        |
| 138 | + }  | 
                                                        |
| 139 | + unset($additionalConnectionParams['host']);  | 
                                                        |
| 140 | + break;  | 
                                                        |
| 141 | +  | 
                                                        |
| 142 | + case 'sqlite3':  | 
                                                        |
| 143 | + $journalMode = $additionalConnectionParams['sqlite.journal_mode'];  | 
                                                        |
| 144 | + $additionalConnectionParams['platform'] = new OCSqlitePlatform();  | 
                                                        |
| 145 | + $eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode));  | 
                                                        |
| 146 | + break;  | 
                                                        |
| 147 | + }  | 
                                                        |
| 148 | + /** @var Connection $connection */  | 
                                                        |
| 149 | + $connection = DriverManager::getConnection(  | 
                                                        |
| 150 | + array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams),  | 
                                                        |
| 151 | + new Configuration(),  | 
                                                        |
| 152 | + $eventManager  | 
                                                        |
| 153 | + );  | 
                                                        |
| 154 | + return $connection;  | 
                                                        |
| 155 | + }  | 
                                                        |
| 156 | +  | 
                                                        |
| 157 | + /**  | 
                                                        |
| 158 | + * @brief Normalize DBMS type  | 
                                                        |
| 159 | + * @param string $type DBMS type  | 
                                                        |
| 160 | + * @return string Normalized DBMS type  | 
                                                        |
| 161 | + */  | 
                                                        |
| 162 | +    public function normalizeType($type) { | 
                                                        |
| 163 | + return $type === 'sqlite' ? 'sqlite3' : $type;  | 
                                                        |
| 164 | + }  | 
                                                        |
| 165 | +  | 
                                                        |
| 166 | + /**  | 
                                                        |
| 167 | + * Checks whether the specified DBMS type is valid.  | 
                                                        |
| 168 | + *  | 
                                                        |
| 169 | + * @param string $type  | 
                                                        |
| 170 | + * @return bool  | 
                                                        |
| 171 | + */  | 
                                                        |
| 172 | +    public function isValidType($type) { | 
                                                        |
| 173 | + $normalizedType = $this->normalizeType($type);  | 
                                                        |
| 174 | + return isset($this->defaultConnectionParams[$normalizedType]);  | 
                                                        |
| 175 | + }  | 
                                                        |
| 176 | +  | 
                                                        |
| 177 | + /**  | 
                                                        |
| 178 | + * Create the connection parameters for the config  | 
                                                        |
| 179 | + *  | 
                                                        |
| 180 | + * @return array  | 
                                                        |
| 181 | + */  | 
                                                        |
| 182 | +    public function createConnectionParams() { | 
                                                        |
| 183 | +        $type = $this->config->getValue('dbtype', 'sqlite'); | 
                                                        |
| 184 | +  | 
                                                        |
| 185 | + $connectionParams = [  | 
                                                        |
| 186 | +            'user' => $this->config->getValue('dbuser', ''), | 
                                                        |
| 187 | +            'password' => $this->config->getValue('dbpassword', ''), | 
                                                        |
| 188 | + ];  | 
                                                        |
| 189 | +        $name = $this->config->getValue('dbname', 'owncloud'); | 
                                                        |
| 190 | +  | 
                                                        |
| 191 | +        if ($this->normalizeType($type) === 'sqlite3') { | 
                                                        |
| 192 | +            $dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); | 
                                                        |
| 193 | + $connectionParams['path'] = $dataDir . '/' . $name . '.db';  | 
                                                        |
| 194 | +        } else { | 
                                                        |
| 195 | +            $host = $this->config->getValue('dbhost', ''); | 
                                                        |
| 196 | + $matches = [];  | 
                                                        |
| 197 | +            if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { | 
                                                        |
| 198 | + // Host variable carries a port or socket.  | 
                                                        |
| 199 | + $host = $matches[1];  | 
                                                        |
| 200 | +                if (is_numeric($matches[2])) { | 
                                                        |
| 201 | + $connectionParams['port'] = (int) $matches[2];  | 
                                                        |
| 202 | +                } else { | 
                                                        |
| 203 | + $connectionParams['unix_socket'] = $matches[2];  | 
                                                        |
| 204 | + }  | 
                                                        |
| 205 | + }  | 
                                                        |
| 206 | + $connectionParams['host'] = $host;  | 
                                                        |
| 207 | + $connectionParams['dbname'] = $name;  | 
                                                        |
| 208 | + }  | 
                                                        |
| 209 | +  | 
                                                        |
| 210 | +        $connectionParams['tablePrefix'] = $this->config->getValue('dbtableprefix', 'oc_'); | 
                                                        |
| 211 | +        $connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL'); | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + //additional driver options, eg. for mysql ssl  | 
                                                        |
| 214 | +        $driverOptions = $this->config->getValue('dbdriveroptions', null); | 
                                                        |
| 215 | +        if ($driverOptions) { | 
                                                        |
| 216 | + $connectionParams['driverOptions'] = $driverOptions;  | 
                                                        |
| 217 | + }  | 
                                                        |
| 218 | +  | 
                                                        |
| 219 | + // set default table creation options  | 
                                                        |
| 220 | + $connectionParams['defaultTableOptions'] = [  | 
                                                        |
| 221 | + 'collate' => 'utf8_bin',  | 
                                                        |
| 222 | + 'tablePrefix' => $connectionParams['tablePrefix']  | 
                                                        |
| 223 | + ];  | 
                                                        |
| 224 | +  | 
                                                        |
| 225 | +        if ($this->config->getValue('mysql.utf8mb4', false)) { | 
                                                        |
| 226 | + $connectionParams['defaultTableOptions'] = [  | 
                                                        |
| 227 | + 'collate' => 'utf8mb4_bin',  | 
                                                        |
| 228 | + 'charset' => 'utf8mb4',  | 
                                                        |
| 229 | + 'row_format' => 'compressed',  | 
                                                        |
| 230 | + 'tablePrefix' => $connectionParams['tablePrefix']  | 
                                                        |
| 231 | + ];  | 
                                                        |
| 232 | + }  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | + return $connectionParams;  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | 236 | }  | 
                                                        
@@ -134,7 +134,7 @@ discard block  | 
                                                    ||
| 134 | 134 |  				if ($host === '') { | 
                                                        
| 135 | 135 | $additionalConnectionParams['dbname'] = $dbName; // use dbname as easy connect name  | 
                                                        
| 136 | 136 |  				} else { | 
                                                        
| 137 | -					$additionalConnectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : "") . '/' . $dbName; | 
                                                        |
| 137 | +					$additionalConnectionParams['dbname'] = '//'.$host.(!empty($port) ? ":{$port}" : "").'/'.$dbName; | 
                                                        |
| 138 | 138 | }  | 
                                                        
| 139 | 139 | unset($additionalConnectionParams['host']);  | 
                                                        
| 140 | 140 | break;  | 
                                                        
@@ -189,8 +189,8 @@ discard block  | 
                                                    ||
| 189 | 189 |  		$name = $this->config->getValue('dbname', 'owncloud'); | 
                                                        
| 190 | 190 | |
| 191 | 191 |  		if ($this->normalizeType($type) === 'sqlite3') { | 
                                                        
| 192 | -			$dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data'); | 
                                                        |
| 193 | - $connectionParams['path'] = $dataDir . '/' . $name . '.db';  | 
                                                        |
| 192 | +			$dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT.'/data'); | 
                                                        |
| 193 | + $connectionParams['path'] = $dataDir.'/'.$name.'.db';  | 
                                                        |
| 194 | 194 |  		} else { | 
                                                        
| 195 | 195 |  			$host = $this->config->getValue('dbhost', ''); | 
                                                        
| 196 | 196 | $matches = [];  |