DataQuery::connectToDatabase(), throw wenn called with empty configuration rather than producing obscure PHP errors.

This commit is contained in:
Claus-Justus Heine
2025-12-05 10:45:00 +01:00
parent 36ad938942
commit fad85d01e0
+8
View File
@@ -4,6 +4,8 @@
* *
* @copyright 2021 Marcin Łojewski <dev@mlojewski.me> * @copyright 2021 Marcin Łojewski <dev@mlojewski.me>
* @author Marcin Łojewski <dev@mlojewski.me> * @author Marcin Łojewski <dev@mlojewski.me>
* @copyright 2025 Claus-Justus Heine
* @author Claus-Justus Heine <himself@claus-justus-heine.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
@@ -21,6 +23,8 @@
namespace OCA\UserSQL\Query; namespace OCA\UserSQL\Query;
use UnexpectedValueException;
use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception as DBALException;
use OC\DB\Connection; use OC\DB\Connection;
@@ -151,6 +155,10 @@ class DataQuery
"driverOptions" => array() "driverOptions" => array()
); );
if (empty($this->properties[DB::DRIVER])) {
throw new UnexpectedValueException('Attempt to connect without configuration.');
}
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];