MediaWiki  master
DatabaseUpdater Class Reference

Class for handling database updates. More...

Inheritance diagram for DatabaseUpdater:
Collaboration diagram for DatabaseUpdater:

Public Member Functions

 addExtensionField ( $tableName, $columnName, $sqlPath)
 Add a field to an existing extension table. More...
 
 addExtensionIndex ( $tableName, $indexName, $sqlPath)
 Add an index to an existing extension table. More...
 
 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. More...
 
 addExtensionUpdate (array $update)
 Add a new update coming from an extension. More...
 
 addPostDatabaseUpdateMaintenance ( $class)
 Add a maintenance script to be run after the database updates are complete. More...
 
 doUpdates (array $what=[ 'core', 'extensions', 'stats'])
 Do all the updates. More...
 
 dropExtensionField ( $tableName, $columnName, $sqlPath)
 Drop a field from an extension table. More...
 
 dropExtensionIndex ( $tableName, $indexName, $sqlPath)
 Drop an index from an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers. More...
 
 dropExtensionTable ( $tableName, $sqlPath=false)
 Drop an extension table. More...
 
 getDB ()
 Get a database connection to run updates. More...
 
 getPostDatabaseUpdateMaintenance ()
 
 getSchemaVars ()
 Get appropriate schema variables in the current database connection. More...
 
 insertUpdateRow ( $key, $val=null)
 Helper function: Add a key to the updatelog table. More...
 
 modifyExtensionField ( $tableName, $fieldName, $sqlPath)
 Modify an existing field in an extension table. More...
 
 modifyExtensionTable ( $tableName, $sqlPath)
 Modify an existing extension table. More...
 
 output ( $str)
 Output some text. More...
 
 patchPath (IDatabase $db, $patch)
 Get the full path of a patch file. More...
 
 purgeCache ()
 Purge various database caches. More...
 
 renameExtensionIndex ( $tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning=false)
 Rename an index on an extension table Intended for use in LoadExtensionSchemaUpdates hook handlers. More...
 
 setFileAccess ()
 Set any .htaccess files or equivilent for storage repos. More...
 
 tableExists ( $tableName)
 
 updateRowExists ( $key)
 Helper function: check if the given key is present in the updatelog table. More...
 

Static Public Member Functions

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

Public Attributes

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. More...
 
 addIndex ( $table, $index, $patch, $fullpath=false)
 Add a new index to an existing table. More...
 
 addIndexIfNoneExist ( $table, $indexes, $patch, $fullpath=false)
 Add a new index to an existing table if none of the given indexes exist. More...
 
 addTable ( $name, $patch, $fullpath=false)
 Add a new table to the database. More...
 
 appendLine ( $line)
 Append a line to the open filehandle. More...
 
 applyPatch ( $path, $isFullPath=false, $msg=null)
 Applies a SQL patch. More...
 
 canUseNewUpdatelog ()
 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). More...
 
 checkStats ()
 Check the site_stats table is not properly populated. More...
 
 copyFile ( $filename)
 Append an SQL fragment to the open file handle. More...
 
 doActiveUsersInit ()
 Sets the number of active users in the site_stats table. More...
 
 doCollationUpdate ()
 Update CategoryLinks collation. More...
 
 doLogSearchPopulation ()
 Migrate log params to new table and index for searching. More...
 
 doLogUsertextPopulation ()
 Populates the log_user_text field in the logging table. More...
 
 doMigrateUserOptions ()
 Migrates user options from the user table blob to user_properties. More...
 
 doTable ( $name)
 Returns whether updates should be executed on the database table $name. More...
 
 dropField ( $table, $field, $patch, $fullpath=false)
 Drop a field from an existing table. More...
 
 dropIndex ( $table, $index, $patch, $fullpath=false)
 Drop an index from an existing table. More...
 
 dropTable ( $table, $patch=false, $fullpath=false)
 If the specified table exists, drop it, or execute the patch if one is provided. More...
 
 getCoreUpdateList ()
 Get an array of updates to perform on the database. More...
 
 getExtensionUpdates ()
 Get the list of extension-defined updates. More...
 
 getOldGlobalUpdates ()
 Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes. More...
 
 ifFieldExists ( $table, $field, $func,... $params)
 Only run a function if the named field exists. More...
 
 ifNoActorTable ( $func,... $params)
 
 ifTableNotExists ( $table, $func,... $params)
 Only run a function if a table does not exist. More...
 
 migrateActors ()
 Migrate actors to the new 'actor' table. More...
 
 migrateArchiveText ()
 Migrate ar_text to modern storage. More...
 
 migrateComments ()
 Migrate comments to the new 'comment' table. More...
 
 migrateImageCommentTemp ()
 Merge image_comment_temp into the image table. More...
 
 modifyField ( $table, $field, $patch, $fullpath=false)
 Modify an existing field. More...
 
 modifyTable ( $table, $patch, $fullpath=false)
 Modify an existing table, similar to modifyField. More...
 
 populateArchiveRevId ()
 Populate ar_rev_id, then make it not nullable. More...
 
 populateContentTables ()
 Populates the MCR content tables. More...
 
 populateExternallinksIndex60 ()
 Populates the externallinks.el_index_60 field. More...
 
 rebuildLocalisationCache ()
 Rebuilds the localisation cache. More...
 
 renameIndex ( $table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath=false)
 Rename an index from an existing table. More...
 
 runMaintenance ( $class, $script)
 Run a maintenance script. More...
 

