Support Doctrine 3
This commit is contained in:
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- Support for Doctrine 3
|
||||
- Support for Nextcloud 21 only
|
||||
|
||||
## [4.6.0] - 2021-01-16
|
||||
### Fixed
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<category>auth</category>
|
||||
<dependencies>
|
||||
<php min-version="7.1"/>
|
||||
<nextcloud min-version="18" max-version="20"/>
|
||||
<nextcloud min-version="21" max-version="21"/>
|
||||
</dependencies>
|
||||
<settings>
|
||||
<admin>\OCA\UserSQL\Settings\Admin</admin>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Nextcloud - user_sql
|
||||
*
|
||||
* @copyright 2020 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @copyright 2021 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -168,12 +168,15 @@ class SettingsController extends Controller
|
||||
];
|
||||
|
||||
if ($dbDriver == 'mysql') {
|
||||
if ($dbSSL_ca)
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$dbSSL_ca;
|
||||
if ($dbSSL_cert)
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$dbSSL_cert;
|
||||
if ($dbSSL_key)
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$dbSSL_key;
|
||||
if ($dbSSL_ca) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT . '/' . $dbSSL_ca;
|
||||
}
|
||||
if ($dbSSL_cert) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT . '/' . $dbSSL_cert;
|
||||
}
|
||||
if ($dbSSL_key) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT . '/' . $dbSSL_key;
|
||||
}
|
||||
}
|
||||
|
||||
$connection = $connectionFactory->getConnection($dbDriver, $parameters);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Nextcloud - user_sql
|
||||
*
|
||||
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @copyright 2021 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -22,6 +22,7 @@
|
||||
namespace OCA\UserSQL\Query;
|
||||
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use OC\DB\Connection;
|
||||
use OC\DB\ConnectionFactory;
|
||||
use OCA\UserSQL\Constant\DB;
|
||||
@@ -119,16 +120,17 @@ class DataQuery
|
||||
["app" => $this->appName]
|
||||
);
|
||||
|
||||
if ($result->execute() !== true) {
|
||||
$error = $result->errorInfo();
|
||||
try {
|
||||
$result = $result->execute();
|
||||
return $result;
|
||||
|
||||
} catch (DBALException $exception) {
|
||||
$this->logger->error(
|
||||
"Could not execute the query: " . implode(", ", $error),
|
||||
"Could not execute the query: " . $exception->getMessage(),
|
||||
["app" => $this->appName]
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,12 +152,15 @@ class DataQuery
|
||||
);
|
||||
|
||||
if ($this->properties[DB::DRIVER] == 'mysql') {
|
||||
if ($this->properties[DB::SSL_CA])
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CA];
|
||||
if ($this->properties[DB::SSL_CERT])
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_CERT];
|
||||
if ($this->properties[DB::SSL_KEY])
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT.'/'.$this->properties[DB::SSL_KEY];
|
||||
if ($this->properties[DB::SSL_CA]) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CA] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_CA];
|
||||
}
|
||||
if ($this->properties[DB::SSL_CERT]) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_CERT] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_CERT];
|
||||
}
|
||||
if ($this->properties[DB::SSL_KEY]) {
|
||||
$parameters["driverOptions"][\PDO::MYSQL_ATTR_SSL_KEY] = \OC::$SERVERROOT . '/' . $this->properties[DB::SSL_KEY];
|
||||
}
|
||||
}
|
||||
|
||||
$this->connection = $connectionFactory->getConnection(
|
||||
@@ -185,7 +190,7 @@ class DataQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = $result->fetch(\PDO::FETCH_COLUMN);
|
||||
$row = $result->fetchOne();
|
||||
if ($row === false) {
|
||||
return $failure;
|
||||
}
|
||||
@@ -211,8 +216,7 @@ class DataQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
$column = $result->fetchAll(\PDO::FETCH_COLUMN);
|
||||
return $column;
|
||||
return $result->fetchFirstColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,8 +236,7 @@ class DataQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
$result->setFetchMode(\PDO::FETCH_CLASS, $entityClass);
|
||||
$entity = $result->fetch();
|
||||
$entity = $result->fetchAssociative();
|
||||
|
||||
if ($entity === false) {
|
||||
return null;
|
||||
@@ -247,7 +250,16 @@ class DataQuery
|
||||
return null;
|
||||
}
|
||||
|
||||
return $entity;
|
||||
return self::arrayToObject($entity, $entityClass);
|
||||
}
|
||||
|
||||
private function arrayToObject($array, $entityClass)
|
||||
{
|
||||
$object = new $entityClass();
|
||||
foreach ($array as $name => $value) {
|
||||
$object->$name = $array[$name];
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,9 +281,15 @@ class DataQuery
|
||||
return false;
|
||||
}
|
||||
|
||||
$result->setFetchMode(\PDO::FETCH_CLASS, $entityClass);
|
||||
$entities = $result->fetchAll();
|
||||
return self::iterableToObjectArray($result->iterateAssociative(), $entityClass);
|
||||
}
|
||||
|
||||
return $entities;
|
||||
private function iterableToObjectArray($array, $entityClass)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($array as $element) {
|
||||
$result[] = self::arrayToObject($element, $entityClass);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user