r76453 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76452‎ | r76453 | r76454 >
Date:16:06, 10 November 2010
Author:demon
Status:deferred (Comments)
Tags:
Comment:
Postgres updater stuff, needs review
* Move setup_database() from DatabasePostgres to PostgresInstaller
** Add install step after interwiki for the COMMIT
** Put the table creation test (should we abstract this?) in setupDatabase()
** The leftover stuff in initial_setup() also belongs in setupDatabase(), I think?
Modified paths:
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -1275,57 +1275,6 @@
12761276 return $sql;
12771277 }
12781278
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 -
13301279 function encodeBlob( $b ) {
13311280 return new Blob( pg_escape_bytea( $this->mConn, $b ) );
13321281 }
Index: trunk/phase3/includes/installer/Installer.i18n.php
@@ -461,6 +461,7 @@
462462 'config-install-database' => 'Setting up database',
463463 'config-install-pg-schema-failed' => 'Tables creation failed.
464464 Make sure that the user "$1" can write to the schema "$2".',
 465+ 'config-install-pg-commit' => 'Committing changes',
465466 'config-install-user' => 'Creating database user',
466467 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
467468 'config-install-tables' => 'Creating tables',
Index: trunk/phase3/includes/installer/DatabaseInstaller.php
@@ -97,9 +97,10 @@
9898 /**
9999 * Connect to the database using the administrative user/password currently
100100 * defined in the session. On success, return the connection, on failure,
101 - * return a Status object.
102101 *
103102 * This may be called multiple times, so the result should be cached.
 103+ *
 104+ * @return Status
104105 */
105106 public abstract function getConnection();
106107
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -107,9 +107,44 @@
108108 return $status;
109109 }
110110
 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+
111120 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;
112143 }
113144
 145+ protected function commitChanges() {
 146+ $this->db->query( 'COMMIT' );
 147+ }
 148+
114149 function getLocalSettings() {
115150 $port = $this->getVar( 'wgDBport' );
116151 $schema = $this->getVar( 'wgDBmwschema' );

Comments

#Comment by MarkAHershberger (talk | contribs)   06:59, 25 November 2010

I still have to

create schema mediawiki;

as the wiki user before it'll let me install. Fails silently in the web install, but I did get some diagnosable errors in the cli install.

+	protected function commitChanges()

and I get this:

PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method PostgresInstaller::commitChanges() in ...

And commitChanges() should return a status object.

#Comment by 😂 (talk | contribs)   15:40, 13 December 2010

Issues with commitChanges() were resolved in r77533.

#Comment by 😂 (talk | contribs)   13:02, 12 January 2011

The create schema part has been handled as of r79989.

Currently fails at table creation, but that's not the fault of this rev. Status -> new

Status & tagging log