2010-07-08 14:57:19 +00:00
|
|
|
<?php
|
2010-08-21 18:20:09 +00:00
|
|
|
/**
|
|
|
|
|
* DBMS-specific updater helper.
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
*/
|
2010-10-31 19:07:05 +00:00
|
|
|
|
|
|
|
|
require_once( dirname(__FILE__) . '/../../maintenance/Maintenance.php' );
|
|
|
|
|
|
2010-07-08 14:57:19 +00:00
|
|
|
/*
|
|
|
|
|
* Class for handling database updates. Roughly based off of updaters.inc, with
|
|
|
|
|
* a few improvements :)
|
2010-07-29 18:36:39 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup Deployment
|
|
|
|
|
* @since 1.17
|
2010-07-08 14:57:19 +00:00
|
|
|
*/
|
2010-07-20 22:28:50 +00:00
|
|
|
abstract class DatabaseUpdater {
|
2010-07-08 14:57:19 +00:00
|
|
|
|
2010-07-20 11:35:38 +00:00
|
|
|
/**
|
|
|
|
|
* Array of updates to perform on the database
|
2010-07-20 22:28:50 +00:00
|
|
|
*
|
2010-07-20 11:35:38 +00:00
|
|
|
* @var array
|
|
|
|
|
*/
|
2010-07-08 14:57:19 +00:00
|
|
|
protected $updates = array();
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
protected $extensionUpdates = array();
|
|
|
|
|
|
2010-07-20 11:35:38 +00:00
|
|
|
protected $db;
|
2010-07-08 14:57:19 +00:00
|
|
|
|
2010-08-15 18:13:23 +00:00
|
|
|
protected $shared = false;
|
|
|
|
|
|
2010-08-16 14:23:28 +00:00
|
|
|
protected $postDatabaseUpdateMaintenance = array(
|
|
|
|
|
'DeleteDefaultMessages'
|
|
|
|
|
);
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param $db DatabaseBase object to perform updates on
|
|
|
|
|
* @param $shared bool Whether to perform updates on shared tables
|
2010-10-27 14:38:31 +00:00
|
|
|
* @param $maintenance Maintenance Maintenance object which created us
|
2010-09-07 14:33:11 +00:00
|
|
|
*
|
2010-11-10 14:41:46 +00:00
|
|
|
* @todo FIXME: Make $wgDatabase go away.
|
2010-09-07 14:33:11 +00:00
|
|
|
*/
|
2010-10-27 14:38:31 +00:00
|
|
|
protected function __construct( DatabaseBase &$db, $shared, Maintenance $maintenance = null ) {
|
2010-09-07 14:33:11 +00:00
|
|
|
global $wgDatabase;
|
|
|
|
|
$wgDatabase = $db;
|
2010-07-08 14:57:19 +00:00
|
|
|
$this->db = $db;
|
2010-08-15 18:13:23 +00:00
|
|
|
$this->shared = $shared;
|
2010-10-27 14:38:31 +00:00
|
|
|
if ( $maintenance ) {
|
|
|
|
|
$this->maintenance = $maintenance;
|
|
|
|
|
} else {
|
|
|
|
|
$this->maintenance = new FakeMaintenance;
|
|
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->initOldGlobals();
|
|
|
|
|
wfRunHooks( 'LoadExtensionSchemaUpdates', array( $this ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize all of the old globals. One day this should all become
|
|
|
|
|
* something much nicer
|
|
|
|
|
*/
|
|
|
|
|
private function initOldGlobals() {
|
2010-09-12 16:48:03 +00:00
|
|
|
global $wgExtNewTables, $wgExtNewFields, $wgExtPGNewFields,
|
2010-09-07 14:33:11 +00:00
|
|
|
$wgExtPGAlteredFields, $wgExtNewIndexes, $wgExtModifiedFields;
|
|
|
|
|
|
|
|
|
|
# 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
|
2010-07-20 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-27 14:38:31 +00:00
|
|
|
public static function newForDB( &$db, $shared = false, $maintenance = null ) {
|
2010-08-15 18:55:08 +00:00
|
|
|
$type = $db->getType();
|
|
|
|
|
if( in_array( $type, Installer::getDBTypes() ) ) {
|
|
|
|
|
$class = ucfirst( $type ) . 'Updater';
|
2010-10-27 14:38:31 +00:00
|
|
|
return new $class( $db, $shared, $maintenance );
|
2010-08-15 18:55:08 +00:00
|
|
|
} else {
|
|
|
|
|
throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Get a database connection to run updates
|
|
|
|
|
*
|
|
|
|
|
* @return DatabasBase object
|
|
|
|
|
*/
|
|
|
|
|
public function getDB() {
|
|
|
|
|
return $this->db;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 15:11:06 +00:00
|
|
|
/**
|
|
|
|
|
* 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 ) {
|
2010-10-27 14:38:31 +00:00
|
|
|
if ( $this->maintenance->isQuiet() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-10-01 15:11:06 +00:00
|
|
|
wfOut( $str );
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
/**
|
|
|
|
|
* Add a new update coming from an extension. This should be called by
|
|
|
|
|
* extensions while executing the LoadExtensionSchemaUpdates hook.
|
|
|
|
|
*
|
|
|
|
|
* @param $update Array: the update to run. Format is the following:
|
|
|
|
|
* first item is the callback function, it also can be a
|
|
|
|
|
* simple string with the name of a function in this class,
|
|
|
|
|
* following elements are parameters to the function.
|
|
|
|
|
* Note that callback functions will recieve this object as
|
|
|
|
|
* first parameter.
|
|
|
|
|
*/
|
|
|
|
|
public function addExtensionUpdate( $update ) {
|
|
|
|
|
$this->extensionUpdates[] = $update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the list of extension-defined updates
|
|
|
|
|
*
|
|
|
|
|
* @return Array
|
|
|
|
|
*/
|
|
|
|
|
protected function getExtensionUpdates() {
|
|
|
|
|
return $this->extensionUpdates;
|
|
|
|
|
}
|
2010-08-15 18:55:08 +00:00
|
|
|
|
2010-08-16 14:23:28 +00:00
|
|
|
public function getPostDatabaseUpdateMaintenance() {
|
|
|
|
|
return $this->postDatabaseUpdateMaintenance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
|
|
|
|
* Do all the updates
|
2010-09-11 08:23:26 +00:00
|
|
|
*
|
|
|
|
|
* @param $purge Boolean: whether to clear the objectcache table after updates
|
2010-09-07 14:33:11 +00:00
|
|
|
*/
|
|
|
|
|
public function doUpdates( $purge = true ) {
|
2010-09-12 16:24:03 +00:00
|
|
|
global $wgVersion;
|
2010-09-11 08:23:26 +00:00
|
|
|
|
2010-10-01 20:56:39 +00:00
|
|
|
if ( !defined( 'MW_NO_SETUP' ) ) {
|
|
|
|
|
define( 'MW_NO_SETUP', true );
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:23:26 +00:00
|
|
|
$this->runUpdates( $this->getCoreUpdateList(), false );
|
|
|
|
|
$this->runUpdates( $this->getOldGlobalUpdates(), false );
|
|
|
|
|
$this->runUpdates( $this->getExtensionUpdates(), true );
|
|
|
|
|
|
|
|
|
|
$this->setAppliedUpdates( $wgVersion, $this->updates );
|
|
|
|
|
|
|
|
|
|
if( $purge ) {
|
|
|
|
|
$this->purgeCache();
|
|
|
|
|
}
|
2010-09-12 09:07:51 +00:00
|
|
|
$this->checkStats();
|
2010-09-11 08:23:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper function for doUpdates()
|
|
|
|
|
*
|
|
|
|
|
* @param $updates Array of updates to run
|
|
|
|
|
* @param $passSelf Boolean: whether to pass this object we calling external
|
|
|
|
|
* functions
|
|
|
|
|
*/
|
|
|
|
|
private function runUpdates( array $updates, $passSelf ) {
|
|
|
|
|
foreach ( $updates as $params ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$func = array_shift( $params );
|
2010-08-22 12:02:36 +00:00
|
|
|
if( !is_array( $func ) && method_exists( $this, $func ) ) {
|
2010-08-17 13:36:59 +00:00
|
|
|
$func = array( $this, $func );
|
2010-09-11 08:23:26 +00:00
|
|
|
} elseif ( $passSelf ) {
|
|
|
|
|
array_unshift( $params, $this );
|
2010-08-17 13:36:59 +00:00
|
|
|
}
|
2010-08-15 18:13:23 +00:00
|
|
|
call_user_func_array( $func, $params );
|
|
|
|
|
flush();
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
2010-09-11 08:23:26 +00:00
|
|
|
$this->updates = array_merge( $this->updates, $updates );
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-17 12:15:42 +00:00
|
|
|
protected function setAppliedUpdates( $version, $updates = array() ) {
|
2010-07-11 12:31:44 +00:00
|
|
|
if( !$this->canUseNewUpdatelog() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-08-15 18:13:23 +00:00
|
|
|
$key = "updatelist-$version-" . time();
|
2010-07-08 14:57:19 +00:00
|
|
|
$this->db->insert( 'updatelog',
|
|
|
|
|
array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
|
|
|
|
|
__METHOD__ );
|
|
|
|
|
}
|
2010-07-11 12:31:44 +00:00
|
|
|
|
2010-09-12 16:24:03 +00:00
|
|
|
/**
|
|
|
|
|
* 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!
|
|
|
|
|
*/
|
|
|
|
|
public function updateRowExists( $key ) {
|
|
|
|
|
$row = $this->db->selectRow(
|
|
|
|
|
'updatelog',
|
|
|
|
|
'1',
|
|
|
|
|
array( 'ul_key' => $key ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
return (bool)$row;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-11 12:31:44 +00:00
|
|
|
/**
|
|
|
|
|
* Updatelog was changed in 1.17 to have a ul_value column so we can record
|
|
|
|
|
* more information about what kind of updates we've done (that's what this
|
|
|
|
|
* class does). Pre-1.17 wikis won't have this column, and really old wikis
|
|
|
|
|
* might not even have updatelog at all
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
protected function canUseNewUpdatelog() {
|
|
|
|
|
return $this->db->tableExists( 'updatelog' ) &&
|
|
|
|
|
$this->db->fieldExists( 'updatelog', 'ul_value' );
|
|
|
|
|
}
|
2010-07-17 12:55:52 +00:00
|
|
|
|
|
|
|
|
/**
|
2010-09-12 16:48:03 +00:00
|
|
|
* Before 1.17, we used to handle updates via stuff like
|
2010-07-17 12:55:52 +00:00
|
|
|
* $wgExtNewTables/Fields/Indexes. This is nasty :) We refactored a lot
|
2010-10-27 14:38:31 +00:00
|
|
|
* of this in 1.17 but we want to remain back-compatible for a while. So
|
2010-09-03 21:14:52 +00:00
|
|
|
* load up these old global-based things into our update list.
|
2010-07-17 12:55:52 +00:00
|
|
|
*/
|
2010-08-22 08:07:26 +00:00
|
|
|
protected function getOldGlobalUpdates() {
|
2010-09-12 16:48:03 +00:00
|
|
|
global $wgExtNewFields, $wgExtNewTables, $wgExtModifiedFields,
|
|
|
|
|
$wgExtNewIndexes, $wgSharedDB, $wgSharedTables;
|
2010-08-15 18:13:23 +00:00
|
|
|
|
|
|
|
|
$doUser = $this->shared ?
|
|
|
|
|
$wgSharedDB && in_array( 'user', $wgSharedTables ) :
|
|
|
|
|
!$wgSharedDB || !in_array( 'user', $wgSharedTables );
|
|
|
|
|
|
|
|
|
|
$updates = array();
|
2010-07-17 12:55:52 +00:00
|
|
|
|
|
|
|
|
foreach ( $wgExtNewTables as $tableRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-08-17 13:36:59 +00:00
|
|
|
'addTable', $tableRecord[0], $tableRecord[1], true
|
2010-07-17 12:55:52 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewFields as $fieldRecord ) {
|
|
|
|
|
if ( $fieldRecord[0] != 'user' || $doUser ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-08-17 17:48:22 +00:00
|
|
|
'addField', $fieldRecord[0], $fieldRecord[1],
|
2010-07-17 12:55:52 +00:00
|
|
|
$fieldRecord[2], true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewIndexes as $fieldRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-08-17 17:48:22 +00:00
|
|
|
'addIndex', $fieldRecord[0], $fieldRecord[1],
|
2010-07-17 12:55:52 +00:00
|
|
|
$fieldRecord[2], true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtModifiedFields as $fieldRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-09-11 08:35:39 +00:00
|
|
|
'modifyField', $fieldRecord[0], $fieldRecord[1],
|
2010-07-17 12:55:52 +00:00
|
|
|
$fieldRecord[2], true
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-08-15 18:13:23 +00:00
|
|
|
|
|
|
|
|
return $updates;
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
2010-07-20 22:28:50 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an array of updates to perform on the database. Should return a
|
2010-09-11 21:55:21 +00:00
|
|
|
* multi-dimensional array. The main key is the MediaWiki version (1.12,
|
2010-07-20 22:28:50 +00:00
|
|
|
* 1.13...) with the values being arrays of updates, identical to how
|
|
|
|
|
* updaters.inc did it (for now)
|
|
|
|
|
*
|
|
|
|
|
* @return Array
|
|
|
|
|
*/
|
|
|
|
|
protected abstract function getCoreUpdateList();
|
2010-08-17 13:36:59 +00:00
|
|
|
|
2010-08-17 17:48:22 +00:00
|
|
|
/**
|
|
|
|
|
* Applies a SQL patch
|
|
|
|
|
* @param $path String Path to the patch file
|
|
|
|
|
* @param $isFullPath Boolean Whether to treat $path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
protected function applyPatch( $path, $isFullPath = false ) {
|
|
|
|
|
if ( $isFullPath ) {
|
|
|
|
|
$this->db->sourceFile( $path );
|
|
|
|
|
} else {
|
2010-10-11 15:29:48 +00:00
|
|
|
$this->db->sourceFile( $this->db->patchPath( $path ) );
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 13:36:59 +00:00
|
|
|
/**
|
|
|
|
|
* Add a new table to the database
|
|
|
|
|
* @param $name String Name of the new table
|
|
|
|
|
* @param $patch String Path to the patch file
|
2010-08-17 17:48:22 +00:00
|
|
|
* @param $fullpath Boolean Whether to treat $patch path as a relative or not
|
2010-08-17 13:36:59 +00:00
|
|
|
*/
|
|
|
|
|
protected function addTable( $name, $patch, $fullpath = false ) {
|
|
|
|
|
if ( $this->db->tableExists( $name ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$name table already exists.\n" );
|
2010-08-17 13:36:59 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Creating $name table..." );
|
2010-08-17 17:48:22 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new field to an existing table
|
|
|
|
|
* @param $table String Name of the table to modify
|
|
|
|
|
* @param $field String Name of the new field
|
|
|
|
|
* @param $patch String Path to the patch file
|
|
|
|
|
* @param $fullpath Boolean Whether to treat $patch path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
protected function addField( $table, $field, $patch, $fullpath = false ) {
|
|
|
|
|
if ( !$this->db->tableExists( $table ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$table table does not exist, skipping new field patch\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
} elseif ( $this->db->fieldExists( $table, $field ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...have $field field in $table table.\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Adding $field field to table $table..." );
|
2010-08-17 17:48:22 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a new index to an existing table
|
|
|
|
|
* @param $table String Name of the table to modify
|
|
|
|
|
* @param $index String Name of the new index
|
|
|
|
|
* @param $patch String Path to the patch file
|
|
|
|
|
* @param $fullpath Boolean Whether to treat $patch path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
function addIndex( $table, $index, $patch, $fullpath = false ) {
|
|
|
|
|
if ( $this->db->indexExists( $table, $index ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$index key already set on $table table.\n" );
|
2010-08-17 17:48:22 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Adding $index key to table $table... " );
|
2010-08-17 17:48:22 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-08-17 13:36:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-08-22 11:57:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Drop a field from an existing table
|
|
|
|
|
*
|
|
|
|
|
* @param $table String Name of the table to modify
|
|
|
|
|
* @param $field String Name of the old field
|
|
|
|
|
* @param $patch String Path to the patch file
|
|
|
|
|
* @param $fullpath Boolean Whether to treat $patch path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
function dropField( $table, $field, $patch, $fullpath = false ) {
|
2010-08-22 11:59:32 +00:00
|
|
|
if ( $this->db->fieldExists( $table, $field ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Table $table contains $field field. Dropping... " );
|
2010-08-22 11:59:32 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-08-22 11:59:32 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$table table does not contain $field field.\n" );
|
2010-08-22 11:59:32 +00:00
|
|
|
}
|
2010-08-22 11:57:31 +00:00
|
|
|
}
|
2010-09-07 14:33:11 +00:00
|
|
|
|
2010-09-11 15:20:39 +00:00
|
|
|
/**
|
|
|
|
|
* Drop an index from an existing table
|
|
|
|
|
*
|
|
|
|
|
* @param $table String: Name of the table to modify
|
|
|
|
|
* @param $index String: Name of the old index
|
|
|
|
|
* @param $patch String: Path to the patch file
|
|
|
|
|
* @param $fullpath Boolean: Whether to treat $patch path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
function dropIndex( $table, $index, $patch, $fullpath = false ) {
|
|
|
|
|
if ( $this->db->indexExists( $table, $index ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Dropping $index from table $table... " );
|
2010-09-11 15:20:39 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-09-11 15:20:39 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$index key doesn't exist.\n" );
|
2010-09-11 15:20:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 08:35:39 +00:00
|
|
|
/**
|
|
|
|
|
* Modify an existing field
|
|
|
|
|
*
|
2010-09-11 08:55:09 +00:00
|
|
|
* @param $table String: name of the table to which the field belongs
|
|
|
|
|
* @param $field String: name of the field to modify
|
2010-09-11 08:35:39 +00:00
|
|
|
* @param $patch String: path to the patch file
|
|
|
|
|
* @param $fullpath Boolean: whether to treat $patch path as a relative or not
|
|
|
|
|
*/
|
|
|
|
|
public function modifyField( $table, $field, $patch, $fullpath = false ) {
|
|
|
|
|
if ( !$this->db->tableExists( $table ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$table table does not exist, skipping modify field patch\n" );
|
2010-09-11 08:35:39 +00:00
|
|
|
} elseif ( !$this->db->fieldExists( $table, $field ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...$field field does not exist in $table table, skipping modify field patch\n" );
|
2010-09-11 08:35:39 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Modifying $field field of table $table..." );
|
2010-09-11 08:35:39 +00:00
|
|
|
$this->applyPatch( $patch, $fullpath );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-09-11 08:35:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-07 14:33:11 +00:00
|
|
|
/**
|
|
|
|
|
* 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
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Purging caches..." );
|
2010-09-07 14:33:11 +00:00
|
|
|
$this->db->delete( 'objectcache', '*', __METHOD__ );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "done.\n" );
|
2010-09-07 14:33:11 +00:00
|
|
|
}
|
2010-09-12 09:07:51 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the site_stats table is not properly populated.
|
|
|
|
|
*/
|
|
|
|
|
protected function checkStats() {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Checking site_stats row..." );
|
2010-09-12 09:07:51 +00:00
|
|
|
$row = $this->db->selectRow( 'site_stats', '*', array( 'ss_row_id' => 1 ), __METHOD__ );
|
|
|
|
|
if ( $row === false ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "data is missing! rebuilding...\n" );
|
2010-09-12 09:07:51 +00:00
|
|
|
} elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "missing ss_total_pages, rebuilding...\n" );
|
2010-09-12 09:07:51 +00:00
|
|
|
} else {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "done.\n" );
|
2010-09-12 09:07:51 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
SiteStatsInit::doAllAndCommit( false );
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-12 16:24:03 +00:00
|
|
|
# Common updater functions
|
|
|
|
|
|
|
|
|
|
protected function doActiveUsersInit() {
|
|
|
|
|
$activeUsers = $this->db->selectField( 'site_stats', 'ss_active_users', false, __METHOD__ );
|
|
|
|
|
if ( $activeUsers == -1 ) {
|
|
|
|
|
$activeUsers = $this->db->selectField( 'recentchanges',
|
|
|
|
|
'COUNT( DISTINCT rc_user_text )',
|
|
|
|
|
array( 'rc_user != 0', 'rc_bot' => 0, "rc_log_type != 'newusers'" ), __METHOD__
|
|
|
|
|
);
|
|
|
|
|
$this->db->update( 'site_stats',
|
|
|
|
|
array( 'ss_active_users' => intval( $activeUsers ) ),
|
|
|
|
|
array( 'ss_row_id' => 1 ), __METHOD__, array( 'LIMIT' => 1 )
|
|
|
|
|
);
|
|
|
|
|
}
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...ss_active_users user count set...\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function doLogSearchPopulation() {
|
|
|
|
|
if ( $this->updateRowExists( 'populate log_search' ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...log_search table already populated.\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output(
|
2010-09-12 16:24:03 +00:00
|
|
|
"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();
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Done populating log_search table.\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doUpdateTranscacheField() {
|
|
|
|
|
if ( $this->updateRowExists( 'convert transcache field' ) ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...transcache tc_time already converted.\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "Converting tc_time from UNIX epoch to MediaWiki timestamp... " );
|
2010-09-12 16:24:03 +00:00
|
|
|
$this->applyPatch( 'patch-tc-timestamp.sql' );
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "ok\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function doCollationUpdate() {
|
|
|
|
|
global $wgCategoryCollation;
|
|
|
|
|
if ( $this->db->selectField(
|
|
|
|
|
'categorylinks',
|
|
|
|
|
'COUNT(*)',
|
|
|
|
|
'cl_collation != ' . $this->db->addQuotes( $wgCategoryCollation ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
) == 0 ) {
|
2010-10-01 15:11:06 +00:00
|
|
|
$this->output( "...collations up-to-date.\n" );
|
2010-09-12 16:24:03 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$task = new UpdateCollation();
|
|
|
|
|
$task->execute();
|
|
|
|
|
}
|
2010-07-20 22:28:50 +00:00
|
|
|
}
|