MediaWiki master
MediaWiki\Installer\DatabaseUpdater Class Reference

Apply database changes after updating MediaWiki. More...

Inherited by MediaWiki\Installer\MysqlUpdater, MediaWiki\Installer\PostgresUpdater, and MediaWiki\Installer\SqliteUpdater.

Collaboration diagram for MediaWiki\Installer\DatabaseUpdater:

Public Member Functions

 addExtensionField ( $tableName, $columnName, $sqlPath)
 Add a field to an existing extension table.
 
 addExtensionIndex ( $tableName, $indexName, $sqlPath)
 Add an index to an existing extension table.
 
 addExtensionTable ( $tableName, $sqlPath)
 Convenience wrapper for addExtensionUpdate() when adding a new table (which is the most common usage of updaters in an extension) Intended for use in LoadExtensionSchemaUpdates hook handlers.
 
 addExtensionUpdate (array $update)
 Add a new update coming from an extension.
 
 addExtensionUpdateOnVirtualDomain (array $update)
 Add a new update coming from an extension on virtual domain databases.
 
 addPostDatabaseUpdateMaintenance ( $class)
 Add a maintenance script to be run after the database updates are complete.
 
 doUpdates (array $what=[ 'core', 'extensions', 'stats'])
 Do all the updates.
 
 dropExtensionField ( $tableName, $columnName, $sqlPath)
 Drop a field from an extension table.
 
 dropExtensionIndex ( $tableName, $indexName, $sqlPath)
 Drop an index from an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers.
 
 dropExtensionTable ( $tableName, $sqlPath=false)
 Drop an extension table.
 
 fieldExists ( $tableName, $fieldName)
 
 getDB ()
 Get a database connection to run updates.
 
 getPostDatabaseUpdateMaintenance ()
 
 getSchemaVars ()
 Get appropriate schema variables in the current database connection.
 
 insertInitialUpdateKeys ()
 Add initial keys to the updatelog table.
 
 insertUpdateRow ( $key, $val=null)
 Helper function: Add a key to the updatelog table.
 
 modifyExtensionField ( $tableName, $fieldName, $sqlPath)
 Modify an existing field in an extension table.
 
 modifyExtensionTable ( $tableName, $sqlPath)
 Modify an existing extension table.
 
 output ( $str)
 Output some text.
 
 outputApplied (string $str)
 Output a note about an update that has already been applied.
 
 outputAppliedSummary ()
 If notes about updates that have already been applied are silenced, output a message with the count of skipped updates.
 
 patchPath (IDatabase $db, $patch)
 Get the full path to a patch file.
 
 purgeCache ()
 Purge various database caches.
 
 renameExtensionIndex ( $tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning=false)
 Rename an index on an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers.
 
 setAutoExtensionHookContainer (HookContainer $hookContainer)
 Set the HookContainer to use for loading extension schema updates.
 
 setFileAccess ()
 Set any .htaccess files or equivalent for storage repos.
 
 tableExists ( $tableName)
 
 updateRowExists ( $key)
 Helper function: check if the given key is present in the updatelog table.
 

Static Public Member Functions

static newForDB (IMaintainableDatabase $db, $shared=false, ?Maintenance $maintenance=null)
 

Public Attributes

int $appliedUpdateCount = 0
 When not outputting notes about already applied updates, their number if stored here.
 
bool $logApplied = false
 Flag specifying whether to output notes about updates that were already applied.
 
const REPLICATION_WAIT_TIMEOUT = 300
 

