summaryrefslogtreecommitdiffstats
path: root/lib/private/Setup
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-12-06 19:04:57 +0100
committerJoas Schilling <coding@schilljs.com>2016-12-12 17:28:57 +0100
commit7293a4e5ecaaa7313c144d8689678d3cca09e23d (patch)
tree142fc03226e6ec0d02007c6d65fd1ef8c2c4b464 /lib/private/Setup
parent6cd421e6034c0d9b43696630958e79fb94c1cbaf (diff)
downloadnextcloud-server-7293a4e5ecaaa7313c144d8689678d3cca09e23d.tar.gz
nextcloud-server-7293a4e5ecaaa7313c144d8689678d3cca09e23d.zip
Allow to reuse the same name when installing a new instance
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Setup')
-rw-r--r--lib/private/Setup/PostgreSQL.php16
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');