Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -1275,57 +1275,6 @@ |
1276 | 1276 | return $sql; |
1277 | 1277 | } |
1278 | 1278 | |
1279 | | - function setup_database() { |
1280 | | - global $wgDBmwschema, $wgDBuser; |
1281 | | - |
1282 | | - // Make sure that we can write to the correct schema |
1283 | | - // If not, Postgres will happily and silently go to the next search_path item |
1284 | | - $ctest = 'mediawiki_test_table'; |
1285 | | - $safeschema = $this->quote_ident( $wgDBmwschema ); |
1286 | | - if ( $this->tableExists( $ctest, $wgDBmwschema ) ) { |
1287 | | - $this->doQuery( "DROP TABLE $safeschema.$ctest" ); |
1288 | | - } |
1289 | | - $SQL = "CREATE TABLE $safeschema.$ctest(a int)"; |
1290 | | - $olde = error_reporting( 0 ); |
1291 | | - $res = $this->doQuery( $SQL ); |
1292 | | - error_reporting( $olde ); |
1293 | | - if ( !$res ) { |
1294 | | - print '<b>FAILED</b>. Make sure that the user "' . htmlspecialchars( $wgDBuser ) . |
1295 | | - '" can write to the schema "' . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n"; |
1296 | | - dieout( '' ); # Will close the main list <ul> and finish the page. |
1297 | | - } |
1298 | | - $this->doQuery( "DROP TABLE $safeschema.$ctest" ); |
1299 | | - |
1300 | | - $res = $this->sourceFile( "../maintenance/postgres/tables.sql" ); |
1301 | | - if ( $res === true ) { |
1302 | | - print " done.</li>\n"; |
1303 | | - } else { |
1304 | | - print " <b>FAILED</b></li>\n"; |
1305 | | - dieout( htmlspecialchars( $res ) ); |
1306 | | - } |
1307 | | - |
1308 | | - echo '<li>Populating interwiki table... '; |
1309 | | - # Avoid the non-standard "REPLACE INTO" syntax |
1310 | | - $f = fopen( "../maintenance/interwiki.sql", 'r' ); |
1311 | | - if ( !$f ) { |
1312 | | - print '<b>FAILED</b></li>'; |
1313 | | - dieout( 'Could not find the interwiki.sql file' ); |
1314 | | - } |
1315 | | - # We simply assume it is already empty as we have just created it |
1316 | | - $SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES "; |
1317 | | - while ( !feof( $f ) ) { |
1318 | | - $line = fgets( $f, 1024 ); |
1319 | | - $matches = array(); |
1320 | | - if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) { |
1321 | | - continue; |
1322 | | - } |
1323 | | - $this->query( "$SQL $matches[1],$matches[2])" ); |
1324 | | - } |
1325 | | - print " successfully populated.</li>\n"; |
1326 | | - |
1327 | | - $this->doQuery( 'COMMIT' ); |
1328 | | - } |
1329 | | - |
1330 | 1279 | function encodeBlob( $b ) { |
1331 | 1280 | return new Blob( pg_escape_bytea( $this->mConn, $b ) ); |
1332 | 1281 | } |
Index: trunk/phase3/includes/installer/Installer.i18n.php |
— | — | @@ -461,6 +461,7 @@ |
462 | 462 | 'config-install-database' => 'Setting up database', |
463 | 463 | 'config-install-pg-schema-failed' => 'Tables creation failed. |
464 | 464 | Make sure that the user "$1" can write to the schema "$2".', |
| 465 | + 'config-install-pg-commit' => 'Committing changes', |
465 | 466 | 'config-install-user' => 'Creating database user', |
466 | 467 | 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2', |
467 | 468 | 'config-install-tables' => 'Creating tables', |
Index: trunk/phase3/includes/installer/DatabaseInstaller.php |
— | — | @@ -97,9 +97,10 @@ |
98 | 98 | /** |
99 | 99 | * Connect to the database using the administrative user/password currently |
100 | 100 | * defined in the session. On success, return the connection, on failure, |
101 | | - * return a Status object. |
102 | 101 | * |
103 | 102 | * This may be called multiple times, so the result should be cached. |
| 103 | + * |
| 104 | + * @return Status |
104 | 105 | */ |
105 | 106 | public abstract function getConnection(); |
106 | 107 | |
Index: trunk/phase3/includes/installer/PostgresInstaller.php |
— | — | @@ -107,9 +107,44 @@ |
108 | 108 | return $status; |
109 | 109 | } |
110 | 110 | |
| 111 | + public function preInstall() { |
| 112 | + # Add our user callback to installSteps, right before the tables are created. |
| 113 | + $callback = array( |
| 114 | + 'name' => 'pg-commit', |
| 115 | + 'callback' => array( $this, 'commitChanges' ), |
| 116 | + ); |
| 117 | + $this->parent->addInstallStepFollowing( 'interwiki', $callback ); |
| 118 | + } |
| 119 | + |
111 | 120 | function setupDatabase() { |
| 121 | + $status = $this->getConnection(); |
| 122 | + if ( !$status->isOK() ) { |
| 123 | + return $status; |
| 124 | + } |
| 125 | + $conn = $status->value; |
| 126 | + |
| 127 | + // Make sure that we can write to the correct schema |
| 128 | + // If not, Postgres will happily and silently go to the next search_path item |
| 129 | + $schema = $this->getVar( 'wgDBmwschema' ); |
| 130 | + $ctest = 'mediawiki_test_table'; |
| 131 | + $safeschema = $conn->quote_ident( $schema ); |
| 132 | + if ( $conn->tableExists( $ctest, $schema ) ) { |
| 133 | + $conn->doQuery( "DROP TABLE $safeschema.$ctest" ); |
| 134 | + } |
| 135 | + $res = $this->doQuery( "CREATE TABLE $safeschema.$ctest(a int)" ); |
| 136 | + if ( !$res ) { |
| 137 | + $status->fatal( 'config-install-pg-schema-failed', |
| 138 | + $this->getVar( 'wgDBuser'), $schema ); |
| 139 | + } |
| 140 | + $conn->doQuery( "DROP TABLE $safeschema.$ctest" ); |
| 141 | + |
| 142 | + return $status; |
112 | 143 | } |
113 | 144 | |
| 145 | + protected function commitChanges() { |
| 146 | + $this->db->query( 'COMMIT' ); |
| 147 | + } |
| 148 | + |
114 | 149 | function getLocalSettings() { |
115 | 150 | $port = $this->getVar( 'wgDBport' ); |
116 | 151 | $schema = $this->getVar( 'wgDBmwschema' ); |