Protected Member Functions

 __construct (IMaintainableDatabase &$db, $shared, ?Maintenance $maintenance=null)
 
 addField ( $table, $field, $patch, $fullpath=false)
 Add a new field to an existing table.
 
 addIndex ( $table, $index, $patch, $fullpath=false)
 Add a new index to an existing table.
 
 addMissingTalkPageWatchlistLabels ()
 
 addTable ( $name, $patch, $fullpath=false)
 Add a new table to the database.
 
 appendLine ( $line)
 Append a line to the open file handle.
 
 applyPatch ( $path, $isFullPath=false, $msg=null)
 Applies a SQL patch.
 
 checkSchemaAltersAllowed (string $schemaAlterMessage)
 Checks whether the DatabaseUpdater is allowed to attempt to apply ALTER TABLE commands on the database.
 
 checkStats ()
 Check the site_stats table is not properly populated.
 
 copyFile ( $filename)
 Append an SQL fragment to the open file handle.
 
 doCollationUpdate ()
 Update CategoryLinks collation.
 
 doConvertDjvuMetadata ()
 
 doTable ( $name)
 Returns whether updates should be executed on the database table $name.
 
 dropField ( $table, $field, $patch, $fullpath=false)
 Drop a field from an existing table.
 
 dropIndex ( $table, $index, $patch, $fullpath=false)
 Drop an index from an existing table.
 
 dropTable ( $table, $patch=false, $fullpath=false)
 If the specified table exists, drop it, or execute the patch if one is provided.
 
 getCoreUpdateList ()
 Get an array of updates to perform on the database.
 
 getInitialUpdateKeys ()
 Get an array of update keys to insert into the updatelog table after a new installation.
 
 ifFieldExists ( $table, $field, $func,... $params)
 Only run a function if the named field exists.
 
 ifTableNotExists ( $table, $func,... $params)
 Only run a function if a table does not exist.
 
 migrateCategorylinks ()
 
 migrateImagelinks ()
 
 migratePagelinks ()
 
 modifyField ( $table, $field, $patch, $fullpath=false)
 Modify an existing field.
 
 modifyFieldIfNullable ( $table, $field, $patch, $fullpath=false)
 Modify a field if the field exists and is nullable.
 
 modifyPrimaryKey ( $table, array $columns, $patch, $fullpath=false)
 Modify or set a PRIMARY KEY on a table.
 
 modifyTable ( $table, $patch, $fullpath=false)
 Modify an existing table, similar to modifyField.
 
 modifyTableIfFieldNotExists ( $table, $field, $patch, $fullpath=false, $fieldBeingModified=null)
 Modify a table if a field doesn't exist.
 
 normalizeCollation ()
 
 rebuildLocalisationCache ()
 Rebuilds the localisation cache.
 
 renameIndex ( $table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath=false)
 Rename an index from an existing table.
 
 runMaintenance ( $class, $unused='')
 Run a maintenance script.
 

Protected Attributes

HookContainer null $autoExtensionHookContainer
 
IMaintainableDatabase $db
 Handle to the database subclass.
 
array $extensionUpdates = []
 List of extension-provided database updates.
 
array $extensionUpdatesWithVirtualDomains = []
 List of extension-provided database updates on virtual domain dbs.
 
resource null $fileHandle = null
 File handle for SQL output.
 
Maintenance $maintenance
 
class string< Maintenance >[] $postDatabaseUpdateMaintenance
 Scripts to run after database update Should be a subclass of LoggedUpdateMaintenance.
 
bool $shared = false
 
bool $skipSchema = false
 Flag specifying whether to skip schema (e.g., SQL-only) updates.
 
bool bool $skipSchemaAlters = false
 Flag specifying whether to skip alter schema updates.
 
array $updates = []
 Array of updates to perform on the database.
 
array $updatesSkipped = []
 Array of updates that were skipped.
 

Detailed Description

Apply database changes after updating MediaWiki.

Since
1.17

Definition at line 40 of file DatabaseUpdater.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Installer\DatabaseUpdater::__construct ( IMaintainableDatabase & $db,
$shared,
?Maintenance $maintenance = null )
protected
Parameters
IMaintainableDatabase&$dbTo perform updates on
bool$sharedWhether to perform updates on shared tables
Maintenance | null$maintenanceMaintenance object which created us

Definition at line 140 of file DatabaseUpdater.php.

References MediaWiki\Installer\DatabaseUpdater\$db, MediaWiki\Installer\DatabaseUpdater\$maintenance, MediaWiki\Installer\DatabaseUpdater\$shared, DBO_DDLMODE, MediaWiki\Maintenance\Maintenance\setDB(), and Wikimedia\Rdbms\Database\IDatabaseFlags\setFlag().

Member Function Documentation

◆ addExtensionField()

MediaWiki\Installer\DatabaseUpdater::addExtensionField ( $tableName,
$columnName,
$sqlPath )

Add a field to an existing extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.19
Parameters
string$tableName
string$columnName
string$sqlPath

Definition at line 339 of file DatabaseUpdater.php.

◆ addExtensionIndex()

MediaWiki\Installer\DatabaseUpdater::addExtensionIndex ( $tableName,
$indexName,
$sqlPath )

Add an index to an existing extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.19
Parameters
string$tableName
string$indexName
string$sqlPath

Definition at line 325 of file DatabaseUpdater.php.

◆ addExtensionTable()

MediaWiki\Installer\DatabaseUpdater::addExtensionTable ( $tableName,
$sqlPath )

