Actually check sourceFile for failure, showing the error message in the install.
authorPlatonides <platonides@users.mediawiki.org>
Thu, 29 Apr 2010 21:49:58 +0000 (21:49 +0000)
committerPlatonides <platonides@users.mediawiki.org>
Thu, 29 Apr 2010 21:49:58 +0000 (21:49 +0000)
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
includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseOracle.php
includes/db/DatabasePostgres.php
includes/db/DatabaseSqlite.php

index 45d6d6e..3eddb18 100644 (file)
@@ -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 "<li>Invalid database superuser, please supply a valid superuser account.</li>";
                                                        echo "<li>ERR: ".print_r(oci_error(), true)."</li>";
@@ -1181,7 +1182,8 @@ if( $conf->posted && ( 0 == count( $errs ) ) ) {
                                                        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>";
                                                }
                                                print "</li>\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 "<li>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.</li>\n<li>Populating interwiki table... \n";
+                                       $res = $wgDatabase->sourceFile( "../maintenance/interwiki.sql" );
+                               }
+                               if ($res === true) {
+                                       print " done.</li>\n";
+                               } else {
+                                       print " <b>FAILED</b></li>\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.</li>\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( "<li>" . htmlspecialchars( "Granting user permissions to $wgDBuser on $wgDBname..." ) );
-                                       $wgDatabase->sourceFile( "../maintenance/users.sql" );
-                                       echo( "success.</li>\n" );
+                                       $res = $wgDatabase->sourceFile( "../maintenance/users.sql" );
+                                       if ( $res === true ) {
+                                               echo( " success.</li>\n" );
+                                       } else {
+                                               echo( " <b>FAILED</b>.</li>\n" );
+                                               dieout( $res );
+                                       }
                                }
                        }
 
index 5964774..bed6724 100644 (file)
@@ -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;
        }
index c9f4c19..e53c028 100644 (file)
@@ -746,6 +746,11 @@ EOF;
                        $this->begin();
                        
                        $res = $this->sourceFile( "../maintenance/ibm_db2/tables.sql" );
+                       if ($res !== true) {
+                               print " <b>FAILED</b>: " . htmlspecialchars( $res ) . "</li>";
+                       } else {
+                               print " done</li>";
+                       }
                        $res = null;
                        
                        // TODO: populate interwiki links
index fee5f40..02c90a9 100644 (file)
@@ -978,14 +978,19 @@ class DatabaseOracle extends DatabaseBase {
        function setup_database() {
                global $wgVersion, $wgDBmwschema, $wgDBts2schema, $wgDBport, $wgDBuser;
 
-               echo "<li>Creating DB objects</li>\n";
                $res = $this->sourceFile( "../maintenance/ora/tables.sql" );
+               if ($res === true) {
+                       print " done.</li>\n";
+               } else {
+                       print " <b>FAILED</b></li>\n";
+                       dieout( htmlspecialchars( $res ) );
+               }
 
                // Avoid the non-standard "REPLACE INTO" syntax
-               echo "<li>Populating table interwiki</li>\n";
+               echo "<li>Populating interwiki table</li>\n";
                $f = fopen( "../maintenance/interwiki.sql", 'r' );
                if ( $f == false ) {
-                       dieout( "<li>Could not find the interwiki.sql file</li>" );
+                       dieout( "Could not find the interwiki.sql file" );
                }
 
                // do it like the postgres :D
index 0249aad..cf62554 100644 (file)
@@ -1330,11 +1330,17 @@ SQL;
                if (!$res) {
                        print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) . 
                                "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
-                       dieout("</ul>");
+                       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 ) );
+               }
 
                ## Update version information
                $mwv = $this->addQuotes($wgVersion);
@@ -1346,10 +1352,12 @@ SQL;
                $dbn = $this->addQuotes($this->mDBname);
                $ctype = $this->addQuotes( pg_fetch_result($this->doQuery("SHOW lc_ctype"),0,0) );
 
+               echo "<li>Populating interwiki table... ";
                ## Avoid the non-standard "REPLACE INTO" syntax
                $f = fopen( "../maintenance/interwiki.sql", 'r' );
                if ($f == false ) {
-                       dieout( "<li>Could not find the interwiki.sql file");
+                       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 ";
@@ -1361,7 +1369,7 @@ SQL;
                        }
                        $this->query("$SQL $matches[1],$matches[2])");
                }
-               print " (table interwiki successfully populated)...\n";
+               print " successfully populated.</li>\n";
 
                $this->doQuery("COMMIT");
        }
index 1ce725c..c149cf0 100644 (file)
@@ -487,13 +487,17 @@ class DatabaseSqlite extends DatabaseBase {
                # Process common MySQL/SQLite table definitions
                $err = $this->sourceFile( "$IP/maintenance/tables.sql" );
                if ( $err !== true ) {
-                       $this->reportQueryError( $err, 0, $sql, __FUNCTION__ );
-                       exit( 1 );
+                       echo " <b>FAILED</b></li>";
+                       dieout( htmlspecialchars( $err ) );
                }
+               echo " done.</li>";
 
                # Use DatabasePostgres's code to populate interwiki from MySQL template
                $f = fopen( "$IP/maintenance/interwiki.sql", 'r' );
-               if ( $f == false ) dieout( "<li>Could not find the interwiki.sql file" );
+               if ( $f == false ) {
+                       dieout( "Could not find the interwiki.sql file." );
+               }
+               
                $sql = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
                while ( !feof( $f ) ) {
                        $line = fgets( $f, 1024 );