Fix usage of the PostgreSQL system function has_database/table_privilege

On PostgreSQL < 8.4 the system functions has_database_privilege() and
has_table_privilege() do no support comma separated privilege types.

fixes #8354
This commit is contained in:
Johannes Meyer 2015-02-04 13:20:41 +01:00
parent 6bae2e0a53
commit a8e0b7effc
1 changed files with 22 additions and 18 deletions

View File

@ -727,28 +727,32 @@ EOD;
} }
if (false === empty($dbPrivileges)) { if (false === empty($dbPrivileges)) {
$query = $this->query( foreach ($dbPrivileges as $dbPrivilege) {
'SELECT has_database_privilege(:user, :dbname, :privileges) AS db_privileges_granted', $query = $this->query(
array( 'SELECT has_database_privilege(:user, :dbname, :privilege) AS db_privilege_granted',
':user' => $username !== null ? $username : $this->config['username'], array(
':dbname' => $this->config['dbname'], ':user' => $username !== null ? $username : $this->config['username'],
':privileges' => join(',', $dbPrivileges) . ($requireGrants ? ' WITH GRANT OPTION' : '') ':dbname' => $this->config['dbname'],
) ':privilege' => $dbPrivilege . ($requireGrants ? ' WITH GRANT OPTION' : '')
); )
$privilegesGranted &= $query->fetchObject()->db_privileges_granted; );
$privilegesGranted &= $query->fetchObject()->db_privilege_granted;
}
} }
if (false === empty($tablePrivileges)) { if (false === empty($tablePrivileges)) {
foreach (array_intersect($context, $this->listTables()) as $table) { foreach (array_intersect($context, $this->listTables()) as $table) {
$query = $this->query( foreach ($tablePrivileges as $tablePrivilege) {
'SELECT has_table_privilege(:user, :table, :privileges) AS table_privileges_granted', $query = $this->query(
array( 'SELECT has_table_privilege(:user, :table, :privilege) AS table_privilege_granted',
':user' => $username !== null ? $username : $this->config['username'], array(
':table' => $table, ':user' => $username !== null ? $username : $this->config['username'],
':privileges' => join(',', $tablePrivileges) . ($requireGrants ? ' WITH GRANT OPTION' : '') ':table' => $table,
) ':privilege' => $tablePrivilege . ($requireGrants ? ' WITH GRANT OPTION' : '')
); )
$privilegesGranted &= $query->fetchObject()->table_privileges_granted; );
$privilegesGranted &= $query->fetchObject()->table_privilege_granted;
}
} }
} }
} else { } else {