Convenience wrapper for addExtensionUpdate() when adding a new table (which is the most common usage of updaters in an extension) Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.18
Parameters
string$tableNameName of table to create
string$sqlPathFull path to the schema file

Definition at line 311 of file DatabaseUpdater.php.

◆ addExtensionUpdate()

MediaWiki\Installer\DatabaseUpdater::addExtensionUpdate ( array $update)

Add a new update coming from an extension.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.17
Parameters
array$updateThe update to run. Format is [ $callback, $params... ] $callback is the method to call; either a DatabaseUpdater method name or a callable. Must be serializable (i.e., no anonymous functions allowed). The rest of the parameters (if any) will be passed to the callback. The first parameter passed to the callback is always this object.

Definition at line 284 of file DatabaseUpdater.php.

◆ addExtensionUpdateOnVirtualDomain()

MediaWiki\Installer\DatabaseUpdater::addExtensionUpdateOnVirtualDomain ( array $update)

Add a new update coming from an extension on virtual domain databases.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.42
Parameters
array$updateThe update to run. The format is [ $virtualDomain, $callback, $params... ] similarly to addExtensionUpdate()

Definition at line 297 of file DatabaseUpdater.php.

◆ addField()

MediaWiki\Installer\DatabaseUpdater::addField ( $table,
$field,
$patch,
$fullpath = false )
protected

Add a new field to an existing table.

Note
Code in a LoadExtensionSchemaUpdates handler should use addExtensionField instead!
Parameters
string$tableName of the table to modify
string$fieldName of the new field
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 874 of file DatabaseUpdater.php.

◆ addIndex()

MediaWiki\Installer\DatabaseUpdater::addIndex ( $table,
$index,
$patch,
$fullpath = false )
protected

Add a new index to an existing table.

Note
Code in a LoadExtensionSchemaUpdates handler should use addExtensionIndex instead!
Parameters
string$tableName of the table to modify
string$indexName of the new index
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 907 of file DatabaseUpdater.php.

◆ addMissingTalkPageWatchlistLabels()

MediaWiki\Installer\DatabaseUpdater::addMissingTalkPageWatchlistLabels ( )
protected

Definition at line 1574 of file DatabaseUpdater.php.

◆ addPostDatabaseUpdateMaintenance()

MediaWiki\Installer\DatabaseUpdater::addPostDatabaseUpdateMaintenance ( $class)

Add a maintenance script to be run after the database updates are complete.

Script should subclass LoggedUpdateMaintenance

Since
1.19
Parameters
class-string<Maintenance>$class Name of a Maintenance subclass

Definition at line 468 of file DatabaseUpdater.php.

◆ addTable()

MediaWiki\Installer\DatabaseUpdater::addTable ( $name,
$patch,
$fullpath = false )
protected

Add a new table to the database.

Note
Code in a LoadExtensionSchemaUpdates handler should use addExtensionTable instead!
Parameters
string$nameName of the new table
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 849 of file DatabaseUpdater.php.

◆ appendLine()

MediaWiki\Installer\DatabaseUpdater::appendLine ( $line)
protected

Append a line to the open file handle.

The line is assumed to be a complete SQL statement.

This is used as a callback for sourceLine().

Note
protected since 1.35
Parameters
string$lineText to append to the file
Returns
bool False to skip actually executing the file

Definition at line 775 of file DatabaseUpdater.php.

◆ applyPatch()

MediaWiki\Installer\DatabaseUpdater::applyPatch ( $path,
$isFullPath = false,
$msg = null )
protected

Applies a SQL patch.

Note
Do not use this in a LoadExtensionSchemaUpdates handler, use addExtensionUpdate instead!
Parameters
string$pathPath to the patch file
bool$isFullPathWhether to treat $path as a relative or not
string | null$msgDescription of the patch
Returns
bool False if the patch was skipped.

Definition at line 795 of file DatabaseUpdater.php.

References $path.

Referenced by MediaWiki\Installer\PostgresUpdater\addPgExtIndex(), MediaWiki\Installer\MysqlUpdater\migrateSearchindex(), MediaWiki\Installer\PostgresUpdater\migrateSearchindex(), and MediaWiki\Installer\PostgresUpdater\renameTable().

◆ checkSchemaAltersAllowed()

◆ checkStats()

MediaWiki\Installer\DatabaseUpdater::checkStats ( )
protected

Check the site_stats table is not properly populated.

Definition at line 1414 of file DatabaseUpdater.php.

◆ copyFile()

MediaWiki\Installer\DatabaseUpdater::copyFile ( $filename)
protected

