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