Protected Attributes

IMaintainableDatabase $db
 Handle to the database subclass. More...
 
array $extensionUpdates = []
 List of extension-provided database updates. More...
 
resource $fileHandle = null
 File handle for SQL output. More...
 
Maintenance $maintenance
 
string[] $postDatabaseUpdateMaintenance
 Scripts to run after database update Should be a subclass of LoggedUpdateMaintenance. More...
 
 $shared = false
 
bool $skipSchema = false
 Flag specifying whether or not to skip schema (e.g. More...
 
array $updates = []
 Array of updates to perform on the database. More...
 
array $updatesSkipped = []
 Array of updates that were skipped. More...
 

Private Member Functions

 initOldGlobals ()
 Initialize all of the old globals. More...
 
 loadExtensions ()
 Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates hook. More...
 
 loadExtensionSchemaUpdates ()
 Cause extensions to register any updates they need to perform. More...
 
 runUpdates (array $updates, $passSelf)
 Helper function for doUpdates() More...
 
 writeSchemaUpdateFile (array $schemaUpdate=[])
 

Detailed Description

Class for handling database updates.

Roughly based off of updaters.inc, with a few improvements :)

Since
1.17

Definition at line 37 of file DatabaseUpdater.php.

Constructor & Destructor Documentation

◆ __construct()

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 113 of file DatabaseUpdater.php.

References $db, $maintenance, $shared, DBO_DDLMODE, Maintenance\setDB(), and Wikimedia\Rdbms\IDatabase\setFlag().

Member Function Documentation

◆ addExtensionField()

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 289 of file DatabaseUpdater.php.

References true.

◆ addExtensionIndex()

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 275 of file DatabaseUpdater.php.

References true.

◆ addExtensionTable()

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 261 of file DatabaseUpdater.php.

References true.