Append an SQL fragment to the open file handle.

Note
protected since 1.35
Parameters
string$filenameFile name to open

Definition at line 754 of file DatabaseUpdater.php.

◆ doCollationUpdate()

MediaWiki\Installer\DatabaseUpdater::doCollationUpdate ( )
protected

Update CategoryLinks collation.

Definition at line 1437 of file DatabaseUpdater.php.

References $wgCategoryCollation.

◆ doConvertDjvuMetadata()

MediaWiki\Installer\DatabaseUpdater::doConvertDjvuMetadata ( )
protected

Definition at line 1452 of file DatabaseUpdater.php.

◆ doTable()

MediaWiki\Installer\DatabaseUpdater::doTable ( $name)
protected

Returns whether updates should be executed on the database table $name.

Updates will be prevented if the table is a shared table, and it is not specified to run updates on shared tables.

Parameters
string$nameTable name
Returns
bool

Definition at line 689 of file DatabaseUpdater.php.

References $wgSharedDB, and $wgSharedTables.

◆ doUpdates()

MediaWiki\Installer\DatabaseUpdater::doUpdates ( array $what = [ 'core', 'extensions', 'stats' ])

Do all the updates.

Parameters
array$whatWhat updates to perform. Supports:
  • 'core' - Run updates for MediaWiki core
  • 'extensions' - Run updates for extensions and skins
  • 'stats' - Check that the site_stats table is populated correctly
  • 'initial' - Inserts the initial update keys from MediaWiki core
  • 'noschema' - Skips all schema updates
  • 'noschema-alters' - Skips all schema updates that involve an ALTER TABLE command, intended for use during install.php where the application of schema updates is not necessary and may cause permission errors when executing the statements in the database

Definition at line 525 of file DatabaseUpdater.php.

◆ dropExtensionField()

MediaWiki\Installer\DatabaseUpdater::dropExtensionField ( $tableName,
$columnName,
$sqlPath )

Drop a field from an extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.20
Parameters
string$tableName
string$columnName
string$sqlPath

Definition at line 353 of file DatabaseUpdater.php.

◆ dropExtensionIndex()

MediaWiki\Installer\DatabaseUpdater::dropExtensionIndex ( $tableName,
$indexName,
$sqlPath )

Drop an index from an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.21
Parameters
string$tableName
string$indexName
string$sqlPathThe path to the SQL change path

Definition at line 367 of file DatabaseUpdater.php.

◆ dropExtensionTable()

MediaWiki\Installer\DatabaseUpdater::dropExtensionTable ( $tableName,
$sqlPath = false )

Drop an extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.20
Parameters
string$tableName
string | bool$sqlPath

Definition at line 380 of file DatabaseUpdater.php.

◆ dropField()

MediaWiki\Installer\DatabaseUpdater::dropField ( $table,
$field,
$patch,
$fullpath = false )
protected

Drop a field from an existing table.

Note
Code in a LoadExtensionSchemaUpdates handler should use dropExtensionField instead!
Parameters
string$tableName of the table to modify
string$fieldName of the old field
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 940 of file DatabaseUpdater.php.

◆ dropIndex()

MediaWiki\Installer\DatabaseUpdater::dropIndex ( $table,
$index,
$patch,
$fullpath = false )
protected

Drop an index from an existing table.

Note
Code in a LoadExtensionSchemaUpdates handler should use dropExtensionIndex instead!
Parameters
string$tableName of the table to modify
string$indexName of the index
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 975 of file DatabaseUpdater.php.

◆ dropTable()

MediaWiki\Installer\DatabaseUpdater::dropTable ( $table,
$patch = false,
$fullpath = false )
protected

If the specified table exists, drop it, or execute the patch if one is provided.

Note
Code in a LoadExtensionSchemaUpdates handler should use dropExtensionTable instead!
protected since 1.35
Parameters
string$tableTable to drop.
string | false$patchString of patch file that will drop the table. Default: false.
bool$fullpathWhether $patch is a full path. Default: false.
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 1075 of file DatabaseUpdater.php.

◆ fieldExists()

MediaWiki\Installer\DatabaseUpdater::fieldExists ( $tableName,
$fieldName )
Since
1.40
Parameters
string$tableName
string$fieldName
Returns
bool

Definition at line 455 of file DatabaseUpdater.php.

◆ getCoreUpdateList()

MediaWiki\Installer\DatabaseUpdater::getCoreUpdateList ( )
abstractprotected

Get an array of updates to perform on the database.

