}
/**
- * @param DatabaseBase $db
+ * @param Database $db
* @param bool $shared
* @param Maintenance $maintenance
*
* @throws MWException
* @return DatabaseUpdater
*/
- public static function newForDB( &$db, $shared = false, $maintenance = null ) {
+ public static function newForDB( Database $db, $shared = false, $maintenance = null ) {
$type = $db->getType();
if ( in_array( $type, Installer::getDBTypes() ) ) {
$class = ucfirst( $type ) . 'Updater';
}
}
+ /**
+ * Get appropriate schema variables in the current database connection.
+ *
+ * This should be called after any request data has been imported, but before
+ * any write operations to the database. The result should be passed to the DB
+ * setSchemaVars() method.
+ *
+ * @return array
+ * @since 1.28
+ */
+ public function getSchemaVars() {
+ return []; // DB-type specific
+ }
+
/**
* Do all the updates
*
public function doUpdates( $what = [ 'core', 'extensions', 'stats' ] ) {
global $wgVersion;
+ $this->db->setSchemaVars( $this->getSchemaVars() );
+
$what = array_flip( $what );
$this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null;
if ( isset( $what['core'] ) ) {
'Making rev_page_id index non-unique'
);
}
+
+ public function getSchemaVars() {
+ global $wgDBTableOptions;
+
+ $vars = [];
+ $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
+ $vars['wgDBTableOptions'] = str_replace(
+ 'CHARSET=mysql4',
+ 'CHARSET=binary',
+ $vars['wgDBTableOptions']
+ );
+
+ return $vars;
+ }
}
return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
}
- /**
- * @return array
- */
- protected function getDefaultSchemaVars() {
- $vars = parent::getDefaultSchemaVars();
- $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] );
- $vars['wgDBTableOptions'] = str_replace(
- 'CHARSET=mysql4',
- 'CHARSET=binary',
- $vars['wgDBTableOptions']
- );
-
- return $vars;
- }
-
/**
* Get status information from SHOW STATUS in an associative array
*
* @param integer $db DB index (DB_REPLICA/DB_MASTER)
* @param array $groups; default: empty array
* @param string|bool $wiki; default: current wiki
- * @return IDatabase
+ * @return Database
*/
protected function getDB( $db, $groups = [], $wiki = false ) {
if ( is_null( $this->mDb ) ) {
public function execute() {
$dbw = $this->getDB( DB_MASTER );
+ $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
+
foreach ( $this->mArgs as $arg ) {
$files = [
$arg,
- $dbw->patchPath( $arg ),
- $dbw->patchPath( "patch-$arg.sql" ),
+ $updater->patchPath( $dbw, $arg ),
+ $updater->patchPath( $dbw, "patch-$arg.sql" ),
];
foreach ( $files as $file ) {
if ( file_exists( $file ) ) {
$this->error( "The server selected ({$db->getServer()}) is not a replica DB.", 1 );
}
+ if ( $index === DB_MASTER ) {
+ $updater = DatabaseUpdater::newForDB( $db, true, $this );
+ $db->setSchemaVars( $updater->getSchemaVars() );
+ }
+
if ( $this->hasArg( 0 ) ) {
$file = fopen( $this->getArg( 0 ), 'r' );
if ( !$file ) {