Skip to content

Commit add8bde

Browse files
whlsxlsusnux
authored andcommitted
fix: use $this->tryCreateDbUser condition
1 parent c7524d9 commit add8bde

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/private/Setup/PostgreSQL.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function setupDatabase($username) {
6262
$canCreateRoles = false;
6363
}
6464

65-
$connectionMainDatabase;
6665
if ($canCreateRoles) {
6766
$connectionMainDatabase = $this->connect();
6867
//use the admin login data for the new database user
@@ -86,16 +85,18 @@ public function setupDatabase($username) {
8685
// the connection to dbname=postgres is not needed anymore
8786
$connection->close();
8887

89-
if ($canCreateRoles) {
90-
// Go to the main database and grant create on the public schema
91-
// The code below is implemented to make installing possible with PostgreSQL version 15:
92-
// https://www.postgresql.org/docs/release/15.0/
93-
// From the release notes: For new databases having no need to defend against insider threats, granting CREATE permission will yield the behavior of prior releases
94-
// Therefore we assume that the database is only used by one user/service which is Nextcloud
95-
// Additional services should get installed in a separate database in order to stay secure
96-
// Also see https://www.postgresql.org/docs/15/ddl-schemas.html#DDL-SCHEMAS-PATTERNS
97-
$connectionMainDatabase->executeQuery('GRANT CREATE ON SCHEMA public TO "' . addslashes($this->dbUser) . '"');
98-
$connectionMainDatabase->close();
88+
if ($this->tryCreateDbUser) {
89+
if ($canCreateRoles) {
90+
// Go to the main database and grant create on the public schema
91+
// The code below is implemented to make installing possible with PostgreSQL version 15:
92+
// https://www.postgresql.org/docs/release/15.0/
93+
// From the release notes: For new databases having no need to defend against insider threats, granting CREATE permission will yield the behavior of prior releases
94+
// Therefore we assume that the database is only used by one user/service which is Nextcloud
95+
// Additional services should get installed in a separate database in order to stay secure
96+
// Also see https://www.postgresql.org/docs/15/ddl-schemas.html#DDL-SCHEMAS-PATTERNS
97+
$connectionMainDatabase->executeQuery('GRANT CREATE ON SCHEMA public TO "' . addslashes($this->dbUser) . '"');
98+
$connectionMainDatabase->close();
99+
}
99100
}
100101
} catch (\Exception $e) {
101102
$this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created', [

0 commit comments

Comments
 (0)