BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
DatabaseUpdater Class Reference
Inheritance diagram for DatabaseUpdater:

Public Member Functions

 getDB ()
 
 output ($str)
 
 addExtensionUpdate (array $update)
 
 addExtensionTable ($tableName, $sqlPath)
 
 addExtensionIndex ($tableName, $indexName, $sqlPath)
 
 addExtensionField ($tableName, $columnName, $sqlPath)
 
 dropExtensionField ($tableName, $columnName, $sqlPath)
 
 dropExtensionIndex ($tableName, $indexName, $sqlPath)
 
 dropExtensionTable ($tableName, $sqlPath)
 
 renameExtensionIndex ($tableName, $oldIndexName, $newIndexName, $sqlPath, $skipBothIndexExistWarning=false)
 
 modifyExtensionField ($tableName, $fieldName, $sqlPath)
 
 modifyExtensionTable ($tableName, $sqlPath)
 
 tableExists ($tableName)
 
 addPostDatabaseUpdateMaintenance ($class)
 
 getPostDatabaseUpdateMaintenance ()
 
 getSchemaVars ()
 
 doUpdates (array $what=[ 'core', 'extensions', 'stats'])
 
 updateRowExists ($key)
 
 insertUpdateRow ($key, $val=null)
 
 copyFile ($filename)
 
 appendLine ($line)
 
 patchPath (IDatabase $db, $patch)
 
 dropTable ($table, $patch=false, $fullpath=false)
 
 modifyField ($table, $field, $patch, $fullpath=false)
 
 modifyTable ($table, $patch, $fullpath=false)
 
 setFileAccess ()
 
 purgeCache ()
 

Static Public Member Functions

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

Protected Member Functions

 __construct (Database &$db, $shared, Maintenance $maintenance=null)
 
 getExtensionUpdates ()
 
 canUseNewUpdatelog ()
 
 doTable ($name)
 
 getOldGlobalUpdates ()
 
 getCoreUpdateList ()
 
 applyPatch ($path, $isFullPath=false, $msg=null)
 
 addTable ($name, $patch, $fullpath=false)
 
 addField ($table, $field, $patch, $fullpath=false)
 
 addIndex ($table, $index, $patch, $fullpath=false)
 
 dropField ($table, $field, $patch, $fullpath=false)
 
 dropIndex ($table, $index, $patch, $fullpath=false)
 
 renameIndex ($table, $oldIndex, $newIndex, $skipBothIndexExistWarning, $patch, $fullpath=false)
 
 checkStats ()
 
 doActiveUsersInit ()
 
 doLogUsertextPopulation ()
 
 doLogSearchPopulation ()
 
 doUpdateTranscacheField ()
 
 doCollationUpdate ()
 
 doMigrateUserOptions ()
 
 doEnableProfiling ()
 
 disableContentHandlerUseDB ()
 
 enableContentHandlerUseDB ()
 
 migrateComments ()
 
 migrateActors ()
 
 migrateArchiveText ()
 
 populateArchiveRevId ()
 

Protected Attributes

 $updates = []
 
 $updatesSkipped = []
 
 $extensionUpdates = []
 
 $db
 
 $maintenance
 
 $shared = false
 
 $postDatabaseUpdateMaintenance
 
 $fileHandle = null
 
 $skipSchema = false
 
 $holdContentHandlerUseDB = true
 

Detailed Description

Class for handling database updates. Roughly based off of updaters.inc, with a few improvements :)

Since
1.17

Constructor & Destructor Documentation

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

Member Function Documentation