Should return a multidimensional array. The main key is the MediaWiki version (1.12, 1.13...) with the values being arrays of updates.

Returns
array[]

Reimplemented in MediaWiki\Installer\MysqlUpdater, MediaWiki\Installer\PostgresUpdater, and MediaWiki\Installer\SqliteUpdater.

◆ getDB()

MediaWiki\Installer\DatabaseUpdater::getDB ( )

Get a database connection to run updates.

Returns
IMaintainableDatabase

Definition at line 227 of file DatabaseUpdater.php.

References MediaWiki\Installer\DatabaseUpdater\$db.

◆ getInitialUpdateKeys()

MediaWiki\Installer\DatabaseUpdater::getInitialUpdateKeys ( )
abstractprotected

Get an array of update keys to insert into the updatelog table after a new installation.

The named operations will then be skipped by a subsequent update.

Add keys here to skip updates that are redundant or harmful on a new installation, for example reducing field sizes, adding constraints, etc.

Returns
string[]

Reimplemented in MediaWiki\Installer\MysqlUpdater, MediaWiki\Installer\PostgresUpdater, and MediaWiki\Installer\SqliteUpdater.

◆ getPostDatabaseUpdateMaintenance()

MediaWiki\Installer\DatabaseUpdater::getPostDatabaseUpdateMaintenance ( )
Since
1.17
Returns
class-string<Maintenance>[]

Definition at line 477 of file DatabaseUpdater.php.

◆ getSchemaVars()

MediaWiki\Installer\DatabaseUpdater::getSchemaVars ( )

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.

Returns
array
Since
1.28

Reimplemented in MediaWiki\Installer\MysqlUpdater.

Definition at line 507 of file DatabaseUpdater.php.

◆ ifFieldExists()

MediaWiki\Installer\DatabaseUpdater::ifFieldExists ( $table,
$field,
$func,
$params )
protected

Only run a function if the named field exists.

Since
1.35
Parameters
string$tableTable to check. If passed $this, it's assumed to be a call from runUpdates() with $passSelf = true: all other parameters are shifted and $this is prepended to the rest of $params.
string$fieldField to check
string | array | static$funcNormally this is the string naming the method on $this to call. It may also be an array style callable.
mixed...$params Parameters for $func
Returns
mixed Whatever $func returns, or null when skipped.

Definition at line 1635 of file DatabaseUpdater.php.

◆ ifTableNotExists()

MediaWiki\Installer\DatabaseUpdater::ifTableNotExists ( $table,
$func,
$params )
protected

Only run a function if a table does not exist.

Since
1.35
Parameters
string$tableTable to check. If passed $this, it's assumed to be a call from runUpdates() with $passSelf = true: all other parameters are shifted and $this is prepended to the rest of $params.
string | array | static$funcNormally this is the string naming the method on $this to call. It may also be an array style callable.
mixed...$params Parameters for $func
Returns
mixed Whatever $func returns, or null when skipped.

Definition at line 1599 of file DatabaseUpdater.php.

◆ insertInitialUpdateKeys()

MediaWiki\Installer\DatabaseUpdater::insertInitialUpdateKeys ( )

Add initial keys to the updatelog table.

Should be called during installation.

Definition at line 668 of file DatabaseUpdater.php.

References DBO_DDLMODE.

◆ insertUpdateRow()

MediaWiki\Installer\DatabaseUpdater::insertUpdateRow ( $key,
$val = null )

Helper function: Add a key to the updatelog table.

Note
Extensions must only use this from within callbacks registered with addExtensionUpdate(). In particular, this method must not be called directly from a LoadExtensionSchemaUpdates handler.
Parameters
string$keyName of the key to insert
string | null$val[optional] Value to insert along with the key

Definition at line 645 of file DatabaseUpdater.php.

References DBO_DDLMODE.

Referenced by MediaWiki\Installer\MysqlUpdater\changeTableOption(), MediaWiki\Installer\MysqlUpdater\dropDefault(), MediaWiki\Installer\MysqlUpdater\migrateSearchindex(), and MediaWiki\Installer\PostgresUpdater\migrateSearchindex().

◆ migrateCategorylinks()

MediaWiki\Installer\DatabaseUpdater::migrateCategorylinks ( )
protected

Definition at line 1511 of file DatabaseUpdater.php.

◆ migrateImagelinks()

MediaWiki\Installer\DatabaseUpdater::migrateImagelinks ( )
protected

Definition at line 1553 of file DatabaseUpdater.php.

◆ migratePagelinks()

MediaWiki\Installer\DatabaseUpdater::migratePagelinks ( )
protected

