Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -117,9 +117,8 @@ |
118 | 118 | |
119 | 119 | $superuser = $this->getVar( '_InstallUser' ); |
120 | 120 | |
121 | | - $rights = $conn->query( 'pg_catalog.pg_user', |
122 | | - 'SELECT |
123 | | - CASE WHEN usesuper IS TRUE THEN |
| 121 | + $rights = $conn->selectField( 'pg_catalog.pg_user', |
| 122 | + 'CASE WHEN usesuper IS TRUE THEN |
124 | 123 | CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END |
125 | 124 | ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END |
126 | 125 | END AS rights', |
— | — | @@ -137,6 +136,52 @@ |
138 | 137 | return true; |
139 | 138 | } |
140 | 139 | |
| 140 | + public function getSettingsForm() { |
| 141 | + if ( $this->canCreateAccounts() ) { |
| 142 | + $noCreateMsg = false; |
| 143 | + } else { |
| 144 | + $noCreateMsg = 'config-db-web-no-create-privs'; |
| 145 | + } |
| 146 | + $s = $this->getWebUserBox( $noCreateMsg ); |
| 147 | + |
| 148 | + return $s; |
| 149 | + } |
| 150 | + |
| 151 | + public function submitSettingsForm() { |
| 152 | + $status = $this->submitWebUserBox(); |
| 153 | + if ( !$status->isOK() ) { |
| 154 | + return $status; |
| 155 | + } |
| 156 | + |
| 157 | + // Validate the create checkbox |
| 158 | + $canCreate = $this->canCreateAccounts(); |
| 159 | + if ( !$canCreate ) { |
| 160 | + $this->setVar( '_CreateDBAccount', false ); |
| 161 | + $create = false; |
| 162 | + } else { |
| 163 | + $create = $this->getVar( '_CreateDBAccount' ); |
| 164 | + } |
| 165 | + |
| 166 | + if ( !$create ) { |
| 167 | + // Test the web account |
| 168 | + try { |
| 169 | + new DatabasePostgres( |
| 170 | + $this->getVar( 'wgDBserver' ), |
| 171 | + $this->getVar( 'wgDBuser' ), |
| 172 | + $this->getVar( 'wgDBpassword' ), |
| 173 | + false, |
| 174 | + false, |
| 175 | + 0, |
| 176 | + $this->getVar( 'wgDBprefix' ) |
| 177 | + ); |
| 178 | + } catch ( DBConnectionError $e ) { |
| 179 | + return Status::newFatal( 'config-connection-error', $e->getMessage() ); |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + return Status::newGood(); |
| 184 | + } |
| 185 | + |
141 | 186 | public function preInstall() { |
142 | 187 | $commitCB = array( |
143 | 188 | 'name' => 'pg-commit', |
— | — | @@ -152,6 +197,7 @@ |
153 | 198 | ); |
154 | 199 | $this->parent->addInstallStep( $commitCB, 'interwiki' ); |
155 | 200 | $this->parent->addInstallStep( $userCB ); |
| 201 | + $this->parent->addInstallStep( $ts2CB, 'setupDatabase' ); |
156 | 202 | } |
157 | 203 | |
158 | 204 | function setupDatabase() { |
— | — | @@ -161,23 +207,23 @@ |
162 | 208 | } |
163 | 209 | $conn = $status->value; |
164 | 210 | |
165 | | - // Make sure that we can write to the correct schema |
166 | | - // If not, Postgres will happily and silently go to the next search_path item |
167 | | - $schema = $this->getVar( 'wgDBmwschema' ); |
168 | | - $ctest = 'mediawiki_test_table'; |
169 | | - $safeschema = $conn->addIdentifierQuotes( $schema ); |
170 | | - if ( $conn->tableExists( $ctest, $schema ) ) { |
171 | | - $conn->query( "DROP TABLE $safeschema.$ctest" ); |
172 | | - } |
173 | | - $res = $conn->query( "CREATE TABLE $safeschema.$ctest(a int)" ); |
174 | | - if ( !$res ) { |
175 | | - $status->fatal( 'config-install-pg-schema-failed', |
176 | | - $this->getVar( 'wgDBuser'), $schema ); |
177 | | - } |
178 | | - $conn->query( "DROP TABLE $safeschema.$ctest" ); |
179 | | - |
180 | 211 | $dbName = $this->getVar( 'wgDBname' ); |
181 | 212 | if( !$conn->selectDB( $dbName ) ) { |
| 213 | + // Make sure that we can write to the correct schema |
| 214 | + // If not, Postgres will happily and silently go to the next search_path item |
| 215 | + $schema = $this->getVar( 'wgDBmwschema' ); |
| 216 | + $ctest = 'mediawiki_test_table'; |
| 217 | + $safeschema = $conn->addIdentifierQuotes( $schema ); |
| 218 | + if ( $conn->tableExists( $ctest, $schema ) ) { |
| 219 | + $conn->query( "DROP TABLE $safeschema.$ctest" ); |
| 220 | + } |
| 221 | + $res = $conn->query( "CREATE TABLE $safeschema.$ctest(a int)" ); |
| 222 | + if ( !$res ) { |
| 223 | + $status->fatal( 'config-install-pg-schema-failed', |
| 224 | + $this->getVar( 'wgDBuser'), $schema ); |
| 225 | + } |
| 226 | + $conn->query( "DROP TABLE $safeschema.$ctest" ); |
| 227 | + |
182 | 228 | $safedb = $conn->addIdentifierQuotes( $dbName ); |
183 | 229 | $safeuser = $conn->addQuotes( $this->getVar( 'wgDBuser' ) ); |
184 | 230 | $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ ); |