DatabaseUpdater::addExtensionField (   $tableName,
  $columnName,
  $sqlPath 
)
Since
1.19
Parameters
string$tableName
string$columnName
string$sqlPath
DatabaseUpdater::addExtensionIndex (   $tableName,
  $indexName,
  $sqlPath 
)
Since
1.19
Parameters
string$tableName
string$indexName
string$sqlPath
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
DatabaseUpdater::addExtensionUpdate ( array  $update)

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 [ $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.
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
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
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
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
DatabaseUpdater::appendLine (   $line)

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

Parameters
string$lineText to append to the file
Returns
bool False to skip actually executing the file
Exceptions
MWException
DatabaseUpdater::applyPatch (   $path,
  $isFullPath = false,
  $msg = null 
)
protected

Applies a SQL patch

Parameters
string$pathPath to the patch file
bool$isFullPathWhether to treat $path as a relative or not
string$msgDescription of the patch
Returns
bool False if patch is skipped.
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
DatabaseUpdater::checkStats ( )
protected

Check the site_stats table is not properly populated.

DatabaseUpdater::copyFile (   $filename)

Append an SQL fragment to the open file handle.

Parameters
string$filenameFile name to open
DatabaseUpdater::disableContentHandlerUseDB ( )
protected

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

DatabaseUpdater::doActiveUsersInit ( )
protected

Sets the number of active users in the site_stats table

DatabaseUpdater::doCollationUpdate ( )
protected

Update CategoryLinks collation

DatabaseUpdater::doEnableProfiling ( )
protected

Enable profiling table when it's turned on

DatabaseUpdater::doLogSearchPopulation ( )
protected

Migrate log params to new table and index for searching

DatabaseUpdater::doLogUsertextPopulation ( )
protected

Populates the log_user_text field in the logging table

DatabaseUpdater::doMigrateUserOptions ( )
protected

Migrates user options from the user table blob to user_properties

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
DatabaseUpdater::doUpdates ( array  $what = [ 'core',
'extensions'  ,
'stats']   
)

Do all the updates

Parameters
array$whatWhat updates to perform
DatabaseUpdater::doUpdateTranscacheField ( )
protected

Updates the timestamps in the transcache table

Returns
bool
DatabaseUpdater::dropExtensionField (   $tableName,
  $columnName,
  $sqlPath 
)
Since
1.20
Parameters
string$tableName
string$columnName
string$sqlPath
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
DatabaseUpdater::dropExtensionTable (   $tableName,
  $sqlPath 
)
Since
1.20
Parameters
string$tableName
string$sqlPath
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
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
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
DatabaseUpdater::enableContentHandlerUseDB ( )
protected

Turns content handler fields back on.

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[]
DatabaseUpdater::getDB ( )

Get a database connection to run updates

Returns
Database
DatabaseUpdater::getExtensionUpdates ( )
protected

Get the list of extension-defined updates

Returns
array
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
DatabaseUpdater::getPostDatabaseUpdateMaintenance ( )
Since
1.17
Returns
string[]
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
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
DatabaseUpdater::migrateActors ( )
protected

Migrate actors to the new 'actor' table

Since
1.31
DatabaseUpdater::migrateArchiveText ( )
protected

Migrate ar_text to modern storage

Since
1.31
DatabaseUpdater::migrateComments ( )
protected

Migrate comments to the new 'comment' table

Since
1.30
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 patch
DatabaseUpdater::modifyExtensionTable (   $tableName,
  $sqlPath 
)
Since
1.31
Parameters
string$tableNameThe table name
string$sqlPathThe path to the SQL patch
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
DatabaseUpdater::modifyTable (   $table,
  $patch,
  $fullpath = false 
)

Modify an existing table, similar to modifyField. Intended for changes that touch more than one column on a table.

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
static DatabaseUpdater::newForDB ( Database  $db,
  $shared = false,
Maintenance  $maintenance = null 
)
static
Parameters
Database$db
bool$shared
Maintenance | null$maintenance
Exceptions
MWException
Returns
DatabaseUpdater
DatabaseUpdater::output (   $str)

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

Parameters
string$strText to output
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
DatabaseUpdater::populateArchiveRevId ( )
protected

Populate ar_rev_id, then make it not nullable

Since
1.31
DatabaseUpdater::purgeCache ( )

Purge various database caches

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]
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
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

DatabaseUpdater::tableExists (   $tableName)
Since
1.20
Parameters
string$tableName
Returns
bool
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

Member Data Documentation

DatabaseUpdater::$holdContentHandlerUseDB = true
protected

Hold the value of $wgContentHandlerUseDB during the upgrade.

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,
]

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