MediaWiki  REL1_19
DatabaseUpdater Class Reference

Class for handling database updates. More...

Inheritance 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.
 doUpdates ($what=array( 'core', 'extensions', 'purge', 'stats'))
 Do all the updates.
 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!
 modifyField ($table, $field, $patch, $fullpath=false)
 Modify an existing field.
 output ($str)
 Output some text.
 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)
 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.
 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.
 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.
 dropTable ($table, $patch, $fullpath=false)
 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.
 purgeCache ()
 Purge the objectcache table.
 rebuildLocalisationCache ()
 Rebuilds the localisation cache.
 setAppliedUpdates ($version, $updates=array())

Protected Attributes

 $db
 $extensionUpdates = array()
 $postDatabaseUpdateMaintenance
 $shared = false
 $updates = array()

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()

Detailed Description

Class for handling database updates.

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

Since:
1.17

Definition at line 18 of file DatabaseUpdater.php.


Constructor & Destructor Documentation

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

Constructor.

Parameters:
$dbDatabaseBase object to perform updates on
$sharedbool Whether to perform updates on shared tables
$maintenanceMaintenance Maintenance object which created us

Definition at line 57 of file DatabaseUpdater.php.

References $db, $maintenance, $shared, initOldGlobals(), loadExtensions(), Maintenance\setDB(), and wfRunHooks().

Here is the call graph for this function:


Member Function Documentation

DatabaseUpdater::addExtensionField ( tableName,
columnName,
sqlPath 
)
Since:
1.19
Parameters:
$tableNamestring
$columnNamestring
$sqlPathstring

Definition at line 201 of file DatabaseUpdater.php.

DatabaseUpdater::addExtensionIndex ( tableName,
indexName,
sqlPath 
)
Since:
1.19
Parameters:
$tableNamestring
$indexNamestring
$sqlPathstring

Definition at line 189 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:
$tableNameString Name of table to create
$sqlPathString Full path to the schema file

Definition at line 178 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:
$updateArray: the 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 165 of file DatabaseUpdater.php.

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

Add a new field to an existing table.

Parameters:
$tableString Name of the table to modify
$fieldString Name of the new field
$patchString Path to the patch file
$fullpathBoolean Whether to treat $patch path as a relative or not

Definition at line 447 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

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

Add a new index to an existing table.

Parameters:
$tableString Name of the table to modify
$indexString Name of the new index
$patchString Path to the patch file
$fullpathBoolean Whether to treat $patch path as a relative or not

Definition at line 466 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

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

Since:
1.19
Parameters:
$classstring Name of a Maintenance subclass

Definition at line 212 of file DatabaseUpdater.php.

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

Add a new table to the database.

Parameters:
$nameString Name of the new table
$patchString Path to the patch file
$fullpathBoolean Whether to treat $patch path as a relative or not

Definition at line 430 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

DatabaseUpdater::applyPatch ( path,
isFullPath = false 
) [protected]

Applies a SQL patch.

Parameters:
$pathString Path to the patch file
$isFullPathBoolean Whether to treat $path as a relative or not

Definition at line 416 of file DatabaseUpdater.php.

References $path.

Referenced by addField(), addIndex(), PostgresUpdater\addPgExtIndex(), addTable(), MysqlUpdater\checkBin(), PostgresUpdater\checkIpbAdress(), PostgresUpdater\checkIwlPrefix(), PostgresUpdater\checkPageDeletedTrigger(), PostgresUpdater\checkRcCurIdNullable(), PostgresUpdater\checkRevUserFkey(), PostgresUpdater\convertArchive2(), MysqlUpdater\doBacklinkingIndicesUpdate(), MysqlUpdater\doCategorylinksIndicesUpdate(), MysqlUpdater\doClFieldsUpdate(), MysqlUpdater\doFilearchiveIndicesUpdate(), MysqlUpdater\doFixAncientImagelinks(), OracleUpdater\doFKRenameDeferr(), OracleUpdater\doFunctions17(), MysqlUpdater\doIndexUpdate(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doLangLinksLengthUpdate(), MysqlUpdater\doMaybeProfilingMemoryUpdate(), OracleUpdater\doNamespaceDefaults(), MysqlUpdater\doPagelinksUpdate(), OracleUpdater\doPageRestrictionsPKUKFix(), OracleUpdater\doRebuildDuplicateFunction(), OracleUpdater\doRecentchangesFK2Cascade(), OracleUpdater\doRemoveNotNullEmptyDefaults(), OracleUpdater\doRemoveNotNullEmptyDefaults2(), MysqlUpdater\doRestrictionsUpdate(), OracleUpdater\doSchemaUpgrade17(), MysqlUpdater\doTemplatelinksUpdate(), MysqlUpdater\doUniquePlTlIl(), MysqlUpdater\doUpdateMimeMinorField(), doUpdateTranscacheField(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), MysqlUpdater\doWatchlistNull(), dropField(), dropIndex(), dropTable(), modifyField(), MysqlUpdater\renameEuWikiId(), SqliteUpdater\sqliteInitialIndexes(), SqliteUpdater\sqliteSetupSearchindex(), and PostgresUpdater\tsearchFixes().

Here is the caller graph for this function:

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:
boolean

Definition at line 346 of file DatabaseUpdater.php.

Referenced by insertUpdateRow(), and setAppliedUpdates().

Here is the caller graph for this function:

DatabaseUpdater::checkStats ( ) [protected]

Check the site_stats table is not properly populated.

Definition at line 565 of file DatabaseUpdater.php.

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

Referenced by doUpdates().

Here is the call graph for this function:

Here is the caller graph for this function:

Sets the number of active users in the site_stats table.

Definition at line 584 of file DatabaseUpdater.php.

References output().

Here is the call graph for this function:

Update CategoryLinks collation.

Definition at line 648 of file DatabaseUpdater.php.

References $wgCategoryCollation, and output().

Here is the call graph for this function:

Migrate log params to new table and index for searching.

Definition at line 618 of file DatabaseUpdater.php.

References output(), and updateRowExists().

Here is the call graph for this function:

Populates the log_user_text field in the logging table.

Definition at line 602 of file DatabaseUpdater.php.

References output(), and updateRowExists().

Here is the call graph for this function:

Migrates user options from the user table blob to user_properties.

Definition at line 669 of file DatabaseUpdater.php.

References output().

Here is the call graph for this function:

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

Do all the updates.

Parameters:
$whatArray: what updates to perform

Reimplemented in OracleUpdater.

Definition at line 239 of file DatabaseUpdater.php.

References $wgLocalisationCacheConf, $wgVersion, checkStats(), getCoreUpdateList(), getExtensionUpdates(), getOldGlobalUpdates(), purgeCache(), rebuildLocalisationCache(), runUpdates(), and setAppliedUpdates().

Here is the call graph for this function:

Updates the timestamps in the transcache table.

Definition at line 634 of file DatabaseUpdater.php.

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

Here is the call graph for this function:

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

Drop a field from an existing table.

Parameters:
$tableString Name of the table to modify
$fieldString Name of the old field
$patchString Path to the patch file
$fullpathBoolean Whether to treat $patch path as a relative or not

Definition at line 484 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

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

Drop an index from an existing table.

Parameters:
$tableString: Name of the table to modify
$indexString: Name of the old index
$patchString: Path to the patch file
$fullpathBoolean: Whether to treat $patch path as a relative or not

Definition at line 502 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

DatabaseUpdater::dropTable ( table,
patch,
fullpath = false 
) [protected]
Parameters:
$tablestring
$patchstring
$fullpathbool

Definition at line 517 of file DatabaseUpdater.php.

References applyPatch(), and output().

Here is the call graph for this function:

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

Referenced by doUpdates().

Here is the caller graph for this function:

Get a database connection to run updates.

Returns:
DatabaseBase

Definition at line 131 of file DatabaseUpdater.php.

Get the list of extension-defined updates.

Returns:
Array

Definition at line 221 of file DatabaseUpdater.php.

Referenced by doUpdates().

Here is the caller graph for this function:

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

References $updates, $wgSharedDB, and $wgSharedTables.

Referenced by doUpdates().

Here is the caller graph for this function:

Since:
1.17
Returns:
array

Definition at line 230 of file DatabaseUpdater.php.

Initialize all of the old globals.

One day this should all become something much nicer

Definition at line 76 of file DatabaseUpdater.php.

Referenced by __construct().

Here is the caller graph for this function:

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:
$keyString Name of key to insert
$valString [optional] value to insert along with the key

Definition at line 328 of file DatabaseUpdater.php.

References canUseNewUpdatelog().

Referenced by modifyField().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 93 of file DatabaseUpdater.php.

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

Referenced by __construct().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Modify an existing field.

Parameters:
$tableString: name of the table to which the field belongs
$fieldString: name of the field to modify
$patchString: path to the patch file
$fullpathBoolean: whether to treat $patch path as a relative or not

Definition at line 535 of file DatabaseUpdater.php.

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

Here is the call graph for this function:

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

Definition at line 116 of file DatabaseUpdater.php.

References $db, $maintenance, $shared, and Installer\getDBTypes().

Referenced by DatabaseInstaller\createExtensionTables(), DatabaseInstaller\doUpgrade(), and DatabaseSqliteTest\prepareDB().

Here is the call graph for this function:

Here is the caller graph for this function:

Output some text.

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

Parameters:
$strString: Text to output

Definition at line 140 of file DatabaseUpdater.php.

References $wgCommandLineMode, and echo.

Referenced by addField(), addIndex(), PostgresUpdater\addPgExtIndex(), PostgresUpdater\addPgField(), PostgresUpdater\addPgIndex(), PostgresUpdater\addSequence(), addTable(), PostgresUpdater\changeField(), PostgresUpdater\changeFkeyDeferrable(), PostgresUpdater\changeNullableField(), MysqlUpdater\checkBin(), PostgresUpdater\checkIpbAdress(), PostgresUpdater\checkIwlPrefix(), PostgresUpdater\checkOiDeleted(), PostgresUpdater\checkOiNameConstraint(), PostgresUpdater\checkPageDeletedTrigger(), PostgresUpdater\checkPagelinkUniqueIndex(), PostgresUpdater\checkRcCurIdNullable(), PostgresUpdater\checkRevUserFkey(), checkStats(), PostgresUpdater\convertArchive2(), doActiveUsersInit(), MysqlUpdater\doBacklinkingIndicesUpdate(), MysqlUpdater\doCategorylinksIndicesUpdate(), MysqlUpdater\doCategoryPopulation(), MysqlUpdater\doClFieldsUpdate(), doCollationUpdate(), MysqlUpdater\doFilearchiveIndicesUpdate(), MysqlUpdater\doFixAncientImagelinks(), OracleUpdater\doFKRenameDeferr(), OracleUpdater\doFunctions17(), MysqlUpdater\doIndexUpdate(), OracleUpdater\doInsertPage0(), MysqlUpdater\doInterwikiUpdate(), MysqlUpdater\doLangLinksLengthUpdate(), doLogSearchPopulation(), doLogUsertextPopulation(), MysqlUpdater\doMaybeProfilingMemoryUpdate(), doMigrateUserOptions(), OracleUpdater\doNamespaceDefaults(), MysqlUpdater\doNamespaceSize(), MysqlUpdater\doPagelinksUpdate(), MysqlUpdater\doPageRandomUpdate(), OracleUpdater\doPageRestrictionsPKUKFix(), MysqlUpdater\doPopulateParentId(), OracleUpdater\doRebuildDuplicateFunction(), OracleUpdater\doRecentchangesFK2Cascade(), OracleUpdater\doRemoveNotNullEmptyDefaults(), OracleUpdater\doRemoveNotNullEmptyDefaults2(), MysqlUpdater\doRestrictionsUpdate(), MysqlUpdater\doSchemaRestructuring(), OracleUpdater\doSchemaUpgrade17(), MysqlUpdater\doTemplatelinksUpdate(), MysqlUpdater\doUniquePlTlIl(), MysqlUpdater\doUpdateMimeMinorField(), doUpdateTranscacheField(), MysqlUpdater\doUserGroupsUpdate(), MysqlUpdater\doUserNewTalkTimestampNotNull(), MysqlUpdater\doUserUniqueUpdate(), MysqlUpdater\doWatchlistNull(), MysqlUpdater\doWatchlistUpdate(), dropField(), dropIndex(), dropTable(), MysqlUpdater\indexHasField(), modifyField(), OracleUpdater\purgeCache(), purgeCache(), rebuildLocalisationCache(), MysqlUpdater\renameEuWikiId(), PostgresUpdater\renameSequence(), PostgresUpdater\renameTable(), SqliteUpdater\sqliteInitialIndexes(), SqliteUpdater\sqliteSetupSearchindex(), and PostgresUpdater\tsearchFixes().

DatabaseUpdater::purgeCache ( ) [protected]

Purge the objectcache table.

Reimplemented in OracleUpdater.

Definition at line 554 of file DatabaseUpdater.php.

References output().

Referenced by doUpdates().

Here is the call graph for this function:

Here is the caller graph for this function:

Rebuilds the localisation cache.

Definition at line 678 of file DatabaseUpdater.php.

References output().

Referenced by doUpdates().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Helper function for doUpdates()

Parameters:
$updatesArray of updates to run
$passSelfBoolean: whether to pass this object we calling external functions

Definition at line 273 of file DatabaseUpdater.php.

Referenced by doUpdates().

Here is the caller graph for this function:

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

Definition at line 291 of file DatabaseUpdater.php.

References $updates, and canUseNewUpdatelog().

Referenced by doUpdates().

Here is the call graph for this function:

Here is the caller graph for this function:

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:
$keyString Name of the key to check for
Returns:
bool

Definition at line 311 of file DatabaseUpdater.php.

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

Here is the caller graph for this function:


Member Data Documentation

DatabaseUpdater::$db [protected]

Reimplemented in OracleUpdater, and PostgresUpdater.

Definition at line 38 of file DatabaseUpdater.php.

Referenced by __construct(), and newForDB().

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

Definition at line 31 of file DatabaseUpdater.php.

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

Definition at line 42 of file DatabaseUpdater.php.

DatabaseUpdater::$shared = false [protected]

Definition at line 40 of file DatabaseUpdater.php.

Referenced by __construct(), and newForDB().

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

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