MediaWiki  REL1_24
DatabaseUpdater Class Reference

Class for handling database updates. More...

Inheritance diagram for DatabaseUpdater:
Collaboration diagram for DatabaseUpdater:

List of all members.

Public Member Functions

 addExtensionField ($tableName, $columnName, $sqlPath)
 addExtensionIndex ($tableName, $indexName, $sqlPath)
 addExtensionTable ($tableName, $sqlPath)
 Convenience wrapper for addExtensionUpdate() when adding a new table (which is the most common usage of updaters in an extension)
 addExtensionUpdate (array $update)
 Add a new update coming from an extension.
 addPostDatabaseUpdateMaintenance ($class)
 Add a maintenance script to be run after the database updates are complete.
 appendLine ($line)
 Append a line to the open filehandle.
 copyFile ($filename)
 Append an SQL fragment to the open file handle.
 doUpdates ($what=array( 'core', 'extensions', 'stats'))
 Do all the updates.
 dropExtensionField ($tableName, $columnName, $sqlPath)
 dropExtensionIndex ($tableName, $indexName, $sqlPath)
 Drop an index from an extension table.
 dropExtensionTable ($tableName, $sqlPath)
 dropTable ($table, $patch=false, $fullpath=false)
 If the specified table exists, drop it, or execute the patch if one is provided.
 getDB ()
 Get a database connection to run updates.
 getPostDatabaseUpdateMaintenance ()
 insertUpdateRow ($key, $val=null)
 Helper function: Add a key to the updatelog table Obviously, only use this for updates that occur after the updatelog table was created!
 modifyExtensionField ($tableName, $fieldName, $sqlPath)
 modifyField ($table, $field, $patch, $fullpath=false)
 Modify an existing field.
 output ($str)
 Output some text.
 purgeCache ()
 Purge the objectcache table.
 renameExtensionIndex ($tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning=false)
 Rename an index on an extension table.
 tableExists ($tableName)
 updateRowExists ($key)
 Helper function: check if the given key is present in the updatelog table.

Static Public Member Functions

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

Protected Member Functions

 __construct (DatabaseBase &$db, $shared, Maintenance $maintenance=null)
 Constructor.
 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.
 addTable ($name, $patch, $fullpath=false)
 Add a new table to the database.
 applyPatch ($path, $isFullPath=false, $msg=null)
 Applies a SQL patch.
 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).
 checkStats ()
 Check the site_stats table is not properly populated.
 disableContentHandlerUseDB ()
 Turns off content handler fields during parts of the upgrade where they aren't available.
 doActiveUsersInit ()
 Sets the number of active users in the site_stats table.
 doCollationUpdate ()
 Update CategoryLinks collation.
 doLogSearchPopulation ()
 Migrate log params to new table and index for searching.
 doLogUsertextPopulation ()
 Populates the log_user_text field in the logging table.
 doMigrateUserOptions ()
 Migrates user options from the user table blob to user_properties.
 doTable ($name)
 Returns whether updates should be executed on the database table $name.
 doUpdateTranscacheField ()
 Updates the timestamps in the transcache table.
 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.
 enableContentHandlerUseDB ()
 Turns content handler fields back on.
 getCoreUpdateList ()
 Get an array of updates to perform on the database.
 getExtensionUpdates ()
 Get the list of extension-defined updates.
 getOldGlobalUpdates ()
 Before 1.17, we used to handle updates via stuff like $wgExtNewTables/Fields/Indexes.
 rebuildLocalisationCache ()
 Rebuilds the localisation cache.
 renameIndex ($table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath=false)
 Rename an index from an existing table.
 setAppliedUpdates ($version, $updates=array())

Protected Attributes

DatabaseBase $db
 Handle to the database subclass.
array $extensionUpdates = array()
 List of extension-provided database updates.
resource $fileHandle = null
 File handle for SQL output.
 $holdContentHandlerUseDB = true
 Hold the value of $wgContentHandlerUseDB during the upgrade.
 $postDatabaseUpdateMaintenance
 Scripts to run after database update Should be a subclass of LoggedUpdateMaintenance.
 $shared = false
