1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PHPPgAdmin 6.1.3 |
||
5 | */ |
||
6 | |||
7 | namespace PHPPgAdmin\Database; |
||
8 | |||
9 | /** |
||
10 | * @file |
||
11 | * PostgreSQL 9.6 support |
||
12 | */ |
||
13 | class Postgres96 extends Postgres |
||
14 | { |
||
15 | public $typIndexes = ['BTREE', 'BRIN', 'RTREE', 'GIST', 'GIN', 'HASH', 'SP-GIST']; |
||
16 | |||
17 | /** |
||
18 | * @var float |
||
19 | */ |
||
20 | public $major_version = 9.6; |
||
21 | |||
22 | /** |
||
23 | * @var class-string |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
24 | */ |
||
25 | public $help_classname = \PHPPgAdmin\Help\PostgresDoc96::class; |
||
26 | |||
27 | // Administration functions |
||
28 | |||
29 | /** |
||
30 | * Returns all available process information. |
||
31 | * |
||
32 | * @param null|string $database (optional) Find only connections to specified database |
||
33 | * |
||
34 | * @return int|\PHPPgAdmin\ADORecordSet A recordset |
||
35 | */ |
||
36 | public function getProcesses($database = null) |
||
37 | { |
||
38 | if (null === $database) { |
||
39 | $sql = "SELECT datid, datname, pid, usename, application_name, client_addr, state, wait_event_type, wait_event, state_change as query_start, |
||
40 | CASE |
||
41 | WHEN state='active' THEN query |
||
42 | ELSE state |
||
43 | END AS query |
||
44 | FROM pg_catalog.pg_stat_activity |
||
45 | ORDER BY datname, usename, pid"; |
||
46 | } else { |
||
47 | $this->clean($database); |
||
48 | $sql = "SELECT datid, datname, pid, usename, application_name, client_addr, state, wait_event_type, wait_event, state_change as query_start, |
||
49 | CASE |
||
50 | WHEN state='active' THEN query |
||
51 | ELSE state |
||
52 | END AS query |
||
53 | FROM pg_catalog.pg_stat_activity |
||
54 | WHERE datname='{$database}' |
||
55 | ORDER BY usename, pid"; |
||
56 | } |
||
57 | |||
58 | return $this->selectSet($sql); |
||
59 | } |
||
60 | |||
61 | public function hasUserSignals() |
||
62 | { |
||
63 | return true; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Creates a new user. As of PG 9.6, CREATEUSER privilege has been deprecated. |
||
68 | * |
||
69 | * @see {@link https://www.postgresql.org/docs/9.6/static/sql-createrole.html} |
||
70 | * |
||
71 | * @param string $username The username of the user to create |
||
72 | * @param string $password A password for the user |
||
73 | * @param bool $createdb boolean Whether or not the user can create databases |
||
74 | * @param bool $createrole boolean Whether or not the user can create other users |
||
75 | * @param string $expiry string Format 'YYYY-MM-DD HH:MM:SS'. '' means never expire |
||
76 | * @param array $groups The groups to create the user in |
||
77 | * |
||
78 | * @return int|\PHPPgAdmin\ADORecordSet 0 if operation was successful |
||
79 | * |
||
80 | * @internal param $group (array) The groups to create the user in |
||
81 | */ |
||
82 | public function createUser($username, $password, $createdb, $createrole, $expiry, $groups) |
||
83 | { |
||
84 | $enc = $this->_encryptPassword($username, $password); |
||
85 | $this->fieldClean($username); |
||
86 | $this->clean($enc); |
||
87 | $this->clean($expiry); |
||
88 | $this->fieldArrayClean($groups); |
||
89 | |||
90 | $sql = "CREATE USER \"{$username}\""; |
||
91 | |||
92 | if ('' !== $password) { |
||
93 | $sql .= " WITH ENCRYPTED PASSWORD '{$enc}'"; |
||
94 | } |
||
95 | |||
96 | $sql .= $createdb ? ' CREATEDB' : ' NOCREATEDB'; |
||
97 | $sql .= $createrole ? ' CREATEROLE' : ' NOCREATEROLE'; |
||
98 | |||
99 | if (\is_array($groups) && 0 < \count($groups)) { |
||
100 | $sql .= ' IN GROUP "' . \implode('", "', $groups) . '"'; |
||
101 | } |
||
102 | |||
103 | if ('' !== $expiry) { |
||
104 | $sql .= " VALID UNTIL '{$expiry}'"; |
||
105 | } else { |
||
106 | $sql .= " VALID UNTIL 'infinity'"; |
||
107 | } |
||
108 | |||
109 | return $this->execute($sql); |
||
110 | } |
||
111 | } |
||
112 |