'DeleteDefaultMessages'
);
- protected function __construct( $db, $shared ) {
+ /**
+ * Constructor
+ *
+ * @param $db DatabaseBase object to perform updates on
+ * @param $shared bool Whether to perform updates on shared tables
+ *
+ * @TODO @FIXME Make $wgDatabase go away.
+ */
+ protected function __construct( DatabaseBase &$db, $shared ) {
+ global $wgDatabase;
+ $wgDatabase = $db;
$this->db = $db;
$this->shared = $shared;
+ $this->initOldGlobals();
+ wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
+ }
+
+ /**
+ * Initialize all of the old globals. One day this should all become
+ * something much nicer
+ */
+ private function initOldGlobals() {
+ global $wgUpdates, $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
+ $wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
+
+ // Deprecated. Do not use, ever.
+ $wgUpdates = array();
+
+ # For extensions only, should be populated via hooks
+ # $wgDBtype should be checked to specifiy the proper file
+ $wgExtNewTables = array(); // table, dir
+ $wgExtNewFields = array(); // table, column, dir
+ $wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
+ $wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
+ $wgExtNewIndexes = array(); // table, index, dir
+ $wgExtModifiedFields = array(); // table, index, dir
}
- public static function newForDB( $db, $shared ) {
+ public static function newForDB( &$db, $shared = false ) {
$type = $db->getType();
if( in_array( $type, Installer::getDBTypes() ) ) {
$class = ucfirst( $type ) . 'Updater';
return $this->postDatabaseUpdateMaintenance;
}
- public function doUpdates() {
+ /**
+ * Do all the updates
+ * @param $purge bool Whether to clear the objectcache table after updates
+ */
+ public function doUpdates( $purge = true ) {
global $IP, $wgVersion;
require_once( "$IP/maintenance/updaters.inc" );
$this->updates = array_merge( $this->getCoreUpdateList(),
flush();
}
$this->setAppliedUpdates( $wgVersion, $this->updates );
+
+ if( $purge ) {
+ $this->purgeCache();
+ }
}
protected function setAppliedUpdates( $version, $updates = array() ) {
wfOut( "...$table table does not contain $field field.\n" );
}
}
+
+ /**
+ * Purge the objectcache table
+ */
+ protected function purgeCache() {
+ # We can't guarantee that the user will be able to use TRUNCATE,
+ # but we know that DELETE is available to us
+ wfOut( "Purging caches..." );
+ $this->db->delete( 'objectcache', '*', __METHOD__ );
+ wfOut( "done.\n" );
+ }
}
* old and new code.
*/
public function doUpgrade() {
- global $wgDatabase, $wgDBuser, $wgDBpassword;
+ global $wgDBuser, $wgDBpassword;
# Some maintenance scripts like wfGetDB()
LBFactory::enableBackend();
- # For do_all_updates()
- $wgDatabase = $this->db;
# Normal user and password are selected after this step, so for now
# just copy these two
$wgDBuser = $this->getVar( '_InstallUser' );
ob_start( array( $this, 'outputHandler' ) );
try {
- do_all_updates( false, true );
+ $updater = DatabaseUpdater::newForDb( $this->db );
+ $updater->doUpdates();
} catch ( MWException $e ) {
echo "\nAn error occured:\n";
echo $e->getText();
}
public function doUpgrade() {
- global $wgDatabase;
LBFactory::enableBackend();
- $wgDatabase = wfGetDB( DB_MASTER );
+ $db = wfGetDB( DB_MASTER );
ob_start( array( $this, 'outputHandler' ) );
- do_all_updates( false, true );
+ $updater = DatabaseUpdater::newForDb( $this->db );
+ $updater->doUpdates();
ob_end_flush();
return true;
}
* @ingroup Maintenance
*/
-/** */
define( 'MW_CMDLINE_CALLBACK', 'wfSetupUpdateScript' );
$wgUseMasterForMaintenance = true;
-require_once( dirname( __FILE__ ) . '/commandLine.inc' );
-require( "updaters.inc" );
+require_once( 'Maintenance.php' );
-$wgTitle = Title::newFromText( "MediaWiki database updater" );
+class UpdateMediaWiki extends Maintenance {
-echo( "MediaWiki {$wgVersion} Updater\n\n" );
+ public function __construct() {
+ parent::__construct();
+ $this->mDescription = "MediaWiki database updater";
+ $this->addOption( 'skip-compat-checks', 'Skips compatibility checks, mostly for developers' );
+ $this->addOption( 'quick', 'Skip 5 second countdown before starting' );
+ $this->addOption( 'doshared', 'Also update shared tables' );
+ $this->addOption( 'nopurge', 'Do not purge the objectcache table after updates' );
+ }
-if ( !isset( $options['skip-compat-checks'] ) ) {
- install_version_checks();
-} else {
- print "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n";
- wfCountdown( 5 );
-}
+ public function getDbType() {
+ return self::DB_ADMIN;
+ }
-# Attempt to connect to the database as a privileged user
-# This will vomit up an error if there are permissions problems
-$wgDatabase = wfGetDB( DB_MASTER );
+ public function execute() {
+ global $wgVersion, $wgTitle;
-print "Going to run database updates for " . wfWikiID() . "\n";
-print "Depending on the size of your database this may take a while!\n";
+ $wgTitle = Title::newFromText( "MediaWiki database updater" );
-if ( !isset( $options['quick'] ) ) {
- print "Abort with control-c in the next five seconds (skip this countdown with --quick) ... ";
- wfCountDown( 5 );
-}
+ $this->output( "MediaWiki {$wgVersion} Updater\n\n" );
+
+ if ( !isset( $options['skip-compat-checks'] ) ) {
+ install_version_checks();
+ } else {
+ $this->output( "Skipping compatibility checks, proceed at your own risk (Ctrl+C to abort)\n" );
+ wfCountdown( 5 );
+ }
+
+ # Attempt to connect to the database as a privileged user
+ # This will vomit up an error if there are permissions problems
+ $db = wfGetDB( DB_MASTER );
+
+ $this->output( "Going to run database updates for " . wfWikiID() . "\n" );
+ $this->output( "Depending on the size of your database this may take a while!\n" );
+
+ if ( !$this->hasOption( 'quick' ) ) {
+ $this->output( "Abort with control-c in the next five seconds (skip this countdown with --quick) ... " );
+ wfCountDown( 5 );
+ }
-$shared = isset( $options['doshared'] );
-$purge = !isset( $options['nopurge'] );
+ $shared = $this->hasOption( 'doshared' );
+ $purge = !$this->hasOption( 'nopurge' );
-do_all_updates( $shared, $purge );
+ $updater = DatabaseUpdater::newForDb( $db, $shared );
+ $updater->doUpdates( $purge );
-print "Done.\n";
+ if ( !defined( 'MW_NO_SETUP' ) ) {
+ define( 'MW_NO_SETUP', true );
+ }
+
+ foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
+ call_user_func_array( array( new $maint, 'execute' ), array() );
+ }
+
+ if ( $db->getType() === 'postgres' ) {
+ return;
+ }
+
+ do_stats_init();
+
+ $this->output( "Done.\n" );
+ }
+}
function wfSetupUpdateScript() {
global $wgLocalisationCacheConf;
# Don't try to access the database
- # This needs to be disabled early since extensions will try to use the l10n
+ # This needs to be disabled early since extensions will try to use the l10n
# cache from $wgExtensionSetupFunctions (bug 20471)
$wgLocalisationCacheConf = array(
'class' => 'LocalisationCache',
'manualRecache' => false,
);
}
+
+$maintClass = 'UpdateMediaWiki';
+require_once( DO_MAINTENANCE );
exit( 1 );
}
-require_once 'userDupes.inc';
-# Extension updates
-require_once( "$IP/includes/Hooks.php" );
-
-/**
- * @deprecated. Do not use, ever.
- */
-$wgUpdates = array();
-
-
-# For extensions only, should be populated via hooks
-# $wgDBtype should be checked to specifiy the proper file
-$wgExtNewTables = array(); // table, dir
-$wgExtNewFields = array(); // table, column, dir
-$wgExtPGNewFields = array(); // table, column, column attributes; for PostgreSQL
-$wgExtPGAlteredFields = array(); // table, column, new type, conversion method; for PostgreSQL
-$wgExtNewIndexes = array(); // table, index, dir
-$wgExtModifiedFields = array(); // table, index, dir
-
# Helper function: check if the given key is present in the updatelog table.
# Obviously, only use this for updates that occur after the updatelog table was
# created!
}
}
-function do_all_updates( $shared = false, $purge = true ) {
- global $wgDatabase, $wgDBtype;
-
- $updater = DatabaseUpdater::newForDb( $wgDatabase, $shared );
-
- wfRunHooks( 'LoadExtensionSchemaUpdates', array( &$updater ) );
-
- $updater->doUpdates();
-
- if ( !defined( 'MW_NO_SETUP' ) ) {
- define( 'MW_NO_SETUP', true );
- }
-
- foreach( $updater->getPostDatabaseUpdateMaintenance() as $maint ) {
- call_user_func_array( array( new $maint, 'execute' ), array() );
- }
-
- if ( $wgDBtype === 'postgres' ) {
- return;
- }
-
- do_stats_init();
-
- if ( $purge ) {
- purge_cache();
- }
-}
-
function archive( $name ) {
return DatabaseBase::patchPath( $name );
}
function do_user_unique_update() {
global $wgDatabase;
+ require_once( "userDupes.inc" );
$duper = new UserDupes( $wgDatabase );
if ( $duper->hasUniqueIndex() ) {
wfOut( "...already have unique user_name index.\n" );
wfOut( "...ss_active_users user count set...\n" );
}
-function purge_cache() {
- global $wgDatabase;
- # We can't guarantee that the user will be able to use TRUNCATE,
- # but we know that DELETE is available to us
- wfOut( "Purging caches..." );
- $wgDatabase->delete( 'objectcache', '*', __METHOD__ );
- wfOut( "done.\n" );
-}
-
/**
* Adding page_restrictions table, obsoleting page.page_restrictions.
* Migrating old restrictions to new table