diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-05 14:31:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 14:31:37 +0100 |
commit | 9e95a89ab7d84f5b15e3b60880ec78ece9de0856 (patch) | |
tree | 79a83f47593f1915e1febf42dc1f16d9720c3113 /lib/private/Setup | |
parent | d9035e2805f2900cd1c78cc8ab22fdd1dfeb4b3e (diff) | |
parent | 7293a4e5ecaaa7313c144d8689678d3cca09e23d (diff) | |
download | nextcloud-server-9e95a89ab7d84f5b15e3b60880ec78ece9de0856.tar.gz nextcloud-server-9e95a89ab7d84f5b15e3b60880ec78ece9de0856.zip |
Merge pull request #2535 from nextcloud/allow-to-reuse-admin-as-install-name-like-on-mysql
Allow to reuse the same name when installing a new instance on postgres
Diffstat (limited to 'lib/private/Setup')
-rw-r--r-- | lib/private/Setup/PostgreSQL.php | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 085e8609ab2..c01e5bc0332 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -150,14 +150,16 @@ class PostgreSQL extends AbstractDatabase { } private function createDBUser(IDBConnection $connection) { + $dbUser = $this->dbUser; try { - if ($this->userExists($connection)) { - // change the password - $query = $connection->prepare("ALTER ROLE " . addslashes($this->dbUser) . " WITH CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); - } else { - // create the user - $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); - } + $i = 1; + while ($this->userExists($connection)) { + $i++; + $this->dbUser = $dbUser . $i; + }; + + // create the user + $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); $query->execute(); } catch (DatabaseException $e) { $this->logger->error('Error while trying to create database user'); |