* @file
* @ingroup Deployment
*/
-
+
+require_once( dirname(__FILE__) . '/../../maintenance/Maintenance.php' );
+
/*
* Class for handling database updates. Roughly based off of updaters.inc, with
* a few improvements :)
*
* @param $db DatabaseBase object to perform updates on
* @param $shared bool Whether to perform updates on shared tables
+ * @param $maintenance Maintenance Maintenance object which created us
*
- * @TODO @FIXME Make $wgDatabase go away.
+ * @todo FIXME: Make $wgDatabase go away.
*/
- protected function __construct( DatabaseBase &$db, $shared ) {
+ protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
global $wgDatabase;
$wgDatabase = $db;
$this->db = $db;
$this->shared = $shared;
+ if ( $maintenance ) {
+ $this->maintenance = $maintenance;
+ } else {
+ $this->maintenance = new FakeMaintenance;
+ }
$this->initOldGlobals();
wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
}
$wgExtModifiedFields = array(); // table, index, dir
}
- public static function newForDB( &$db, $shared = false ) {
+ public static function newForDB( &$db, $shared = false, $maintenance = null ) {
$type = $db->getType();
if( in_array( $type, Installer::getDBTypes() ) ) {
$class = ucfirst( $type ) . 'Updater';
- return new $class( $db, $shared );
+ return new $class( $db, $shared, $maintenance );
} else {
throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
}
return $this->db;
}
+ /**
+ * Output some text. Right now this is a wrapper for wfOut, but hopefully
+ * that function can go away some day :)
+ *
+ * @param $str String: Text to output
+ */
+ protected function output( $str ) {
+ if ( $this->maintenance->isQuiet() ) {
+ return;
+ }
+ wfOut( $str );
+ }
+
/**
* Add a new update coming from an extension. This should be called by
* extensions while executing the LoadExtensionSchemaUpdates hook.
public function doUpdates( $purge = true ) {
global $wgVersion;
+ if ( !defined( 'MW_NO_SETUP' ) ) {
+ define( 'MW_NO_SETUP', true );
+ }
+
$this->runUpdates( $this->getCoreUpdateList(), false );
$this->runUpdates( $this->getOldGlobalUpdates(), false );
$this->runUpdates( $this->getExtensionUpdates(), true );
/**
* Before 1.17, we used to handle updates via stuff like
* $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
- * of this in 1.17 but we want to remain back-compatible for awhile. So
+ * of this in 1.17 but we want to remain back-compatible for a while. So
* load up these old global-based things into our update list.
*/
protected function getOldGlobalUpdates() {
if ( $isFullPath ) {
$this->db->sourceFile( $path );
} else {
- $this->db->sourceFile( DatabaseBase::patchPath( $path ) );
+ $this->db->sourceFile( $this->db->patchPath( $path ) );
}
}
*/
protected function addTable( $name, $patch, $fullpath = false ) {
if ( $this->db->tableExists( $name ) ) {
- wfOut( "...$name table already exists.\n" );
+ $this->output( "...$name table already exists.\n" );
} else {
- wfOut( "Creating $name table..." );
+ $this->output( "Creating $name table..." );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
}
}
*/
protected function addField( $table, $field, $patch, $fullpath = false ) {
if ( !$this->db->tableExists( $table ) ) {
- wfOut( "...$table table does not exist, skipping new field patch\n" );
+ $this->output( "...$table table does not exist, skipping new field patch\n" );
} elseif ( $this->db->fieldExists( $table, $field ) ) {
- wfOut( "...have $field field in $table table.\n" );
+ $this->output( "...have $field field in $table table.\n" );
} else {
- wfOut( "Adding $field field to table $table..." );
+ $this->output( "Adding $field field to table $table..." );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
}
}
*/
function addIndex( $table, $index, $patch, $fullpath = false ) {
if ( $this->db->indexExists( $table, $index ) ) {
- wfOut( "...$index key already set on $table table.\n" );
+ $this->output( "...$index key already set on $table table.\n" );
} else {
- wfOut( "Adding $index key to table $table... " );
+ $this->output( "Adding $index key to table $table... " );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
}
}
*/
function dropField( $table, $field, $patch, $fullpath = false ) {
if ( $this->db->fieldExists( $table, $field ) ) {
- wfOut( "Table $table contains $field field. Dropping... " );
+ $this->output( "Table $table contains $field field. Dropping... " );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
} else {
- wfOut( "...$table table does not contain $field field.\n" );
+ $this->output( "...$table table does not contain $field field.\n" );
}
}
*/
function dropIndex( $table, $index, $patch, $fullpath = false ) {
if ( $this->db->indexExists( $table, $index ) ) {
- wfOut( "Dropping $index from table $table... " );
+ $this->output( "Dropping $index from table $table... " );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
} else {
- wfOut( "...$index key doesn't exist.\n" );
+ $this->output( "...$index key doesn't exist.\n" );
}
}
*/
public function modifyField( $table, $field, $patch, $fullpath = false ) {
if ( !$this->db->tableExists( $table ) ) {
- wfOut( "...$table table does not exist, skipping modify field patch\n" );
+ $this->output( "...$table table does not exist, skipping modify field patch\n" );
} elseif ( !$this->db->fieldExists( $table, $field ) ) {
- wfOut( "...$field field does not exist in $table table, skipping modify field patch\n" );
+ $this->output( "...$field field does not exist in $table table, skipping modify field patch\n" );
} else {
- wfOut( "Modifying $field field of table $table..." );
+ $this->output( "Modifying $field field of table $table..." );
$this->applyPatch( $patch, $fullpath );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
}
}
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->output( "Purging caches..." );
$this->db->delete( 'objectcache', '*', __METHOD__ );
- wfOut( "done.\n" );
+ $this->output( "done.\n" );
}
/**
* Check the site_stats table is not properly populated.
*/
protected function checkStats() {
- wfOut( "Checking site_stats row..." );
+ $this->output( "Checking site_stats row..." );
$row = $this->db->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
if ( $row === false ) {
- wfOut( "data is missing! rebuilding...\n" );
+ $this->output( "data is missing! rebuilding...\n" );
} elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
- wfOut( "missing ss_total_pages, rebuilding...\n" );
+ $this->output( "missing ss_total_pages, rebuilding...\n" );
} else {
- wfOut( "done.\n" );
+ $this->output( "done.\n" );
return;
}
SiteStatsInit::doAllAndCommit( false );
array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
);
}
- wfOut( "...ss_active_users user count set...\n" );
+ $this->output( "...ss_active_users user count set...\n" );
}
protected function doLogSearchPopulation() {
if ( $this->updateRowExists( 'populate log_search' ) ) {
- wfOut( "...log_search table already populated.\n" );
+ $this->output( "...log_search table already populated.\n" );
return;
}
- wfOut(
+ $this->output(
"Populating log_search table, printing progress markers. For large\n" .
"databases, you may want to hit Ctrl-C and do this manually with\n" .
"maintenance/populateLogSearch.php.\n" );
$task = new PopulateLogSearch();
$task->execute();
- wfOut( "Done populating log_search table.\n" );
+ $this->output( "Done populating log_search table.\n" );
}
function doUpdateTranscacheField() {
if ( $this->updateRowExists( 'convert transcache field' ) ) {
- wfOut( "...transcache tc_time already converted.\n" );
+ $this->output( "...transcache tc_time already converted.\n" );
return;
}
- wfOut( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
+ $this->output( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
$this->applyPatch( 'patch-tc-timestamp.sql' );
- wfOut( "ok\n" );
+ $this->output( "ok\n" );
}
protected function doCollationUpdate() {
'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
__METHOD__
) == 0 ) {
- wfOut( "...collations up-to-date.\n" );
+ $this->output( "...collations up-to-date.\n" );
return;
}