Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -151,6 +151,7 @@ |
152 | 152 | if ( !strlen( $user ) ) { # e.g. the class is being loaded |
153 | 153 | return; |
154 | 154 | } |
| 155 | + |
155 | 156 | $this->close(); |
156 | 157 | $this->mServer = $server; |
157 | 158 | $this->mPort = $port = $wgDBport; |
— | — | @@ -1014,6 +1015,7 @@ |
1015 | 1016 | if ( !$schema ) { |
1016 | 1017 | $schema = $wgDBmwschema; |
1017 | 1018 | } |
| 1019 | + $table = $this->tableName( $table ); |
1018 | 1020 | $etable = $this->addQuotes( $table ); |
1019 | 1021 | $eschema = $this->addQuotes( $schema ); |
1020 | 1022 | $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n " |
Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | ); |
26 | 26 | |
27 | 27 | var $minimumVersion = '8.3'; |
| 28 | + var $useAdmin = FALSE; |
28 | 29 | |
29 | 30 | function getName() { |
30 | 31 | return 'postgres'; |
— | — | @@ -69,17 +70,18 @@ |
70 | 71 | return $status; |
71 | 72 | } |
72 | 73 | |
| 74 | + $this->useAdmin = TRUE; |
73 | 75 | // Try to connect |
74 | | - $status->merge( $this->getConnection( 'template1' ) ); |
| 76 | + $status->merge( $this->getConnection() ); |
75 | 77 | if ( !$status->isOK() ) { |
76 | 78 | return $status; |
77 | 79 | } |
78 | 80 | |
79 | | -/* //Make sure install user can create |
| 81 | + //Make sure install user can create |
80 | 82 | $status->merge( $this->canCreateAccounts() ); |
81 | 83 | if ( !$status->isOK() ) { |
82 | 84 | return $status; |
83 | | - } */ |
| 85 | + } |
84 | 86 | |
85 | 87 | // Check version |
86 | 88 | $version = $this->db->getServerVersion(); |
— | — | @@ -92,14 +94,22 @@ |
93 | 95 | return $status; |
94 | 96 | } |
95 | 97 | |
96 | | - function openConnection( $database = 'template1' ) { |
| 98 | + public function openConnection() { |
97 | 99 | $status = Status::newGood(); |
98 | 100 | try { |
99 | | - $db = new DatabasePostgres( |
100 | | - $this->getVar( 'wgDBserver' ), |
101 | | - $this->getVar( '_InstallUser' ), |
102 | | - $this->getVar( '_InstallPassword' ), |
103 | | - $database ); |
| 101 | + if ( $this->useAdmin ) { |
| 102 | + $db = new DatabasePostgres( |
| 103 | + $this->getVar( 'wgDBserver' ), |
| 104 | + $this->getVar( '_InstallUser' ), |
| 105 | + $this->getVar( '_InstallPassword' ), |
| 106 | + 'template1' ); |
| 107 | + } else { |
| 108 | + $db = new DatabasePostgres( |
| 109 | + $this->getVar( 'wgDBserver' ), |
| 110 | + $this->getVar( 'wgDBuser' ), |
| 111 | + $this->getVar( 'wgDBpassword' ), |
| 112 | + $this->getVar( 'wgDBname' ) ); |
| 113 | + } |
104 | 114 | $status->value = $db; |
105 | 115 | } catch ( DBConnectionError $e ) { |
106 | 116 | $status->fatal( 'config-connection-error', $e->getMessage() ); |
— | — | @@ -107,32 +117,9 @@ |
108 | 118 | return $status; |
109 | 119 | } |
110 | 120 | |
111 | | - function getConnection($database = null) { |
112 | | - $status = Status::newGood(); |
113 | | - |
114 | | - if( is_null( $database ) ) { |
115 | | - $dbname = $this->getVar( 'wgDBname' ); |
116 | | - $dbuser = $this->getVar( 'wgDBuser' ); |
117 | | - $dbpass = $this->getVar( 'wgDBpassword' ); |
118 | | - } else { |
119 | | - $dbname = $database; |
120 | | - $dbuser = $this->getVar( '_InstallUser' ); |
121 | | - $dbpass = $this->getVar( '_InstallPassword' ); |
122 | | - } |
123 | | - |
124 | | - try { |
125 | | - $this->db = new DatabasePostgres( |
126 | | - $this->getVar( 'wgDBserver' ), |
127 | | - $dbuser, $dbpass, $dbname ); |
128 | | - $status->value = $this->db; |
129 | | - } catch ( DBConnectionError $e ) { |
130 | | - $status->fatal( 'config-connection-error', $e->getMessage() ); |
131 | | - } |
132 | | - return $status; |
133 | | - } |
134 | | - |
135 | 121 | protected function canCreateAccounts() { |
136 | | - $status = $this->getConnection( 'template1' ); |
| 122 | + $this->useAdmin = TRUE; |
| 123 | + $status = $this->getConnection(); |
137 | 124 | if ( !$status->isOK() ) { |
138 | 125 | return false; |
139 | 126 | } |
— | — | @@ -224,7 +211,8 @@ |
225 | 212 | } |
226 | 213 | |
227 | 214 | function setupDatabase() { |
228 | | - $status = $this->getConnection( 'template1' ); |
| 215 | + $this->useAdmin = TRUE; |
| 216 | + $status = $this->getConnection(); |
229 | 217 | if ( !$status->isOK() ) { |
230 | 218 | return $status; |
231 | 219 | } |
— | — | @@ -273,7 +261,6 @@ |
274 | 262 | "FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n\n" . |
275 | 263 | "WHERE p.pronamespace = n.oid AND n.nspname = $safeschema2"; |
276 | 264 | $res = $conn->query( $SQL ); |
277 | | - $conn->query( "SET search_path = $safeschema" ); |
278 | 265 | } |
279 | 266 | } |
280 | 267 | return $status; |
— | — | @@ -289,27 +276,31 @@ |
290 | 277 | return Status::newGood(); |
291 | 278 | } |
292 | 279 | |
293 | | - $status = $this->getConnection( 'template1' ); |
| 280 | + $this->useAdmin = TRUE; |
| 281 | + $status = $this->getConnection(); |
| 282 | + |
294 | 283 | if ( !$status->isOK() ) { |
295 | 284 | return $status; |
296 | 285 | } |
297 | 286 | |
298 | 287 | $db = $this->getVar( 'wgDBname' ); |
| 288 | + $schema = $this->getVar( 'wgDBmwschema' ); |
299 | 289 | $this->db->selectDB( $db ); |
300 | 290 | $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) ); |
301 | 291 | $safeusercheck = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) ); |
302 | 292 | $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) ); |
| 293 | + $safeschema = $this->db->addIdentifierQuotes( $schema ); |
303 | 294 | |
304 | 295 | $rows = $this->db->numRows( |
305 | 296 | $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" ) |
306 | 297 | ); |
307 | 298 | if ( $rows < 1 ) { |
308 | | - $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ ); |
309 | | - |
| 299 | + $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ ); |
310 | 300 | if ( $res !== true && !( $res instanceOf ResultWrapper ) ) { |
311 | 301 | $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res ); |
| 302 | + } |
| 303 | + $this->db->query("ALTER USER $safeuser SET search_path = $safeschema"); |
312 | 304 | } |
313 | | - } |
314 | 305 | |
315 | 306 | return $status; |
316 | 307 | } |
— | — | @@ -332,7 +323,41 @@ |
333 | 324 | $wgDBpassword = $this->getVar( '_InstallPassword' ); |
334 | 325 | } |
335 | 326 | |
| 327 | + public function createTables() { |
| 328 | + $this->db = NULL; |
| 329 | + $this->useAdmin = FALSE; |
| 330 | + $status = $this->getConnection(); |
| 331 | + var_export($status); |
| 332 | + if ( !$status->isOK() ) { |
| 333 | + return $status; |
| 334 | + } |
| 335 | + $this->db->selectDB( $this->getVar( 'wgDBname' ) ); |
| 336 | + |
| 337 | + if( $this->db->tableExists( 'user' ) ) { |
| 338 | + $status->warning( 'config-install-tables-exist' ); |
| 339 | + return $status; |
| 340 | + } |
| 341 | + |
| 342 | + $this->db->setFlag( DBO_DDLMODE ); // For Oracle's handling of schema files |
| 343 | + $this->db->begin( __METHOD__ ); |
| 344 | + |
| 345 | + $error = $this->db->sourceFile( $this->db->getSchema() ); |
| 346 | + if( $error !== true ) { |
| 347 | + $this->db->reportQueryError( $error, 0, '', __METHOD__ ); |
| 348 | + $this->db->rollback( __METHOD__ ); |
| 349 | + $status->fatal( 'config-install-tables-failed', $error ); |
| 350 | + } else { |
| 351 | + $this->db->commit( __METHOD__ ); |
| 352 | + } |
| 353 | + // Resume normal operations |
| 354 | + if( $status->isOk() ) { |
| 355 | + $this->enableLB(); |
| 356 | + } |
| 357 | + return $status; |
| 358 | + } |
| 359 | + |
336 | 360 | public function setupPLpgSQL() { |
| 361 | + $this->useAdmin = TRUE; |
337 | 362 | $status = $this->getConnection(); |
338 | 363 | if ( !$status->isOK() ) { |
339 | 364 | return $status; |