Skip to content

Commit 49d1c76

Browse files
author
Marcin Łojewski
committed
Support Doctrine 3
1 parent 09d710f commit 49d1c76

4 files changed

Lines changed: 53 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Support for Doctrine 3
10+
- Support for Nextcloud 21 only
811

912
## [4.6.0] - 2021-01-16
1013
### Fixed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<category>auth</category>
2323
<dependencies>
2424
<php min-version="7.1"/>
25-
<nextcloud min-version="18" max-version="20"/>
25+
<nextcloud min-version="21" max-version="21"/>
2626
</dependencies>
2727
<settings>
2828
<admin>\OCA\UserSQL\Settings\Admin</admin>

lib/Controller/SettingsController.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2021 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -168,12 +168,15 @@ private function getConnection()
168168
];
169169

170170
if ($dbDriver == 'mysql') {
171-
if ($dbSSL_ca)
172-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$dbSSL_ca;
173-
if ($dbSSL_cert)
174-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$dbSSL_cert;
175-
if ($dbSSL_key)
176-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$dbSSL_key;
171+
if ($dbSSL_ca) {
172+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT . '/' . $dbSSL_ca;
173+
}
174+
if ($dbSSL_cert) {
175+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT . '/' . $dbSSL_cert;
176+
}
177+
if ($dbSSL_key) {
178+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT . '/' . $dbSSL_key;
179+
}
177180
}
178181

179182
$connection = $connectionFactory->getConnection($dbDriver, $parameters);

lib/Query/DataQuery.php

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Nextcloud - user_sql
44
*
5-
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
5+
* @copyright 2021 Marcin Łojewski <dev@mlojewski.me>
66
* @author Marcin Łojewski <dev@mlojewski.me>
77
*
88
* This program is free software: you can redistribute it and/or modify
@@ -22,6 +22,7 @@
2222
namespace OCA\UserSQL\Query;
2323

2424
use Doctrine\DBAL\Driver\Statement;
25+
use Doctrine\DBAL\Exception as DBALException;
2526
use OC\DB\Connection;
2627
use OC\DB\ConnectionFactory;
2728
use OCA\UserSQL\Constant\DB;
@@ -119,16 +120,17 @@ private function execQuery(
119120
["app" => $this->appName]
120121
);
121122

122-
if ($result->execute() !== true) {
123-
$error = $result->errorInfo();
123+
try {
124+
$result = $result->execute();
125+
return $result;
126+
127+
} catch (DBALException $exception) {
124128
$this->logger->error(
125-
"Could not execute the query: " . implode(", ", $error),
129+
"Could not execute the query: " . $exception->getMessage(),
126130
["app" => $this->appName]
127131
);
128132
return false;
129133
}
130-
131-
return $result;
132134
}
133135

134136
/**
@@ -150,12 +152,15 @@ private function connectToDatabase()
150152
);
151153

152154
if ($this->properties[DB::DRIVER] == 'mysql') {
153-
if ($this->properties[DB::SSL_CA])
154-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CA];
155-
if ($this->properties[DB::SSL_CERT])
156-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CERT];
157-
if ($this->properties[DB::SSL_KEY])
158-
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_KEY];
155+
if ($this->properties[DB::SSL_CA]) {
156+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_CA];
157+
}
158+
if ($this->properties[DB::SSL_CERT]) {
159+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_CERT];
160+
}
161+
if ($this->properties[DB::SSL_KEY]) {
162+
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_KEY];
163+
}
159164
}
160165

161166
$this->connection = $connectionFactory->getConnection(
@@ -185,7 +190,7 @@ public function queryValue($queryName, $params = [], $failure = false)
185190
return false;
186191
}
187192

188-
$row = $result->fetch(\PDO::FETCH_COLUMN);
193+
$row = $result->fetchOne();
189194
if ($row === false) {
190195
return $failure;
191196
}
@@ -211,8 +216,7 @@ public function queryColumn(
211216
return false;
212217
}
213218

214-
$column = $result->fetchAll(\PDO::FETCH_COLUMN);
215-
return $column;
219+
return $result->fetchFirstColumn();
216220
}
217221

218222
/**
@@ -232,8 +236,7 @@ public function queryEntity($queryName, $entityClass, $params = [])
232236
return false;
233237
}
234238

235-
$result->setFetchMode(\PDO::FETCH_CLASS, $entityClass);
236-
$entity = $result->fetch();
239+
$entity = $result->fetchAssociative();
237240

238241
if ($entity === false) {
239242
return null;
@@ -247,7 +250,16 @@ public function queryEntity($queryName, $entityClass, $params = [])
247250
return null;
248251
}
249252

250-
return $entity;
253+
return self::arrayToObject($entity, $entityClass);
254+
}
255+
256+
private function arrayToObject($array, $entityClass)
257+
{
258+
$object = new $entityClass();
259+
foreach ($array as $name => $value) {
260+
$object->$name = $array[$name];
261+
}
262+
return $object;
251263
}
252264

253265
/**
@@ -269,9 +281,15 @@ public function queryEntities(
269281
return false;
270282
}
271283

272-
$result->setFetchMode(\PDO::FETCH_CLASS, $entityClass);
273-
$entities = $result->fetchAll();
284+
return self::iterableToObjectArray($result->iterateAssociative(), $entityClass);
285+
}
274286

275-
return $entities;
287+
private function iterableToObjectArray($array, $entityClass)
288+
{
289+
$result = array();
290+
foreach ($array as $element) {
291+
$result[] = self::arrayToObject($element, $entityClass);
292+
}
293+
return $result;
276294
}
277295
}

0 commit comments

Comments
 (0)