r65672 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65671‎ | r65672 | r65673 >
Date:21:49, 29 April 2010
Author:platonides
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/config/Installer.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -978,14 +978,19 @@
979979 function setup_database() {
980980 global $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgDBport, $wgDBuser;
981981
982 - echo "<li>Creating DB objects</li>\n";
983982 $res = $this->sourceFile( "../maintenance/ora/tables.sql" );
 983+ if ($res === true) {
 984+ print " done.</li>\n";
 985+ } else {
 986+ print " <b>FAILED</b></li>\n";
 987+ dieout( htmlspecialchars( $res ) );
 988+ }
984989
985990 // Avoid the non-standard "REPLACE INTO" syntax
986 - echo "<li>Populating table interwiki</li>\n";
 991+ echo "<li>Populating interwiki table</li>\n";
987992 $f = fopen( "../maintenance/interwiki.sql", 'r' );
988993 if ( $f == false ) {
989 - dieout( "<li>Could not find the interwiki.sql file</li>" );
 994+ dieout( "Could not find the interwiki.sql file" );
990995 }
991996
992997 // do it like the postgres :D
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -1330,11 +1330,17 @@
13311331 if (!$res) {
13321332 print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) .
13331333 "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
1334 - dieout("</ul>");
 1334+ dieout(""); # Will close the main list <ul> and finish the page.
13351335 }
13361336 $this->doQuery("DROP TABLE $safeschema.$ctest");
13371337
13381338 $res = $this->sourceFile( "../maintenance/postgres/tables.sql" );
 1339+ if ($res === true) {
 1340+ print " done.</li>\n";
 1341+ } else {
 1342+ print " <b>FAILED</b></li>\n";
 1343+ dieout( htmlspecialchars( $res ) );
 1344+ }
13391345
13401346 ## Update version information
13411347 $mwv = $this->addQuotes($wgVersion);
@@ -1346,10 +1352,12 @@
13471353 $dbn = $this->addQuotes($this->mDBname);
13481354 $ctype = $this->addQuotes( pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0) );
13491355
 1356+ echo "<li>Populating interwiki table... ";
13501357 ## Avoid the non-standard "REPLACE INTO" syntax
13511358 $f = fopen( "../maintenance/interwiki.sql", 'r' );
13521359 if ($f == false ) {
1353 - dieout( "<li>Could not find the interwiki.sql file");
 1360+ print "<b>FAILED</b></li>";
 1361+ dieout( "Could not find the interwiki.sql file" );
13541362 }
13551363 ## We simply assume it is already empty as we have just created it
13561364 $SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
@@ -1361,7 +1369,7 @@
13621370 }
13631371 $this->query("$SQL $matches[1],$matches[2])");
13641372 }
1365 - print " (table interwiki successfully populated)...\n";
 1373+ print " successfully populated.</li>\n";
13661374
13671375 $this->doQuery("COMMIT");
13681376 }
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -746,6 +746,11 @@
747747 $this->begin();
748748
749749 $res = $this->sourceFile( "../maintenance/ibm_db2/tables.sql" );
 750+ if ($res !== true) {
 751+ print " <b>FAILED</b>: " . htmlspecialchars( $res ) . "</li>";
 752+ } else {
 753+ print " done</li>";
 754+ }
750755 $res = null;
751756
752757 // TODO: populate interwiki links
Index: trunk/phase3/includes/db/Database.php
@@ -2193,9 +2193,23 @@
21942194 function sourceFile( $filename, $lineCallback = false, $resultCallback = false ) {
21952195 $fp = fopen( $filename, 'r' );
21962196 if ( false === $fp ) {
2197 - throw new MWException( "Could not open \"{$filename}\".\n" );
 2197+ if (!defined("MEDIAWIKI_INSTALL"))
 2198+ throw new MWException( "Could not open \"{$filename}\".\n" );
 2199+ else
 2200+ return "Could not open \"{$filename}\".\n";
21982201 }
2199 - $error = $this->sourceStream( $fp, $lineCallback, $resultCallback );
 2202+ try {
 2203+ $error = $this->sourceStream( $fp, $lineCallback, $resultCallback );
 2204+ }
 2205+ catch( MWException $e ) {
 2206+ if ( defined("MEDIAWIKI_INSTALL") ) {
 2207+ $error = $e->getMessage();
 2208+ } else {
 2209+ fclose( $fp );
 2210+ throw $e;
 2211+ }
 2212+ }
 2213+
22002214 fclose( $fp );
22012215 return $error;
22022216 }
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -487,13 +487,17 @@
488488 # Process common MySQL/SQLite table definitions
489489 $err = $this->sourceFile( "$IP/maintenance/tables.sql" );
490490 if ( $err !== true ) {
491 - $this->reportQueryError( $err, 0, $sql, __FUNCTION__ );
492 - exit( 1 );
 491+ echo " <b>FAILED</b></li>";
 492+ dieout( htmlspecialchars( $err ) );
493493 }
 494+ echo " done.</li>";