Definition at line 1490 of file DatabaseUpdater.php.

◆ modifyExtensionField()

MediaWiki\Installer\DatabaseUpdater::modifyExtensionField ( $tableName,
$fieldName,
$sqlPath )

Modify an existing field in an extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.21
Parameters
string$tableName
string$fieldNameThe field to be modified
string$sqlPathThe path to the SQL patch

Definition at line 421 of file DatabaseUpdater.php.

◆ modifyExtensionTable()

MediaWiki\Installer\DatabaseUpdater::modifyExtensionTable ( $tableName,
$sqlPath )

Modify an existing extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.31
Parameters
string$tableName
string$sqlPathThe path to the SQL patch

Definition at line 434 of file DatabaseUpdater.php.

◆ modifyField()

MediaWiki\Installer\DatabaseUpdater::modifyField ( $table,
$field,
$patch,
$fullpath = false )
protected

Modify an existing field.

Note
Code in a LoadExtensionSchemaUpdates handler should use modifyExtensionField instead!
protected since 1.35
Parameters
string$tableName of the table to which the field belongs
string$fieldName of the field to modify
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 1111 of file DatabaseUpdater.php.

◆ modifyFieldIfNullable()

MediaWiki\Installer\DatabaseUpdater::modifyFieldIfNullable ( $table,
$field,
$patch,
$fullpath = false )
protected

Modify a field if the field exists and is nullable.

Since
1.44
Parameters
string$tableName of the table to which the field belongs
string$fieldName of the field to modify
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 1262 of file DatabaseUpdater.php.

◆ modifyPrimaryKey()

MediaWiki\Installer\DatabaseUpdater::modifyPrimaryKey ( $table,
array $columns,
$patch,
$fullpath = false )
protected

Modify or set a PRIMARY KEY on a table.

This checks the current table schema via the database layer to determine the existing PRIMARY KEY columns. If they already match the requested set, the patch is skipped; otherwise the supplied patch is applied.

Parameters
string$tableTable name
string[]$columnsDesired PRIMARY KEY columns in order
string$patchSQL patch path
bool$fullpathWhether $patch is a full path
Returns
bool False if the patch was skipped because schema changes are skipped

Definition at line 1132 of file DatabaseUpdater.php.

◆ modifyTable()

MediaWiki\Installer\DatabaseUpdater::modifyTable ( $table,
$patch,
$fullpath = false )
protected

Modify an existing table, similar to modifyField.

Intended for changes that touch more than one column on a table.

Note
Code in a LoadExtensionSchemaUpdates handler should use modifyExtensionTable instead!
protected since 1.35
Parameters
string$tableName of the table to modify
string$patchName of the patch file to apply
string | bool$fullpathWhether to treat $patch path as relative or not, defaults to false
Returns
bool False if this was skipped because of schema changes being skipped

Definition at line 1171 of file DatabaseUpdater.php.

◆ modifyTableIfFieldNotExists()

MediaWiki\Installer\DatabaseUpdater::modifyTableIfFieldNotExists ( $table,
$field,
$patch,
$fullpath = false,
$fieldBeingModified = null )
protected

Modify a table if a field doesn't exist.

This helps extensions to avoid running updates on SQLite that are destructive because they don't copy new fields.

Since
1.44
Parameters
string$tableName of the table to which the field belongs
string$fieldName of the field to check
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
string | null$fieldBeingModifiedThe field being modified. If this is specified, the updatelog key will match that used by modifyField(), so if the patch was previously applied via modifyField(), it won't be applied again. Also, if the field doesn't exist, the patch will not be applied. If this is null, the updatelog key will match that used by modifyTable().
Returns
bool False if this was skipped because schema changes are skipped

Definition at line 1214 of file DatabaseUpdater.php.

◆ newForDB()

static MediaWiki\Installer\DatabaseUpdater::newForDB ( IMaintainableDatabase $db,
$shared = false,
?Maintenance $maintenance = null )
static
Parameters
IMaintainableDatabase$db
bool$shared
Maintenance | null$maintenance
Returns
DatabaseUpdater

Definition at line 196 of file DatabaseUpdater.php.

References MediaWiki\Installer\DatabaseUpdater\$db, MediaWiki\Installer\DatabaseUpdater\$maintenance, MediaWiki\Installer\DatabaseUpdater\$shared, MediaWiki\Installer\Installer\getDBTypes(), and Wikimedia\Rdbms\IReadableDatabase\getType().

◆ normalizeCollation()

