BlueSpice MediaWiki REL1_27
 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)
 
 tableExists ($tableName)
 
 addPostDatabaseUpdateMaintenance ($class)
 
 getPostDatabaseUpdateMaintenance ()
 
 doUpdates ($what=[ 'core', 'extensions', 'stats'])
 
 updateRowExists ($key)
 
 insertUpdateRow ($key, $val=null)
 
 copyFile ($filename)
 
 appendLine ($line)
 
 dropTable ($table, $patch=false, $fullpath=false)
 
 modifyField ($table, $field, $patch, $fullpath=false)
 
 setFileAccess ()
 
 purgeCache ()
 

Static Public Member Functions

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

Protected Member Functions

 __construct (DatabaseBase &$db, $shared, Maintenance $maintenance=null)
 
 getExtensionUpdates ()
 
 setAppliedUpdates ($version, $updates=[])
 
 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 ()
 

Protected Attributes

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

Static Protected Attributes

static $updateCounter = 0
 

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

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 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.
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 (   $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
DatabaseBase
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::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::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
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
static DatabaseUpdater::newForDB ( $db,
  $shared = false,
  $maintenance = null 
)
static
Parameters
DatabaseBase$db
bool$shared
Maintenance$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::purgeCache ( )

Purge the objectcache table

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::setAppliedUpdates (   $version,
  $updates = [] 
)
protected
Parameters
string$version
array$updates
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,
]

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