◆ addExtensionUpdate()

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 (ie. 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 247 of file DatabaseUpdater.php.

◆ addField()

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 788 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ addIndex()

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 816 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ addIndexIfNoneExist()

DatabaseUpdater::addIndexIfNoneExist (   $table,
  $indexes,
  $patch,
  $fullpath = false 
)
protected

Add a new index to an existing table if none of the given indexes exist.

Parameters
string$tableName of the table to modify
string[]$indexesName of the indexes to check. $indexes[0] should be the one actually being added.
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 842 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ addPostDatabaseUpdateMaintenance()

DatabaseUpdater::addPostDatabaseUpdateMaintenance (   $class)

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

Script should subclass LoggedUpdateMaintenance

Since
1.19
Parameters
string$className of a Maintenance subclass

Definition at line 407 of file DatabaseUpdater.php.

◆ addTable()

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 762 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ appendLine()

DatabaseUpdater::appendLine (   $line)
protected

Append a line to the open filehandle.

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
Exceptions
MWException

Definition at line 686 of file DatabaseUpdater.php.

References $line.

◆ applyPatch()

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 patch is skipped.

Definition at line 706 of file DatabaseUpdater.php.

References $path, copyFile(), output(), and patchPath().

Referenced by addField(), addIndex(), addIndexIfNoneExist(), PostgresUpdater\addInterwikiType(), PostgresUpdater\addPgExtIndex(), addTable(), MysqlUpdater\checkBin(), PostgresUpdater\checkIwlPrefix(), PostgresUpdater\checkPageDeletedTrigger(), PostgresUpdater\checkRevUserFkey(), PostgresUpdater\convertArchive2(), MysqlUpdater\doBacklinkingIndicesUpdate(), MysqlUpdater\doCategorylinksIndicesUpdate(), MysqlUpdater\doClFieldsUpdate(), MysqlUpdater\doExtendCommentLengths(), MysqlUpdater\doFilearchiveIndicesUpdate(), MysqlUpdater\doFixAncientImagelinks(), SqliteUpdater\doFixIpbAddressUniqueIndex(), MysqlUpdater\doFixIpbAddressUniqueIndex(), MysqlUpdater\doIndexUpdate(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doIwlinksIndexNonUnique(), MysqlUpdater\doLanguageLinksLengthSync(), MysqlUpdater\doNonUniquePlTlIl(), MysqlUpdater\doPagelinksUpdate(), MysqlUpdater\doRestrictionsUpdate(), MysqlUpdater\doRevisionPageRevIndexNonUnique(), MysqlUpdater\doTemplatelinksUpdate(), MysqlUpdater\doUnsignedSyncronisation(), MysqlUpdater\doUpdateMimeMinorField(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), MysqlUpdater\doWatchlistNull(), dropField(), dropIndex(), dropTable(), migrateArchiveText(), modifyField(), modifyTable(), populateArchiveRevId(), PostgresUpdater\rebuildTextSearch(), renameIndex(), PostgresUpdater\renameTable(), SqliteUpdater\sqliteInitialIndexes(), SqliteUpdater\sqliteSetupSearchindex(), and PostgresUpdater\tsearchFixes().

◆ canUseNewUpdatelog()

DatabaseUpdater::canUseNewUpdatelog ( )
protected

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

Returns
bool

Definition at line 573 of file DatabaseUpdater.php.

Referenced by insertUpdateRow().

◆ checkStats()

DatabaseUpdater::checkStats ( )
protected

Check the site_stats table is not properly populated.

Definition at line 1169 of file DatabaseUpdater.php.

References SiteStatsInit\doAllAndCommit(), and output().

Referenced by doUpdates().

◆ copyFile()

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 664 of file DatabaseUpdater.php.

Referenced by applyPatch().

◆ doActiveUsersInit()

DatabaseUpdater::doActiveUsersInit ( )
protected

Sets the number of active users in the site_stats table.

Definition at line 1189 of file DatabaseUpdater.php.

References output().

◆ doCollationUpdate()

DatabaseUpdater::doCollationUpdate ( )
protected

Update CategoryLinks collation.

Definition at line 1240 of file DatabaseUpdater.php.

References $wgCategoryCollation, and output().

◆ doLogSearchPopulation()

DatabaseUpdater::doLogSearchPopulation ( )
protected

Migrate log params to new table and index for searching.

Definition at line 1224 of file DatabaseUpdater.php.

References output(), and updateRowExists().

◆ doLogUsertextPopulation()

DatabaseUpdater::doLogUsertextPopulation ( )
protected

Populates the log_user_text field in the logging table.

Definition at line 1207 of file DatabaseUpdater.php.

References output(), and updateRowExists().

◆ doMigrateUserOptions()

DatabaseUpdater::doMigrateUserOptions ( )
protected

Migrates user options from the user table blob to user_properties.

Definition at line 1265 of file DatabaseUpdater.php.

References output().

◆ doTable()

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 586 of file DatabaseUpdater.php.

References $wgSharedDB, $wgSharedTables, and output().

Referenced by addField(), addIndex(), addIndexIfNoneExist(), addTable(), MysqlUpdater\checkBin(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doRevisionPageRevIndexNonUnique(), MysqlUpdater\doUnsignedSyncronisation(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), dropField(), dropIndex(), dropTable(), SqliteUpdater\indexHasField(), MysqlUpdater\indexHasField(), modifyField(), modifyTable(), and renameIndex().

◆ doUpdates()

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

Do all the updates.

Parameters
array$whatWhat updates to perform

Definition at line 467 of file DatabaseUpdater.php.

References checkStats(), getCoreUpdateList(), getExtensionUpdates(), getOldGlobalUpdates(), getSchemaVars(), loadExtensionSchemaUpdates(), runUpdates(), and writeSchemaUpdateFile().

◆ dropExtensionField()

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 303 of file DatabaseUpdater.php.

References true.

◆ dropExtensionIndex()

DatabaseUpdater::dropExtensionIndex (   $tableName,
  $indexName,
  $sqlPath 
)

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

Since
1.21
Parameters
string$tableNameThe table name
string$indexNameThe index name
string$sqlPathThe path to the SQL change path

Definition at line 317 of file DatabaseUpdater.php.

References true.

◆ dropExtensionTable()

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 330 of file DatabaseUpdater.php.

References true.

◆ dropField()

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 877 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ dropIndex()

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 903 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ dropTable()

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 | bool$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 989 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

Referenced by migrateImageCommentTemp().

◆ getCoreUpdateList()

DatabaseUpdater::getCoreUpdateList ( )
abstractprotected

Get an array of updates to perform on the database.

Should return a multi-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)

Returns
array[]

Reimplemented in PostgresUpdater, MysqlUpdater, and SqliteUpdater.

Referenced by doUpdates().

◆ getDB()

DatabaseUpdater::getDB ( )

Get a database connection to run updates.

Returns
IMaintainableDatabase

Definition at line 213 of file DatabaseUpdater.php.

References $db.

◆ getExtensionUpdates()

DatabaseUpdater::getExtensionUpdates ( )
protected

Get the list of extension-defined updates.

Returns
array

Definition at line 416 of file DatabaseUpdater.php.

References $extensionUpdates.

Referenced by doUpdates().

◆ getOldGlobalUpdates()

DatabaseUpdater::getOldGlobalUpdates ( )
protected

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 a while. So load up these old global-based things into our update list.

Returns
array

Reimplemented in PostgresUpdater.

Definition at line 611 of file DatabaseUpdater.php.

References $updates, and true.

Referenced by doUpdates().

◆ getPostDatabaseUpdateMaintenance()

DatabaseUpdater::getPostDatabaseUpdateMaintenance ( )
Since
1.17
Returns
string[]

Definition at line 425 of file DatabaseUpdater.php.

References $postDatabaseUpdateMaintenance.

◆ getSchemaVars()

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 MysqlUpdater.

Definition at line 458 of file DatabaseUpdater.php.

Referenced by doUpdates().

◆ ifFieldExists()

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 callable.
mixed...$params Parameters for $func
Returns
mixed Whatever $func returns, or null when skipped.

Definition at line 1478 of file DatabaseUpdater.php.

◆ ifNoActorTable()

DatabaseUpdater::ifNoActorTable (   $func,
  $params 
)
protected
Deprecated:
since 1.35, use ifTableNotExists() instead

Definition at line 1423 of file DatabaseUpdater.php.

References ifTableNotExists(), and wfDeprecated().

◆ ifTableNotExists()

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 callable.
mixed...$params Parameters for $func
Returns
mixed Whatever $func returns, or null when skipped.

Definition at line 1441 of file DatabaseUpdater.php.

Referenced by ifNoActorTable().

◆ initOldGlobals()

DatabaseUpdater::initOldGlobals ( )
private

Initialize all of the old globals.

One day this should all become something much nicer

Definition at line 143 of file DatabaseUpdater.php.

Referenced by loadExtensionSchemaUpdates().

◆ insertUpdateRow()

DatabaseUpdater::insertUpdateRow (   $key,
  $val = null 
)

Helper function: Add a key to the updatelog table.

Note
Only use this for updates that occur after the updatelog table was created!
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 key to insert
string | null$val[optional] Value to insert along with the key

Definition at line 555 of file DatabaseUpdater.php.

References canUseNewUpdatelog(), and DBO_DDLMODE.

Referenced by modifyField(), modifyTable(), and populateContentTables().

◆ loadExtensions()

DatabaseUpdater::loadExtensions ( )
private

Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates hook.

Definition at line 161 of file DatabaseUpdater.php.

References $queue, $wgAutoloadClasses, $wgHooks, Installer\getExistingLocalSettings(), and ExtensionRegistry\getInstance().

Referenced by loadExtensionSchemaUpdates().

◆ loadExtensionSchemaUpdates()

DatabaseUpdater::loadExtensionSchemaUpdates ( )
private

Cause extensions to register any updates they need to perform.

Definition at line 133 of file DatabaseUpdater.php.

References initOldGlobals(), loadExtensions(), and Hooks\runner().

Referenced by doUpdates().

◆ migrateActors()

DatabaseUpdater::migrateActors ( )
protected

Migrate actors to the new 'actor' table.

Since
1.31

Definition at line 1331 of file DatabaseUpdater.php.

References output(), and updateRowExists().

◆ migrateArchiveText()

DatabaseUpdater::migrateArchiveText ( )
protected

Migrate ar_text to modern storage.

Since
1.31

Definition at line 1348 of file DatabaseUpdater.php.

References applyPatch(), and output().

◆ migrateComments()

DatabaseUpdater::migrateComments ( )
protected

Migrate comments to the new 'comment' table.

Since
1.30

Definition at line 1294 of file DatabaseUpdater.php.

References output(), and updateRowExists().

◆ migrateImageCommentTemp()

DatabaseUpdater::migrateImageCommentTemp ( )
protected

Merge image_comment_temp into the image table.

Since
1.32

Definition at line 1311 of file DatabaseUpdater.php.

References dropTable(), output(), and tableExists().

◆ modifyExtensionField()

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$tableNameThe table name
string$fieldNameThe field to be modified
string$sqlPathThe path to the SQL patch

Definition at line 371 of file DatabaseUpdater.php.

References true.

◆ modifyExtensionTable()

DatabaseUpdater::modifyExtensionTable (   $tableName,
  $sqlPath 
)

Modify an existing extension table.

Intended for use in LoadExtensionSchemaUpdates hook handlers.

Since
1.31
Parameters
string$tableNameThe table name
string$sqlPathThe path to the SQL patch

Definition at line 384 of file DatabaseUpdater.php.

References true.

◆ modifyField()

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 1025 of file DatabaseUpdater.php.

References applyPatch(), doTable(), insertUpdateRow(), output(), and updateRowExists().

◆ modifyTable()

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 1062 of file DatabaseUpdater.php.

References applyPatch(), doTable(), insertUpdateRow(), output(), and updateRowExists().

◆ newForDB()

static DatabaseUpdater::newForDB ( IMaintainableDatabase  $db,
  $shared = false,
Maintenance  $maintenance = null 
)
static
Parameters
IMaintainableDatabase$db
bool$shared
Maintenance | null$maintenance
Exceptions
MWException
Returns
DatabaseUpdater

Definition at line 193 of file DatabaseUpdater.php.

References $db, $maintenance, $shared, $type, and Wikimedia\Rdbms\IDatabase\getType().

Referenced by DatabaseInstaller\createExtensionTables(), DatabaseInstaller\doUpgrade(), PatchSql\execute(), MwSql\execute(), and UpdateMediaWiki\execute().

◆ output()

DatabaseUpdater::output (   $str)

Output some text.

If we're running from web, escape the text first.

Parameters
string$strText to output
-taint$strescapes_html

Definition at line 223 of file DatabaseUpdater.php.

References $wgCommandLineMode.

Referenced by addField(), addIndex(), addIndexIfNoneExist(), PostgresUpdater\addPgEnumValue(), PostgresUpdater\addPgExtIndex(), PostgresUpdater\addPgField(), PostgresUpdater\addPgIndex(), PostgresUpdater\addSequence(), addTable(), applyPatch(), PostgresUpdater\changeField(), PostgresUpdater\changeFieldPurgeTable(), PostgresUpdater\changeFkeyDeferrable(), PostgresUpdater\changeNullableField(), MysqlUpdater\checkBin(), PostgresUpdater\checkIndex(), PostgresUpdater\checkOiDeleted(), PostgresUpdater\checkOiNameConstraint(), PostgresUpdater\checkPageDeletedTrigger(), PostgresUpdater\checkRevUserFkey(), checkStats(), PostgresUpdater\convertArchive2(), doActiveUsersInit(), MysqlUpdater\doCategoryPopulation(), MysqlUpdater\doClFieldsUpdate(), doCollationUpdate(), MysqlUpdater\doExtendCommentLengths(), MysqlUpdater\doFixAncientImagelinks(), SqliteUpdater\doFixIpbAddressUniqueIndex(), MysqlUpdater\doFixIpbAddressUniqueIndex(), MysqlUpdater\doIndexUpdate(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doIwlinksIndexNonUnique(), MysqlUpdater\doLanguageLinksLengthSync(), doLogSearchPopulation(), doLogUsertextPopulation(), doMigrateUserOptions(), MysqlUpdater\doNamespaceSize(), MysqlUpdater\doNonUniquePlTlIl(), MysqlUpdater\doPagelinksUpdate(), MysqlUpdater\doPageRandomUpdate(), MysqlUpdater\doPopulateParentId(), MysqlUpdater\doRestrictionsUpdate(), MysqlUpdater\doRevisionPageRevIndexNonUnique(), MysqlUpdater\doSchemaRestructuring(), doTable(), MysqlUpdater\doTemplatelinksUpdate(), MysqlUpdater\doUnsignedSyncronisation(), MysqlUpdater\doUpdateMimeMinorField(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), MysqlUpdater\doWatchlistNull(), MysqlUpdater\doWatchlistUpdate(), PostgresUpdater\dropDefault(), dropField(), PostgresUpdater\dropFkey(), dropIndex(), PostgresUpdater\dropPgField(), PostgresUpdater\dropPgIndex(), PostgresUpdater\dropSequence(), dropTable(), SqliteUpdater\indexHasField(), MysqlUpdater\indexHasField(), migrateActors(), migrateArchiveText(), migrateComments(), migrateImageCommentTemp(), modifyField(), modifyTable(), populateArchiveRevId(), populateContentTables(), populateExternallinksIndex60(), purgeCache(), rebuildLocalisationCache(), PostgresUpdater\rebuildTextSearch(), PostgresUpdater\renameIndex(), renameIndex(), PostgresUpdater\renameSequence(), PostgresUpdater\renameTable(), runMaintenance(), PostgresUpdater\setDefault(), setFileAccess(), PostgresUpdater\setSequenceOwner(), SqliteUpdater\sqliteInitialIndexes(), and SqliteUpdater\sqliteSetupSearchindex().

◆ patchPath()

DatabaseUpdater::patchPath ( IDatabase  $db,
  $patch 
)

Get the full path of a patch file.

Originally based on archive() from updaters.inc. Keep in mind this always returns a patch, as it fails back to MySQL if no DB-specific patch can be found

Parameters
IDatabase$db
string$patchThe name of the patch, like patch-something.sql
Returns
string Full path to patch file

Definition at line 740 of file DatabaseUpdater.php.

References $db, $IP, and Wikimedia\Rdbms\IDatabase\getType().

Referenced by applyPatch().

◆ populateArchiveRevId()

DatabaseUpdater::populateArchiveRevId ( )
protected

Populate ar_rev_id, then make it not nullable.

Since
1.31

Definition at line 1365 of file DatabaseUpdater.php.

References applyPatch(), and output().

◆ populateContentTables()

DatabaseUpdater::populateContentTables ( )
protected

Populates the MCR content tables.

Since
1.32

Definition at line 1402 of file DatabaseUpdater.php.

References insertUpdateRow(), output(), and updateRowExists().

◆ populateExternallinksIndex60()

DatabaseUpdater::populateExternallinksIndex60 ( )
protected

Populates the externallinks.el_index_60 field.

Since
1.32

Definition at line 1384 of file DatabaseUpdater.php.

References output(), and updateRowExists().

◆ purgeCache()

DatabaseUpdater::purgeCache ( )

Purge various database caches.

Definition at line 1138 of file DatabaseUpdater.php.

References $wgLocalisationCacheConf, output(), and rebuildLocalisationCache().

◆ rebuildLocalisationCache()

DatabaseUpdater::rebuildLocalisationCache ( )
protected

Rebuilds the localisation cache.

Definition at line 1276 of file DatabaseUpdater.php.

References output().

Referenced by purgeCache().

◆ renameExtensionIndex()

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$tableNameThe table name
string$oldIndexNameThe old index name
string$newIndexNameThe new index name
string$sqlPathThe path to the SQL change path
bool$skipBothIndexExistWarningWhether to warn if both the old and the new indexes exist. [facultative; by default, false]

Definition at line 347 of file DatabaseUpdater.php.

References true.

◆ renameIndex()

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 the 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 PostgresUpdater.

Definition at line 932 of file DatabaseUpdater.php.

References applyPatch(), doTable(), and output().

◆ runMaintenance()

DatabaseUpdater::runMaintenance (   $class,
  $script 
)
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
string$classMaintenance subclass
string$scriptScript path and filename, usually "maintenance/fooBar.php"

Definition at line 1102 of file DatabaseUpdater.php.

References output().

◆ runUpdates()

DatabaseUpdater::runUpdates ( array  $updates,
  $passSelf 
)
private

Helper function for doUpdates()

Parameters
array$updatesArray of updates to run
bool$passSelfWhether to pass this object we calling external functions

Definition at line 497 of file DatabaseUpdater.php.

References $updates, and $updatesSkipped.

Referenced by doUpdates().

◆ setFileAccess()

DatabaseUpdater::setFileAccess ( )

Set any .htaccess files or equivilent for storage repos.

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

Definition at line 1117 of file DatabaseUpdater.php.

References output().

◆ tableExists()

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

Definition at line 394 of file DatabaseUpdater.php.

Referenced by migrateImageCommentTemp().

◆ updateRowExists()

DatabaseUpdater::updateRowExists (   $key)

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!

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

Definition at line 530 of file DatabaseUpdater.php.

Referenced by MysqlUpdater\doCategoryPopulation(), MysqlUpdater\doClFieldsUpdate(), doLogSearchPopulation(), doLogUsertextPopulation(), MysqlUpdater\doPopulateParentId(), MysqlUpdater\doUpdateMimeMinorField(), migrateActors(), migrateComments(), modifyField(), modifyTable(), populateContentTables(), populateExternallinksIndex60(), PostgresUpdater\rebuildTextSearch(), SqliteUpdater\sqliteInitialIndexes(), and SqliteUpdater\sqliteSetupSearchindex().

◆ writeSchemaUpdateFile()

DatabaseUpdater::writeSchemaUpdateFile ( array  $schemaUpdate = [])
private
Since
1.21

Writes the schema updates desired to a file for the DB Admin to run.

Parameters
array$schemaUpdate

Definition at line 435 of file DatabaseUpdater.php.

References $args, $updates, and $updatesSkipped.

Referenced by doUpdates().

Member Data Documentation

◆ $db

IMaintainableDatabase DatabaseUpdater::$db
protected

Handle to the database subclass.

Definition at line 65 of file DatabaseUpdater.php.

Referenced by __construct(), getDB(), newForDB(), and patchPath().

◆ $extensionUpdates

array DatabaseUpdater::$extensionUpdates = []
protected

List of extension-provided database updates.

Definition at line 58 of file DatabaseUpdater.php.

Referenced by getExtensionUpdates().

◆ $fileHandle

resource DatabaseUpdater::$fileHandle = null
protected

File handle for SQL output.

Definition at line 99 of file DatabaseUpdater.php.

◆ $maintenance

Maintenance DatabaseUpdater::$maintenance
protected

Definition at line 70 of file DatabaseUpdater.php.

Referenced by __construct(), and newForDB().

◆ $postDatabaseUpdateMaintenance

string [] DatabaseUpdater::$postDatabaseUpdateMaintenance
protected
Initial value:
= [
DeleteDefaultMessages::class,
PopulateRevisionLength::class,
PopulateRevisionSha1::class,
PopulateImageSha1::class,
FixExtLinksProtocolRelative::class,
PopulateFilearchiveSha1::class,
PopulateBacklinkNamespace::class,
FixDefaultJsonContentPages::class,
CleanupEmptyCategories::class,
AddRFCandPMIDInterwiki::class,
PopulatePPSortKey::class,
PopulateIpChanges::class,
RefreshExternallinksIndex::class,
]

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

Definition at line 78 of file DatabaseUpdater.php.

Referenced by getPostDatabaseUpdateMaintenance().

◆ $shared

DatabaseUpdater::$shared = false
protected

Definition at line 72 of file DatabaseUpdater.php.

Referenced by __construct(), and newForDB().

◆ $skipSchema

bool DatabaseUpdater::$skipSchema = false
protected

Flag specifying whether or not to skip schema (e.g.

SQL-only) updates.

Definition at line 106 of file DatabaseUpdater.php.

◆ $updates

array DatabaseUpdater::$updates = []
protected

Array of updates to perform on the database.

Definition at line 45 of file DatabaseUpdater.php.

Referenced by getOldGlobalUpdates(), PostgresUpdater\getOldGlobalUpdates(), runUpdates(), and writeSchemaUpdateFile().

◆ $updatesSkipped

array DatabaseUpdater::$updatesSkipped = []
protected

Array of updates that were skipped.

Definition at line 52 of file DatabaseUpdater.php.

Referenced by runUpdates(), and writeSchemaUpdateFile().

◆ REPLICATION_WAIT_TIMEOUT

const DatabaseUpdater::REPLICATION_WAIT_TIMEOUT = 300

Definition at line 38 of file DatabaseUpdater.php.

Referenced by MysqlUpdater\doTemplatelinksUpdate().


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