MediaWiki\Installer\DatabaseUpdater::normalizeCollation ( )
protected

Definition at line 1532 of file DatabaseUpdater.php.

◆ output()

MediaWiki\Installer\DatabaseUpdater::output ( $str)

◆ outputApplied()

MediaWiki\Installer\DatabaseUpdater::outputApplied ( string $str)

Output a note about an update that has already been applied.

These updates may instead be silenced and merely counted.

Parameters
string$strText to output

Definition at line 237 of file DatabaseUpdater.php.

References MediaWiki\Installer\DatabaseUpdater\output().

Referenced by MediaWiki\Installer\MysqlUpdater\migrateSearchindex(), and MediaWiki\Installer\PostgresUpdater\migrateSearchindex().

◆ outputAppliedSummary()

MediaWiki\Installer\DatabaseUpdater::outputAppliedSummary ( )

If notes about updates that have already been applied are silenced, output a message with the count of skipped updates.

Definition at line 249 of file DatabaseUpdater.php.

◆ patchPath()

MediaWiki\Installer\DatabaseUpdater::patchPath ( IDatabase $db,
$patch )

Get the full path to a patch file.

Parameters
IDatabase$db
string$patchThe basename of the patch, like patch-something.sql
Returns
string Full path to patch file. It fails back to MySQL if no DB-specific patch exists.

Definition at line 826 of file DatabaseUpdater.php.

References Wikimedia\Rdbms\IReadableDatabase\getType().

◆ purgeCache()

MediaWiki\Installer\DatabaseUpdater::purgeCache ( )

Purge various database caches.

Definition at line 1386 of file DatabaseUpdater.php.

References $wgLocalisationCacheConf.

◆ rebuildLocalisationCache()

MediaWiki\Installer\DatabaseUpdater::rebuildLocalisationCache ( )
protected

Rebuilds the localisation cache.

Definition at line 1476 of file DatabaseUpdater.php.

◆ renameExtensionIndex()

MediaWiki\Installer\DatabaseUpdater::renameExtensionIndex ( $tableName,
$oldIndexName,
$newIndexName,
$sqlPath,
$skipBothIndexExistWarning = false )

Rename an index on an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.21
Parameters
string$tableName
string$oldIndexName
string$newIndexName
string$sqlPathThe path to the SQL change file
bool$skipBothIndexExistWarningWhether to warn if both the old and the new indexes exist. [facultative; by default, false]

Definition at line 397 of file DatabaseUpdater.php.

◆ renameIndex()

MediaWiki\Installer\DatabaseUpdater::renameIndex ( $table,
$oldIndex,
$newIndex,
$skipBothIndexExistWarning,
$patch,
$fullpath = false )
protected

Rename an index from an existing table.

Note
Code in a LoadExtensionSchemaUpdates handler should use renameExtensionIndex instead!
Parameters
string$tableName of the table to modify
string$oldIndexOld name of the index
string$newIndexNew name of the index
bool$skipBothIndexExistWarningWhether to warn if both the old and new indexes exist.
string$patchPath to the patch file
bool$fullpathWhether to treat $patch path as a relative or not
Returns
bool False if this was skipped because schema changes are skipped

Reimplemented in MediaWiki\Installer\PostgresUpdater.

Definition at line 1013 of file DatabaseUpdater.php.

◆ runMaintenance()

MediaWiki\Installer\DatabaseUpdater::runMaintenance ( $class,
$unused = '' )
protected

Run a maintenance script.

This should only be used when the maintenance script must run before later updates. If later updates don't depend on the script, add it to DatabaseUpdater::$postDatabaseUpdateMaintenance instead.

The script's execute() method must return true to indicate successful completion, and must return false (or throw an exception) to indicate unsuccessful completion.

Note
Code in a LoadExtensionSchemaUpdates handler should use addExtensionUpdate instead!
protected since 1.35
Since
1.32
Parameters
class-string<Maintenance>$class Maintenance subclass
string$unusedUnused, kept for compatibility

Definition at line 1346 of file DatabaseUpdater.php.

References MediaWiki\Maintenance\LoggedUpdateMaintenance\isAlreadyCompleted().

◆ setAutoExtensionHookContainer()

MediaWiki\Installer\DatabaseUpdater::setAutoExtensionHookContainer ( HookContainer $hookContainer)

Set the HookContainer to use for loading extension schema updates.

Access: internal
For use by DatabaseInstaller
Since
1.36
Parameters
HookContainer$hookContainer

Definition at line 218 of file DatabaseUpdater.php.

