From fd7eab173160dc7b71c47d1451b431ce49f525c5 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Wed, 26 Apr 2006 20:42:15 +0000 Subject: [PATCH] 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 --- RELEASE-NOTES | 2 ++ maintenance/update.php | 33 ++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9657b0320e..9699b278fd 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/maintenance/update.php b/maintenance/update.php index d8c44bda9e..8643aa7927 100644 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -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"; -- 2.20.1