bool $skipSchema = false
 Flag specifying whether or not to skip schema (e.g.
array $updates = array()
 Array of updates to perform on the database.
array $updatesSkipped = array()
 Array of updates that were skipped.

Private Member Functions

 initOldGlobals ()
 Initialize all of the old globals.
 loadExtensions ()
 Loads LocalSettings.php, if needed, and initialises everything needed for LoadExtensionSchemaUpdates hook.
 runUpdates (array $updates, $passSelf)
 Helper function for doUpdates()
 writeSchemaUpdateFile ($schemaUpdate=array())

Detailed Description

Class for handling database updates.

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

Since:
1.17

Definition at line 33 of file DatabaseUpdater.php.


Constructor & Destructor Documentation

DatabaseUpdater::__construct ( DatabaseBase &$  db,
shared,
Maintenance maintenance = null 
) [protected]

Constructor.

Parameters:
DatabaseBase$dbTo perform updates on
bool$sharedWhether to perform updates on shared tables
Maintenance$maintenanceMaintenance object which created us

Definition at line 98 of file DatabaseUpdater.php.


Member Function Documentation

DatabaseUpdater::addExtensionField ( tableName,
columnName,
sqlPath 
)
Since:
1.19
Parameters:
string$tableName
string$columnName
string$sqlPath

Definition at line 246 of file DatabaseUpdater.php.

DatabaseUpdater::addExtensionIndex ( tableName,
indexName,
sqlPath 
)
Since:
1.19
Parameters:
string$tableName
string$indexName
string$sqlPath

Definition at line 234 of file DatabaseUpdater.php.

DatabaseUpdater::addExtensionTable ( tableName,
sqlPath 
)

Convenience wrapper for addExtensionUpdate() when adding a new table (which is the most common usage of updaters in an extension)

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

Definition at line 223 of file DatabaseUpdater.php.

Add a new update coming from an extension.

This should be called by extensions while executing the LoadExtensionSchemaUpdates hook.

Since:
1.17
Parameters:
array$updateThe 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 receive this object as first parameter.

Definition at line 210 of file DatabaseUpdater.php.

DatabaseUpdater::addField ( table,
field,
patch,
fullpath = false 
) [protected]

Add a new field to an existing table.

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

DatabaseUpdater::addIndex ( table,
index,
patch,
fullpath = false 
) [protected]

Add a new index to an existing table.

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

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

DatabaseUpdater::addTable ( name,
patch,
fullpath = false 
) [protected]

Add a new table to the database.

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

Append a line to the open filehandle.

The line is assumed to be a complete SQL statement.

This is used as a callback for for sourceLine().

Parameters:
string$lineText to append to the file
Returns:
bool False to skip actually executing the file
Exceptions:
MWException

Definition at line 613 of file DatabaseUpdater.php.

DatabaseUpdater::applyPatch ( path,
isFullPath = false,
msg = null 
) [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 508 of file DatabaseUpdater.php.

DatabaseUpdater::checkStats ( ) [protected]

Check the site_stats table is not properly populated.

Definition at line 911 of file DatabaseUpdater.php.

Referenced by doUpdates().

DatabaseUpdater::copyFile ( filename)

Append an SQL fragment to the open file handle.

Parameters:
string$filenameFile name to open

Definition at line 597 of file DatabaseUpdater.php.

References array().

Turns off content handler fields during parts of the upgrade where they aren't available.

Definition at line 1048 of file DatabaseUpdater.php.

Sets the number of active users in the site_stats table.

Definition at line 931 of file DatabaseUpdater.php.

References array().

Update CategoryLinks collation.

Definition at line 997 of file DatabaseUpdater.php.

Migrate log params to new table and index for searching.

Definition at line 966 of file DatabaseUpdater.php.

Populates the log_user_text field in the logging table.

Definition at line 949 of file DatabaseUpdater.php.

Migrates user options from the user table blob to user_properties.

Definition at line 1022 of file DatabaseUpdater.php.

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

Referenced by MysqlUpdater\checkBin(), MysqlUpdater\doEnableProfiling(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doMaybeProfilingMemoryUpdate(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), and MysqlUpdater\indexHasField().

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

Do all the updates.

Parameters:
array$whatWhat updates to perform

Reimplemented in OracleUpdater.

Definition at line 390 of file DatabaseUpdater.php.

References checkStats(), getCoreUpdateList(), getExtensionUpdates(), getOldGlobalUpdates(), global, runUpdates(), setAppliedUpdates(), updates(), and writeSchemaUpdateFile().

Updates the timestamps in the transcache table.

Returns:
bool

Definition at line 983 of file DatabaseUpdater.php.

DatabaseUpdater::dropExtensionField ( tableName,
columnName,
sqlPath 
)
Since:
1.20
Parameters:
string$tableName
string$columnName
string$sqlPath

Definition at line 258 of file DatabaseUpdater.php.

DatabaseUpdater::dropExtensionIndex ( tableName,
indexName,
sqlPath 
)

Drop an index from an extension table.

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

Definition at line 271 of file DatabaseUpdater.php.

DatabaseUpdater::dropExtensionTable ( tableName,
sqlPath 
)
Since:
1.20
Parameters:
string$tableName
string$sqlPath

Definition at line 282 of file DatabaseUpdater.php.

DatabaseUpdater::dropField ( table,
field,
patch,
fullpath = false 
) [protected]

Drop a field from an existing table.

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

DatabaseUpdater::dropIndex ( table,
index,
patch,
fullpath = false 
) [protected]

Drop an index from an existing table.

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

Reimplemented in PostgresUpdater.

Definition at line 759 of file DatabaseUpdater.php.

DatabaseUpdater::dropTable ( table,
patch = false,
fullpath = false 
)

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

Public

Since:
1.20
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 839 of file DatabaseUpdater.php.

Turns content handler fields back on.

Definition at line 1061 of file DatabaseUpdater.php.

DatabaseUpdater::getCoreUpdateList ( ) [abstract, protected]

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, OracleUpdater, MssqlUpdater, SqliteUpdater, and MysqlUpdater.

Referenced by doUpdates().

Get a database connection to run updates.

Returns:
DatabaseBase

Definition at line 176 of file DatabaseUpdater.php.

Get the list of extension-defined updates.

Returns:
array

Definition at line 352 of file DatabaseUpdater.php.

Referenced by doUpdates().

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

Referenced by doUpdates().

Since:
1.17
Returns:
array

Definition at line 361 of file DatabaseUpdater.php.

Initialize all of the old globals.

One day this should all become something much nicer

Definition at line 118 of file DatabaseUpdater.php.

DatabaseUpdater::insertUpdateRow ( key,
val = null 
)

Helper function: Add a key to the updatelog table Obviously, only use this for updates that occur after the updatelog table was created!

Parameters:
string$keyName of key to insert
string$val[optional] Value to insert along with the key

Definition at line 490 of file DatabaseUpdater.php.

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

Definition at line 136 of file DatabaseUpdater.php.

DatabaseUpdater::modifyExtensionField ( tableName,
fieldName,
sqlPath 
)
Since:
1.21
Parameters:
string$tableNameThe table name
string$fieldNameThe field to be modified
string$sqlPathThe path to the SQL change path

Definition at line 319 of file DatabaseUpdater.php.

DatabaseUpdater::modifyField ( table,
field,
patch,
fullpath = false 
)

Modify an existing field.

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

static DatabaseUpdater::newForDB ( &$  db,
shared = false,
maintenance = null 
) [static]
Parameters:
DatabaseBase$db
bool$shared
Maintenance$maintenance
Exceptions:
MWException
Returns:
DatabaseUpdater

Definition at line 160 of file DatabaseUpdater.php.

Referenced by DatabaseSqliteTest\prepareDB().

Output some text.

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

Parameters:
string$strText to output

Definition at line 185 of file DatabaseUpdater.php.

References $wgCommandLineMode, and global.

Referenced by PostgresUpdater\addPgExtIndex(), PostgresUpdater\addPgField(), PostgresUpdater\addPgIndex(), PostgresUpdater\addSequence(), PostgresUpdater\changeField(), PostgresUpdater\changeFieldPurgeTable(), PostgresUpdater\changeFkeyDeferrable(), PostgresUpdater\changeNullableField(), MysqlUpdater\checkBin(), PostgresUpdater\checkIndex(), PostgresUpdater\checkOiDeleted(), PostgresUpdater\checkOiNameConstraint(), PostgresUpdater\checkPageDeletedTrigger(), PostgresUpdater\checkRevUserFkey(), PostgresUpdater\convertArchive2(), MysqlUpdater\doCategoryPopulation(), MysqlUpdater\doClFieldsUpdate(), MysqlUpdater\doFixAncientImagelinks(), MysqlUpdater\doIndexUpdate(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doIwlinksIndexNonUnique(), MysqlUpdater\doLangLinksLengthUpdate(), MysqlUpdater\doMaybeProfilingMemoryUpdate(), MysqlUpdater\doNamespaceSize(), MysqlUpdater\doPagelinksUpdate(), MysqlUpdater\doPageRandomUpdate(), MysqlUpdater\doPopulateParentId(), MysqlUpdater\doRestrictionsUpdate(), MysqlUpdater\doSchemaRestructuring(), MysqlUpdater\doTemplatelinksUpdate(), MysqlUpdater\doUniquePlTlIl(), MysqlUpdater\doUpdateMimeMinorField(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), MysqlUpdater\doWatchlistNull(), MysqlUpdater\doWatchlistUpdate(), PostgresUpdater\dropIndex(), MysqlUpdater\indexHasField(), PostgresUpdater\renameIndex(), PostgresUpdater\renameSequence(), PostgresUpdater\renameTable(), PostgresUpdater\setDefault(), SqliteUpdater\sqliteInitialIndexes(), and SqliteUpdater\sqliteSetupSearchindex().

Purge the objectcache table.

Reimplemented in OracleUpdater.

Definition at line 895 of file DatabaseUpdater.php.

Rebuilds the localisation cache.

Definition at line 1033 of file DatabaseUpdater.php.

DatabaseUpdater::renameExtensionIndex ( tableName,
oldIndexName,
newIndexName,
sqlPath,
skipBothIndexExistWarning = false 
)

Rename an index on an extension table.

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

DatabaseUpdater::renameIndex ( table,
oldIndex,
newIndex,
skipBothIndexExistWarning,
patch,
fullpath = false 
) [protected]

Rename an index from an existing table.

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

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

Referenced by doUpdates().

DatabaseUpdater::setAppliedUpdates ( version,
updates = array() 
) [protected]
Parameters:
string$version
array$updates

Definition at line 452 of file DatabaseUpdater.php.

Referenced by doUpdates().

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

Definition at line 330 of file DatabaseUpdater.php.

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

Referenced by MysqlUpdater\doCategoryPopulation(), MysqlUpdater\doClFieldsUpdate(), MysqlUpdater\doPopulateParentId(), MysqlUpdater\doUpdateMimeMinorField(), SqliteUpdater\sqliteInitialIndexes(), and SqliteUpdater\sqliteSetupSearchindex().

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

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

Parameters:
array$schemaUpdate

Definition at line 371 of file DatabaseUpdater.php.

Referenced by doUpdates().


Member Data Documentation

DatabaseBase DatabaseUpdater::$db [protected]

Handle to the database subclass.

Reimplemented in OracleUpdater, MssqlUpdater, and PostgresUpdater.

Definition at line 56 of file DatabaseUpdater.php.

array DatabaseUpdater::$extensionUpdates = array() [protected]

List of extension-provided database updates.

Definition at line 50 of file DatabaseUpdater.php.

resource DatabaseUpdater::$fileHandle = null [protected]

File handle for SQL output.

Definition at line 78 of file DatabaseUpdater.php.

DatabaseUpdater::$holdContentHandlerUseDB = true [protected]

Hold the value of $wgContentHandlerUseDB during the upgrade.

Definition at line 89 of file DatabaseUpdater.php.

DatabaseUpdater::$postDatabaseUpdateMaintenance [protected]
Initial value:
 array(
        'DeleteDefaultMessages',
        'PopulateRevisionLength',
        'PopulateRevisionSha1',
        'PopulateImageSha1',
        'FixExtLinksProtocolRelative',
        'PopulateFilearchiveSha1',
        'PopulateBacklinkNamespace'
    )

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

Definition at line 64 of file DatabaseUpdater.php.

DatabaseUpdater::$shared = false [protected]

Definition at line 58 of file DatabaseUpdater.php.

bool DatabaseUpdater::$skipSchema = false [protected]

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

SQL-only) updates.

Definition at line 84 of file DatabaseUpdater.php.

array DatabaseUpdater::$updates = array() [protected]

Array of updates to perform on the database.

Definition at line 39 of file DatabaseUpdater.php.

Referenced by PostgresUpdater\getOldGlobalUpdates().

array DatabaseUpdater::$updatesSkipped = array() [protected]

Array of updates that were skipped.

Definition at line 45 of file DatabaseUpdater.php.


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