◆ setFileAccess()

MediaWiki\Installer\DatabaseUpdater::setFileAccess ( )

Set any .htaccess files or equivalent for storage repos.

Some zones (e.g. "temp") used to be public and may have been initialized as such

Definition at line 1365 of file DatabaseUpdater.php.

◆ tableExists()

MediaWiki\Installer\DatabaseUpdater::tableExists ( $tableName)
Since
1.20
Parameters
string$tableName
Returns
bool

Definition at line 444 of file DatabaseUpdater.php.

Referenced by MediaWiki\Installer\MysqlUpdater\migrateSearchindex(), and MediaWiki\Installer\PostgresUpdater\migrateSearchindex().

◆ updateRowExists()

MediaWiki\Installer\DatabaseUpdater::updateRowExists ( $key)

Helper function: check if the given key is present in the updatelog table.

Parameters
string$keyName of the key to check for
Returns
bool

Definition at line 619 of file DatabaseUpdater.php.

Referenced by MediaWiki\Installer\MysqlUpdater\changeTableOption(), MediaWiki\Installer\MysqlUpdater\dropDefault(), MediaWiki\Installer\MysqlUpdater\migrateSearchindex(), and MediaWiki\Installer\PostgresUpdater\migrateSearchindex().

Member Data Documentation

◆ $appliedUpdateCount

int MediaWiki\Installer\DatabaseUpdater::$appliedUpdateCount = 0

When not outputting notes about already applied updates, their number if stored here.

Definition at line 133 of file DatabaseUpdater.php.

◆ $autoExtensionHookContainer

HookContainer null MediaWiki\Installer\DatabaseUpdater::$autoExtensionHookContainer
protected

Definition at line 85 of file DatabaseUpdater.php.

◆ $db

IMaintainableDatabase MediaWiki\Installer\DatabaseUpdater::$db
protected

◆ $extensionUpdates

array MediaWiki\Installer\DatabaseUpdater::$extensionUpdates = []
protected

List of extension-provided database updates.

Definition at line 61 of file DatabaseUpdater.php.

◆ $extensionUpdatesWithVirtualDomains

array MediaWiki\Installer\DatabaseUpdater::$extensionUpdatesWithVirtualDomains = []
protected

List of extension-provided database updates on virtual domain dbs.

Definition at line 67 of file DatabaseUpdater.php.

◆ $fileHandle

resource null MediaWiki\Installer\DatabaseUpdater::$fileHandle = null
protected

File handle for SQL output.

Definition at line 101 of file DatabaseUpdater.php.

◆ $logApplied

bool MediaWiki\Installer\DatabaseUpdater::$logApplied = false

Flag specifying whether to output notes about updates that were already applied.

Definition at line 126 of file DatabaseUpdater.php.

◆ $maintenance

Maintenance MediaWiki\Installer\DatabaseUpdater::$maintenance
protected

◆ $postDatabaseUpdateMaintenance

class string<Maintenance> [] MediaWiki\Installer\DatabaseUpdater::$postDatabaseUpdateMaintenance
protected
Initial value:
= [
DeleteDefaultMessages::class,
CleanupEmptyCategories::class,
]

Scripts to run after database update Should be a subclass of LoggedUpdateMaintenance.

Definition at line 91 of file DatabaseUpdater.php.

◆ $shared

bool MediaWiki\Installer\DatabaseUpdater::$shared = false
protected

◆ $skipSchema

bool MediaWiki\Installer\DatabaseUpdater::$skipSchema = false
protected

Flag specifying whether to skip schema (e.g., SQL-only) updates.

Definition at line 108 of file DatabaseUpdater.php.

◆ $skipSchemaAlters

bool bool MediaWiki\Installer\DatabaseUpdater::$skipSchemaAlters = false
protected

Flag specifying whether to skip alter schema updates.

Definition at line 113 of file DatabaseUpdater.php.

◆ $updates

array MediaWiki\Installer\DatabaseUpdater::$updates = []
protected

Array of updates to perform on the database.

Definition at line 48 of file DatabaseUpdater.php.

◆ $updatesSkipped

array MediaWiki\Installer\DatabaseUpdater::$updatesSkipped = []
protected

Array of updates that were skipped.

Definition at line 55 of file DatabaseUpdater.php.

◆ REPLICATION_WAIT_TIMEOUT

const MediaWiki\Installer\DatabaseUpdater::REPLICATION_WAIT_TIMEOUT = 300

Definition at line 41 of file DatabaseUpdater.php.


The documentation for this class was generated from the following file: