Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PostgresSettingsForm | |
0.00% |
0 / 37 |
|
0.00% |
0 / 3 |
306 | |
0.00% |
0 / 1 |
getHtml | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
submit | |
0.00% |
0 / 31 |
|
0.00% |
0 / 1 |
210 | |||
getPostgresInstaller | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Installer; |
4 | |
5 | use MediaWiki\Status\Status; |
6 | use Wikimedia\Rdbms\DatabasePostgres; |
7 | |
8 | /** |
9 | * @internal |
10 | */ |
11 | class PostgresSettingsForm extends DatabaseSettingsForm { |
12 | |
13 | public function getHtml() { |
14 | if ( $this->getPostgresInstaller()->canCreateAccounts() ) { |
15 | $noCreateMsg = false; |
16 | } else { |
17 | $noCreateMsg = 'config-db-web-no-create-privs'; |
18 | } |
19 | $s = $this->getWebUserBox( $noCreateMsg ); |
20 | |
21 | return $s; |
22 | } |
23 | |
24 | public function submit() { |
25 | $status = $this->submitWebUserBox(); |
26 | if ( !$status->isOK() ) { |
27 | return $status; |
28 | } |
29 | |
30 | $same = $this->getVar( 'wgDBuser' ) === $this->getVar( '_InstallUser' ); |
31 | |
32 | if ( $same ) { |
33 | $exists = true; |
34 | } else { |
35 | // Check if the web user exists |
36 | // Connect to the database with the install user |
37 | $status = $this->getPostgresInstaller()->getPgConnection( 'create-db' ); |
38 | if ( !$status->isOK() ) { |
39 | return $status; |
40 | } |
41 | $conn = $status->getDB(); |
42 | '@phan-var DatabasePostgres $conn'; /** @var DatabasePostgres $conn */ |
43 | $exists = $conn->roleExists( $this->getVar( 'wgDBuser' ) ); |
44 | } |
45 | |
46 | // Validate the create checkbox |
47 | if ( $this->getPostgresInstaller()->canCreateAccounts() && !$same && !$exists ) { |
48 | $create = $this->getVar( '_CreateDBAccount' ); |
49 | } else { |
50 | $this->setVar( '_CreateDBAccount', false ); |
51 | $create = false; |
52 | } |
53 | |
54 | if ( !$create && !$exists ) { |
55 | if ( $this->getPostgresInstaller()->canCreateAccounts() ) { |
56 | $msg = 'config-install-user-missing-create'; |
57 | } else { |
58 | $msg = 'config-install-user-missing'; |
59 | } |
60 | |
61 | return Status::newFatal( $msg, $this->getVar( 'wgDBuser' ) ); |
62 | } |
63 | |
64 | if ( !$exists ) { |
65 | // No more checks to do |
66 | return Status::newGood(); |
67 | } |
68 | |
69 | // Existing web account. Test the connection. |
70 | $status = $this->getPostgresInstaller()->openConnectionToAnyDB( |
71 | $this->getVar( 'wgDBuser' ), |
72 | $this->getVar( 'wgDBpassword' ) ); |
73 | if ( !$status->isOK() ) { |
74 | return $status; |
75 | } |
76 | |
77 | // The web user is conventionally the table owner in PostgreSQL |
78 | // installations. Make sure the install user is able to create |
79 | // objects on behalf of the web user. |
80 | if ( $same || $this->getPostgresInstaller()->canCreateObjectsForWebUser() ) { |
81 | return Status::newGood(); |
82 | } else { |
83 | return Status::newFatal( 'config-pg-not-in-role' ); |
84 | } |
85 | } |
86 | |
87 | /** |
88 | * Downcast the DatabaseInstaller |
89 | * @return PostgresInstaller |
90 | */ |
91 | private function getPostgresInstaller(): PostgresInstaller { |
92 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
93 | return $this->dbInstaller; |
94 | } |
95 | |
96 | } |