Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/user_sql.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Łojewski <marcin.lojewski@pentacomp.pl>2021-03-24 13:40:46 +0300
committerMarcin Łojewski <marcin.lojewski@pentacomp.pl>2021-03-24 13:53:35 +0300
commit49d1c76a6103bebba209c09f7aae550822c4d55a (patch)
tree89c3cfcd87e4594dfa171fd00654d38c6d3e6bcf
parent09d710fc8414465e78ee02e29b641844d0e7dda6 (diff)
Support Doctrine 3
-rw-r--r--CHANGELOG.md3
-rw-r--r--appinfo/info.xml2
-rw-r--r--lib/Controller/SettingsController.php17
-rw-r--r--lib/Query/DataQuery.php60
4 files changed, 53 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f868a4f..5015a67 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 7402b67..de0bd55 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -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>
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 0e59261..845abf9 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -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);
diff --git a/lib/Query/DataQuery.php b/lib/Query/DataQuery.php
index c71b464..2f11c55 100644
--- a/lib/Query/DataQuery.php
+++ b/lib/Query/DataQuery.php
@@ -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;
}
}