return $sql;
}
- function setup_database() {
- global $wgDBmwschema, $wgDBuser;
-
- // Make sure that we can write to the correct schema
- // If not, Postgres will happily and silently go to the next search_path item
- $ctest = 'mediawiki_test_table';
- $safeschema = $this->quote_ident( $wgDBmwschema );
- if ( $this->tableExists( $ctest, $wgDBmwschema ) ) {
- $this->doQuery( "DROP TABLE $safeschema.$ctest" );
- }
- $SQL = "CREATE TABLE $safeschema.$ctest(a int)";
- $olde = error_reporting( 0 );
- $res = $this->doQuery( $SQL );
- error_reporting( $olde );
- if ( !$res ) {
- print '<b>FAILED</b>. Make sure that the user "' . htmlspecialchars( $wgDBuser ) .
- '" can write to the schema "' . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
- dieout( '' ); # Will close the main list <ul> and finish the page.
- }
- $this->doQuery( "DROP TABLE $safeschema.$ctest" );
-
- $res = $this->sourceFile( "../maintenance/postgres/tables.sql" );
- if ( $res === true ) {
- print " done.</li>\n";
- } else {
- print " <b>FAILED</b></li>\n";
- dieout( htmlspecialchars( $res ) );
- }
-
- echo '<li>Populating interwiki table... ';
- # Avoid the non-standard "REPLACE INTO" syntax
- $f = fopen( "../maintenance/interwiki.sql", 'r' );
- if ( !$f ) {
- print '<b>FAILED</b></li>';
- dieout( 'Could not find the interwiki.sql file' );
- }
- # We simply assume it is already empty as we have just created it
- $SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
- while ( !feof( $f ) ) {
- $line = fgets( $f, 1024 );
- $matches = array();
- if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) {
- continue;
- }
- $this->query( "$SQL $matches[1],$matches[2])" );
- }
- print " successfully populated.</li>\n";
-
- $this->doQuery( 'COMMIT' );
- }
-
function encodeBlob( $b ) {
return new Blob( pg_escape_bytea( $this->mConn, $b ) );
}
'config-install-database' => 'Setting up database',
'config-install-pg-schema-failed' => 'Tables creation failed.
Make sure that the user "$1" can write to the schema "$2".',
+ 'config-install-pg-commit' => 'Committing changes',
'config-install-user' => 'Creating database user',
'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
'config-install-tables' => 'Creating tables',
return $status;
}
+ public function preInstall() {
+ # Add our user callback to installSteps, right before the tables are created.
+ $callback = array(
+ 'name' => 'pg-commit',
+ 'callback' => array( $this, 'commitChanges' ),
+ );
+ $this->parent->addInstallStepFollowing( 'interwiki', $callback );
+ }
+
function setupDatabase() {
+ $status = $this->getConnection();
+ if ( !$status->isOK() ) {
+ return $status;
+ }
+ $conn = $status->value;
+
+ // Make sure that we can write to the correct schema
+ // If not, Postgres will happily and silently go to the next search_path item
+ $schema = $this->getVar( 'wgDBmwschema' );
+ $ctest = 'mediawiki_test_table';
+ $safeschema = $conn->quote_ident( $schema );
+ if ( $conn->tableExists( $ctest, $schema ) ) {
+ $conn->doQuery( "DROP TABLE $safeschema.$ctest" );
+ }
+ $res = $this->doQuery( "CREATE TABLE $safeschema.$ctest(a int)" );
+ if ( !$res ) {
+ $status->fatal( 'config-install-pg-schema-failed',
+ $this->getVar( 'wgDBuser'), $schema );
+ }
+ $conn->doQuery( "DROP TABLE $safeschema.$ctest" );
+
+ return $status;
+ }
+
+ protected function commitChanges() {
+ $this->db->query( 'COMMIT' );
}
function getLocalSettings() {