Improvements to update scripts; print out the version, check for superuser credential...
authorRob Church <robchurch@users.mediawiki.org>
Wed, 26 Apr 2006 20:42:15 +0000 (20:42 +0000)
committerRob Church <robchurch@users.mediawiki.org>
Wed, 26 Apr 2006 20:42:15 +0000 (20:42 +0000)
RELEASE-NOTES
maintenance/update.php

index 9657b03..9699b27 100644 (file)
@@ -127,6 +127,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Pass login link to "whitelistedittext" containing 'returnto' parameter
 * (bug 5728): mVersion missing from User::__sleep() leading to constant cache miss
 * Updated maintenance/transstat.php so it can show duplicate messages
+* Improvements to update scripts; print out the version, check for superuser credentials
+  before attempting a connection, and produce a friendlier error if the connection fails
 
 == Compatibility ==
 
index d8c44bd..8643aa7 100644 (file)
@@ -14,13 +14,36 @@ $options = array( 'quick' );
 require_once( "commandLine.inc" );
 require_once( "updaters.inc" );
 $wgTitle = Title::newFromText( "MediaWiki database updater" );
-$dbclass = 'Database'.ucfirst($wgDBtype);
+$dbclass = 'Database' . ucfirst( $wgDBtype ) ;
 require_once("$dbclass.php");
 $dbc = new $dbclass;
-# TODO : check for AdminSettings file existence ? See #5725
-print "Attempting connection to the database. If it fails, maybe you are\n";
-print "missing a proper AdminSettings.php file in $IP\n\n";
-$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+
+echo( "MediaWiki {$wgVersion} Updater\n\n" );
+
+# Do a pre-emptive check to ensure we've got credentials supplied
+# We can't, at this stage, check them, but we can detect their absence,
+# which seems to cause most of the problems people whinge about
+if( !isset( $wgDBadminuser ) || !isset( $wgDBadminpassword ) ) {
+       echo( "No superuser credentials could be found. Please provide the details\n" );
+       echo( "of a user with appropriate permissions to update the database. See\n" );
+       echo( "AdminSettings.sample for more details.\n\n" );
+       exit();
+}
+
+# Attempt to connect to the database as a privileged user
+# This will vomit up an error if there are permissions problems
+$wgDatabase = $dbc->newFromParams( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname, 1 );
+
+if( !$wgDatabase->isOpen() ) {
+       # Appears to have failed
+       echo( "A connection to the database could not be established. Check the\n" );
+       # Let's be a bit clever and guess at what's wrong
+       if( isset( $wgDBadminuser ) && isset( $wgDBadminpassword ) ) {
+               # Tell the user the value(s) are wrong
+               echo( 'values of $wgDBadminuser and $wgDBadminpassword.' . "\n" );
+       }
+       exit();
+}
 
 print "Going to run database updates for $wgDBname\n";
 print "Depending on the size of your database this may take a while!\n";