diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-03 15:28:31 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-08 11:45:19 +0100 |
commit | 8b64e92b9262d2a2eec6345685ce421050f95c66 (patch) | |
tree | dd51490b8a184b2643414d11867a9fa450aa5065 /lib/private/Setup | |
parent | 84e6e9f7cf19207041925eaa237d24e1c12c2c2d (diff) | |
download | nextcloud-server-8b64e92b9262d2a2eec6345685ce421050f95c66.tar.gz nextcloud-server-8b64e92b9262d2a2eec6345685ce421050f95c66.zip |
Bump doctrine/dbal from 2.12.0 to 3.0.0
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Setup')
-rw-r--r-- | lib/private/Setup/AbstractDatabase.php | 5 | ||||
-rw-r--r-- | lib/private/Setup/MySQL.php | 42 | ||||
-rw-r--r-- | lib/private/Setup/PostgreSQL.php | 10 |
3 files changed, 28 insertions, 29 deletions
diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 8a9aed09f1b..e0761db3070 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -29,6 +29,7 @@ namespace OC\Setup; +use OC\DB\Connection; use OC\DB\ConnectionFactory; use OC\DB\MigrationService; use OC\SystemConfig; @@ -108,7 +109,7 @@ abstract class AbstractDatabase { * @param array $configOverwrite * @return \OC\DB\Connection */ - protected function connect(array $configOverwrite = []) { + protected function connect(array $configOverwrite = []): Connection { $connectionParams = [ 'host' => $this->dbHost, 'user' => $this->dbUser, @@ -149,7 +150,7 @@ abstract class AbstractDatabase { if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { return; } - $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); + $ms = new MigrationService('core', \OC::$server->get(Connection::class)); $ms->migrate('latest', true); } } diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 966c97edf55..21339dc46d0 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -31,6 +31,7 @@ namespace OC\Setup; +use OC\DB\ConnectionAdapter; use OC\DB\MySqlTools; use OCP\IDBConnection; use OCP\ILogger; @@ -45,12 +46,12 @@ class MySQL extends AbstractDatabase { // detect mb4 $tools = new MySqlTools(); - if ($tools->supports4ByteCharset($connection)) { + if ($tools->supports4ByteCharset(new ConnectionAdapter($connection))) { $this->config->setValue('mysql.utf8mb4', true); $connection = $this->connect(['dbname' => null]); } - $this->createSpecificUser($username, $connection); + $this->createSpecificUser($username, new ConnectionAdapter($connection)); //create the database $this->createDatabase($connection); @@ -156,27 +157,24 @@ class MySQL extends AbstractDatabase { $result = $connection->executeQuery($query, [$adminUser]); //current dbuser has admin rights - if ($result) { - $data = $result->fetchAll(); - //new dbuser does not exist - if (count($data) === 0) { - //use the admin login data for the new database user - $this->dbUser = $adminUser; - - //create a random password so we don't need to store the admin password in the config file - $this->dbPassword = $this->random->generate(30); - - $this->createDBUser($connection); - - break; - } else { - //repeat with different username - $length = strlen((string)$i); - $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; - $i++; - } - } else { + $data = $result->fetchAll(); + $result->closeCursor(); + //new dbuser does not exist + if (count($data) === 0) { + //use the admin login data for the new database user + $this->dbUser = $adminUser; + + //create a random password so we don't need to store the admin password in the config file + $this->dbPassword = $this->random->generate(30); + + $this->createDBUser($connection); + break; + } else { + //repeat with different username + $length = strlen((string)$i); + $adminUser = substr('oc_' . $username, 0, 16 - $length) . $i; + $i++; } } } diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 1f0b7b8f894..7e59bf297f1 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -30,8 +30,8 @@ namespace OC\Setup; use OC\DatabaseException; +use OC\DB\Connection; use OC\DB\QueryBuilder\Literal; -use OCP\IDBConnection; class PostgreSQL extends AbstractDatabase { public $dbprettyname = 'PostgreSQL'; @@ -103,7 +103,7 @@ class PostgreSQL extends AbstractDatabase { } } - private function createDatabase(IDBConnection $connection) { + private function createDatabase(Connection $connection) { if (!$this->databaseExists($connection)) { //The database does not exists... let's create it $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); @@ -124,7 +124,7 @@ class PostgreSQL extends AbstractDatabase { } } - private function userExists(IDBConnection $connection) { + private function userExists(Connection $connection) { $builder = $connection->getQueryBuilder(); $builder->automaticTablePrefix(false); $query = $builder->select('*') @@ -134,7 +134,7 @@ class PostgreSQL extends AbstractDatabase { return $result->rowCount() > 0; } - private function databaseExists(IDBConnection $connection) { + private function databaseExists(Connection $connection) { $builder = $connection->getQueryBuilder(); $builder->automaticTablePrefix(false); $query = $builder->select('datname') @@ -144,7 +144,7 @@ class PostgreSQL extends AbstractDatabase { return $result->rowCount() > 0; } - private function createDBUser(IDBConnection $connection) { + private function createDBUser(Connection $connection) { $dbUser = $this->dbUser; try { $i = 1; |