494495
495496 # Use DatabasePostgres's code to populate interwiki from MySQL template
496497 $f = fopen( "$IP/maintenance/interwiki.sql", 'r' );
497 - if ( $f == false ) dieout( "<li>Could not find the interwiki.sql file" );
 498+ if ( $f == false ) {
 499+ dieout( "Could not find the interwiki.sql file." );
 500+ }
 501+
498502 $sql = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
499503 while ( !feof( $f ) ) {
500504 $line = fgets( $f, 1024 );
Index: trunk/phase3/config/Installer.php
@@ -1004,7 +1004,8 @@
10051005 if ($wgDatabase->isOpen()) {
10061006 $wgDBOracleDefTS = $conf->DBdefTS_ora;
10071007 $wgDBOracleTempTS = $conf->DBtempTS_ora;
1008 - $wgDatabase->sourceFile( "../maintenance/ora/user.sql" );
 1008+ $res = $wgDatabase->sourceFile( "../maintenance/ora/user.sql" );
 1009+ if ($res !== true) dieout($res);
10091010 } else {
10101011 echo "<li>Invalid database superuser, please supply a valid superuser account.</li>";
10111012 echo "<li>ERR: ".print_r(oci_error(), true)."</li>";
@@ -1181,7 +1182,8 @@
11821183 print " <b class='error'>If the next step fails, see <a href='http://dev.mysql.com/doc/mysql/en/old-client.html'>http://dev.mysql.com/doc/mysql/en/old-client.html</a> for help.</b>";
11831184 }
11841185 print "</li>\n";
1185 - $wgDatabase->sourceFile( "../maintenance/users.sql" );
 1186+ $res = $wgDatabase->sourceFile( "../maintenance/users.sql" );
 1187+ if ($res !== true) dieout($res);
11861188 }
11871189 }
11881190 }
@@ -1216,8 +1218,17 @@
12171219 # FIXME: Check for errors
12181220 print "<li>Creating tables...";
12191221 if ($conf->DBtype == 'mysql') {
1220 - $wgDatabase->sourceFile( "../maintenance/tables.sql" );
1221 - $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
 1222+ $res = $wgDatabase->sourceFile( "../maintenance/tables.sql" );
 1223+ if ($res === true) {
 1224+ print " done.</li>\n<li>Populating interwiki table... \n";
 1225+ $res = $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
 1226+ }
 1227+ if ($res === true) {
 1228+ print " done.</li>\n";
 1229+ } else {
 1230+ print " <b>FAILED</b></li>\n";
 1231+ dieout( htmlspecialchars( $res ) );
 1232+ }
12221233 } elseif (is_callable(array($wgDatabase, 'setup_database'))) {
12231234 $wgDatabase->setup_database();
12241235 }
@@ -1226,9 +1237,7 @@
12271238 continue;
12281239 }
12291240
1230 - print " done.</li>\n";
12311241
1232 -
12331242 if ( $conf->DBtype == 'ibm_db2' ) {
12341243 // Now that table creation is done, make sure everything is committed
12351244 // Do this before doing inserts through API
@@ -1268,8 +1277,13 @@
12691278 } else {
12701279 # Yes, so run the grants
12711280 echo( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
1272 - $wgDatabase->sourceFile( "../maintenance/users.sql" );
1273 - echo( "success.</li>\n" );
 1281+ $res = $wgDatabase->sourceFile( "../maintenance/users.sql" );
 1282+ if ( $res === true ) {
 1283+ echo( " success.</li>\n" );
 1284+ } else {
 1285+ echo( " <b>FAILED</b>.</li>\n" );
 1286+ dieout( $res );
 1287+ }
12741288 }
12751289 }
12761290

Follow-up revisions

RevisionCommit summaryAuthorDate
r65673MFT r65672platonides22:00, 29 April 2010
r65674Follow up r65672. FIXED.platonides22:02, 29 April 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r36211* (bug 14497) Throw visible errors in installer scripts when SQL files fail d...brion00:15, 12 June 2008

Status & tagging log