2010-07-08 14:57:19 +00:00
|
|
|
<?php
|
2010-07-20 11:35:38 +00:00
|
|
|
|
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-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-08-15 18:13:23 +00:00
|
|
|
protected function __construct( $db, $shared ) {
|
2010-07-08 14:57:19 +00:00
|
|
|
$this->db = $db;
|
2010-08-15 18:13:23 +00:00
|
|
|
$this->shared = $shared;
|
2010-07-20 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-15 18:13:23 +00:00
|
|
|
public static function newForDB( $db, $shared ) {
|
2010-08-15 18:55:08 +00:00
|
|
|
$type = $db->getType();
|
|
|
|
|
if( in_array( $type, Installer::getDBTypes() ) ) {
|
|
|
|
|
$class = ucfirst( $type ) . 'Updater';
|
|
|
|
|
return new $class( $db, $shared );
|
|
|
|
|
} else {
|
|
|
|
|
throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' );
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-15 18:55:08 +00:00
|
|
|
public function getDB() { return $this->db; }
|
|
|
|
|
|
2010-08-16 14:23:28 +00:00
|
|
|
public function getPostDatabaseUpdateMaintenance() {
|
|
|
|
|
return $this->postDatabaseUpdateMaintenance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-15 18:24:26 +00:00
|
|
|
public function doUpdates() {
|
2010-08-15 18:13:23 +00:00
|
|
|
global $IP, $wgVersion;
|
2010-07-08 14:57:19 +00:00
|
|
|
require_once( "$IP/maintenance/updaters.inc" );
|
2010-08-15 18:13:23 +00:00
|
|
|
$this->updates = array_merge( $this->getCoreUpdateList(),
|
2010-08-15 18:24:26 +00:00
|
|
|
$this->getOldGlobalUpdates() );
|
2010-08-15 18:13:23 +00:00
|
|
|
foreach ( $this->updates as $params ) {
|
|
|
|
|
$func = array_shift( $params );
|
|
|
|
|
call_user_func_array( $func, $params );
|
|
|
|
|
flush();
|
2010-07-08 14:57:19 +00:00
|
|
|
}
|
2010-08-15 18:13:23 +00:00
|
|
|
$this->setAppliedUpdates( $wgVersion, $this->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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Before 1.17, we used to handle updates via stuff like $wgUpdates,
|
|
|
|
|
* $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
|
|
|
|
|
* load up these old global-based things into our update list. We can't
|
|
|
|
|
* version these like we do with our core updates, so they have to go
|
|
|
|
|
* in 'always'
|
|
|
|
|
*/
|
2010-08-15 18:24:26 +00:00
|
|
|
private function getOldGlobalUpdates() {
|
2010-07-17 12:55:52 +00:00
|
|
|
global $wgUpdates, $wgExtNewFields, $wgExtNewTables,
|
2010-08-15 18:13:23 +00:00
|
|
|
$wgExtModifiedFields, $wgExtNewIndexes, $wgSharedDB, $wgSharedTables;
|
|
|
|
|
|
|
|
|
|
$doUser = $this->shared ?
|
|
|
|
|
$wgSharedDB && in_array( 'user', $wgSharedTables ) :
|
|
|
|
|
!$wgSharedDB || !in_array( 'user', $wgSharedTables );
|
|
|
|
|
|
|
|
|
|
$updates = array();
|
2010-07-17 12:55:52 +00:00
|
|
|
|
|
|
|
|
if( isset( $wgUpdates[ $this->db->getType() ] ) ) {
|
|
|
|
|
foreach( $wgUpdates[ $this->db->getType() ] as $upd ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = $upd;
|
2010-07-17 12:55:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewTables as $tableRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-07-17 12:55:52 +00:00
|
|
|
'add_table', $tableRecord[0], $tableRecord[1], true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewFields as $fieldRecord ) {
|
|
|
|
|
if ( $fieldRecord[0] != 'user' || $doUser ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-07-17 12:55:52 +00:00
|
|
|
'add_field', $fieldRecord[0], $fieldRecord[1],
|
|
|
|
|
$fieldRecord[2], true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtNewIndexes as $fieldRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-07-17 12:55:52 +00:00
|
|
|
'add_index', $fieldRecord[0], $fieldRecord[1],
|
|
|
|
|
$fieldRecord[2], true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $wgExtModifiedFields as $fieldRecord ) {
|
2010-08-15 18:13:23 +00:00
|
|
|
$updates[] = array(
|
2010-07-17 12:55:52 +00:00
|
|
|
'modify_field', $fieldRecord[0], $fieldRecord[1],
|
|
|
|
|
$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
|
|
|
|
|
* mutli-dimensional array. The main key is the MediaWiki version (1.12,
|
|
|
|
|
* 1.13...) with the values being arrays of updates, identical to how
|
|
|
|
|
* updaters.inc did it (for now)
|
|
|
|
|
*
|
|
|
|
|
* @return Array
|
|
|
|
|
*/
|
|
|
|
|
protected abstract function getCoreUpdateList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class OracleUpdater extends DatabaseUpdater {
|
|
|
|
|
protected function getCoreUpdateList() {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
}
|