From 62a615c6c0438af8f8a5e367a2ef6954d4f11169 Mon Sep 17 00:00:00 2001 From: Platonides Date: Thu, 29 Apr 2010 21:49:58 +0000 Subject: [PATCH] Actually check sourceFile for failure, showing the error message in the install. See report on http://permalink.gmane.org/gmane.org.wikimedia.mediawiki/33902 Fixed several tag nesting problems from setup_database(). Make sourceFile() always use text errors in the installer. It can't handle exceptions properly (introduced in r36211). But they are appropiate for update.php thus the ugly branches. The installer now always handles sourceFile() errors. --- config/Installer.php | 30 ++++++++++++++++++++++-------- includes/db/Database.php | 18 ++++++++++++++++-- includes/db/DatabaseIbm_db2.php | 5 +++++ includes/db/DatabaseOracle.php | 11 ++++++++--- includes/db/DatabasePostgres.php | 14 +++++++++++--- includes/db/DatabaseSqlite.php | 10 +++++++--- 6 files changed, 69 insertions(+), 19 deletions(-) diff --git a/config/Installer.php b/config/Installer.php index 45d6d6e4d8..3eddb18ca9 100644 --- a/config/Installer.php +++ b/config/Installer.php @@ -1004,7 +1004,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { if ($wgDatabase->isOpen()) { $wgDBOracleDefTS = $conf->DBdefTS_ora; $wgDBOracleTempTS = $conf->DBtempTS_ora; - $wgDatabase->sourceFile( "../maintenance/ora/user.sql" ); + $res = $wgDatabase->sourceFile( "../maintenance/ora/user.sql" ); + if ($res !== true) dieout($res); } else { echo "
  • Invalid database superuser, please supply a valid superuser account.
  • "; echo "
  • ERR: ".print_r(oci_error(), true)."
  • "; @@ -1181,7 +1182,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { print " If the next step fails, see http://dev.mysql.com/doc/mysql/en/old-client.html for help."; } print "\n"; - $wgDatabase->sourceFile( "../maintenance/users.sql" ); + $res = $wgDatabase->sourceFile( "../maintenance/users.sql" ); + if ($res !== true) dieout($res); } } } @@ -1216,8 +1218,17 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { # FIXME: Check for errors print "
  • Creating tables..."; if ($conf->DBtype == 'mysql') { - $wgDatabase->sourceFile( "../maintenance/tables.sql" ); - $wgDatabase->sourceFile( "../maintenance/interwiki.sql" ); + $res = $wgDatabase->sourceFile( "../maintenance/tables.sql" ); + if ($res === true) { + print " done.
  • \n
  • Populating interwiki table... \n"; + $res = $wgDatabase->sourceFile( "../maintenance/interwiki.sql" ); + } + if ($res === true) { + print " done.
  • \n"; + } else { + print " FAILED\n"; + dieout( htmlspecialchars( $res ) ); + } } elseif (is_callable(array($wgDatabase, 'setup_database'))) { $wgDatabase->setup_database(); } @@ -1226,8 +1237,6 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { continue; } - print " done.\n"; - if ( $conf->DBtype == 'ibm_db2' ) { // Now that table creation is done, make sure everything is committed @@ -1268,8 +1277,13 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) { } else { # Yes, so run the grants echo( "
  • " . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) ); - $wgDatabase->sourceFile( "../maintenance/users.sql" ); - echo( "success.
  • \n" ); + $res = $wgDatabase->sourceFile( "../maintenance/users.sql" ); + if ( $res === true ) { + echo( " success.\n" ); + } else { + echo( " FAILED.\n" ); + dieout( $res ); + } } } diff --git a/includes/db/Database.php b/includes/db/Database.php index 596477473d..bed6724561 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2193,9 +2193,23 @@ abstract class DatabaseBase { function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) { $fp = fopen( $filename, 'r' ); if ( false === $fp ) { - throw new MWException( "Could not open \"{$filename}\".\n" ); + if (!defined("MEDIAWIKI_INSTALL")) + throw new MWException( "Could not open \"{$filename}\".\n" ); + else + return "Could not open \"{$filename}\".\n"; + } + try { + $error = $this->sourceStream( $fp, $lineCallback, $resultCallback ); + } + catch( MWException $e ) { + if ( defined("MEDIAWIKI_INSTALL") ) { + $error = $e->getMessage(); + } else { + fclose( $fp ); + throw $e; + } } - $error = $this->sourceStream( $fp, $lineCallback, $resultCallback ); + fclose( $fp ); return $error; } diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index c9f4c19fe7..e53c0283e3 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -746,6 +746,11 @@ EOF; $this->begin(); $res = $this->sourceFile( "../maintenance/ibm_db2/tables.sql" ); + if ($res !== true) { + print " FAILED: " . htmlspecialchars( $res ) . ""; + } else { + print " done"; + } $res = null; // TODO: populate interwiki links diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index fee5f404ab..02c90a9d76 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -978,14 +978,19 @@ class DatabaseOracle extends DatabaseBase { function setup_database() { global $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgDBport, $wgDBuser; - echo "
  • Creating DB objects
  • \n"; $res = $this->sourceFile( "../maintenance/ora/tables.sql" ); + if ($res === true) { + print " done.\n"; + } else { + print " FAILED\n"; + dieout( htmlspecialchars( $res ) ); + } // Avoid the non-standard "REPLACE INTO" syntax - echo "
  • Populating table interwiki
  • \n"; + echo "
  • Populating interwiki table
  • \n"; $f = fopen( "../maintenance/interwiki.sql", 'r' ); if ( $f == false ) { - dieout( "
  • Could not find the interwiki.sql file
  • " ); + dieout( "Could not find the interwiki.sql file" ); } // do it like the postgres :D diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 0249aad3bc..cf62554ad5 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1330,11 +1330,17 @@ SQL; if (!$res) { print "FAILED. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) . "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"\n"; - dieout(""); + dieout(""); # Will close the main list