MediaWiki REL1_37
ActorMigrationBase Class Reference

This abstract base class helps migrate core and extension code to use the actor table. More...

Inheritance diagram for ActorMigrationBase:
Collaboration diagram for ActorMigrationBase:

Public Member Functions

 __construct ( $fieldInfos, $stage, ActorStoreFactory $actorStoreFactory, $options=[])
 
 getInsertValues (IDatabase $dbw, $key, UserIdentity $user)
 Get UPDATE fields for the actor.
 
 getInsertValuesWithTempTable (IDatabase $dbw, $key, UserIdentity $user)
 Get UPDATE fields for the actor.
 
 getJoin ( $key)
 Get SELECT fields and joins for the actor key.
 
 getWhere (IDatabase $db, $key, $users, $useId=true)
 Get WHERE condition for the actor.
 
 isAnon ( $field)
 Return an SQL condition to test if a user field is anonymous.
 
 isNotAnon ( $field)
 Return an SQL condition to test if a user field is non-anonymous.
 

Protected Member Functions

 checkDeprecation ( $key)
 Issue deprecation warning/error as appropriate.
 
 getFieldInfo ( $key)
 Get config information about a field.
 
 getInstanceName ()
 Get a name for this instance to use in error messages.
 

Private Member Functions

 getFieldNames ( $key)
 
 getTempTableInfo ( $key)
 Convenience function for getting temp table config.
 

Private Attributes

ActorStoreFactory $actorStoreFactory
 
bool $allowUnknown
 
array $fieldInfos
 
array[] $joinCache = []
 Cache for self::getJoin()
 
int $readStage
 One of the SCHEMA_COMPAT_READ_* values.
 
int $writeStage
 A combination of the SCHEMA_COMPAT_WRITE_* flags.
 

Detailed Description

This abstract base class helps migrate core and extension code to use the actor table.

Stability: stable
to extend
Since
1.37

Definition at line 35 of file ActorMigrationBase.php.

Constructor & Destructor Documentation

◆ __construct()

ActorMigrationBase::__construct (   $fieldInfos,
  $stage,
ActorStoreFactory  $actorStoreFactory,
  $options = [] 
)
Parameters
array$fieldInfosAn array of associative arrays, giving configuration information about fields which are being migrated. Subkeys are:
  • removedVersion: The version in which the field was removed
  • deprecatedVersion: The version in which the field was deprecated
  • component: The component for removedVersion and deprecatedVersion. Default: MediaWiki.
  • textField: Override the old text field name. Default {$key}_text.
  • actorField: Override the actor field name. Default {$key}_actor.
  • tempTable: An array of information about the temp table linking the old table to the actor table. Default: no temp table is used. If set, the following subkeys must be present:
    • table: Temporary table name
    • pk: Temporary table column referring to the main table's primary key
    • field: Temporary table column referring actor.actor_id
    • joinPK: Main table's primary key
    • extra: An array of extra field names to be copied into the temp table for indexing. The key is the field name in the temp table, and the value is the field name in the main table.
  • formerTempTableVersion: The version of the component in which this field used a temp table. If present, getInsertValuesWithTempTable() still works, but issues a deprecation warning. All subkeys are optional.
Stability: stable
to override
Stability: stable
to call
Parameters
int$stageThe migration stage. This is a combination of SCHEMA_COMPAT_* flags:
  • SCHEMA_COMPAT_READ_OLD, SCHEMA_COMPAT_WRITE_OLD: Use the old schema, with *_user and *_user_text fields.
  • SCHEMA_COMPAT_READ_TEMP, SCHEMA_COMPAT_WRITE_TEMP: Use the new schema, with an actor table. Normal tables are joined via a *_actor field, whereas temp tables are joined to the actor table via an intermediate table.
  • SCHEMA_COMPAT_READ_NEW, SCHEMA_COMPAT_WRITE_NEW: Use the new schema. Former temp tables are no longer used, and all relevant tables join directly to the actor table.
ActorStoreFactory$actorStoreFactory
array$optionsArray of other options. May contain:
  • allowUnknown: Allow fields not present in $fieldInfos. True by default.

Definition at line 97 of file ActorMigrationBase.php.

References $actorStoreFactory, $fieldInfos, $readStage, $writeStage, SCHEMA_COMPAT_READ_MASK, SCHEMA_COMPAT_READ_NEW, SCHEMA_COMPAT_READ_OLD, SCHEMA_COMPAT_READ_TEMP, SCHEMA_COMPAT_WRITE_MASK, SCHEMA_COMPAT_WRITE_NEW, SCHEMA_COMPAT_WRITE_OLD, and SCHEMA_COMPAT_WRITE_TEMP.

Member Function Documentation

◆ checkDeprecation()

ActorMigrationBase::checkDeprecation (   $key)
protected

Issue deprecation warning/error as appropriate.

Access: internal
Parameters
string$key

Definition at line 176 of file ActorMigrationBase.php.

References getFieldInfo(), and wfDeprecated().

Referenced by getInsertValues(), getInsertValuesWithTempTable(), getJoin(), and getWhere().

◆ getFieldInfo()

ActorMigrationBase::getFieldInfo (   $key)
protected

Get config information about a field.

Stability: stable
to override
Parameters
string$key
Returns
array

Definition at line 142 of file ActorMigrationBase.php.

References getInstanceName().

Referenced by checkDeprecation(), getFieldNames(), getInsertValuesWithTempTable(), and getTempTableInfo().

◆ getFieldNames()

ActorMigrationBase::getFieldNames (   $key)
private
Parameters
string$keyA key such as "rev_user" identifying the actor field being fetched.
Returns
string[] [ $text, $actor ]

Definition at line 215 of file ActorMigrationBase.php.

References getFieldInfo().

Referenced by getInsertValues(), getInsertValuesWithTempTable(), getJoin(), and getWhere().

◆ getInsertValues()

ActorMigrationBase::getInsertValues ( IDatabase  $dbw,
  $key,
UserIdentity  $user 
)

Get UPDATE fields for the actor.

Parameters
IDatabase$dbwDatabase to use for creating an actor ID, if necessary
string$keyA key such as "rev_user" identifying the actor field being fetched.
UserIdentity$userUser to set in the update
Returns
array to merge into $values to IDatabase->update() or $a to IDatabase->insert()

Definition at line 307 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), getFieldNames(), MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\getName(), getTempTableInfo(), SCHEMA_COMPAT_WRITE_NEW, SCHEMA_COMPAT_WRITE_OLD, and SCHEMA_COMPAT_WRITE_TEMP.

◆ getInsertValuesWithTempTable()

ActorMigrationBase::getInsertValuesWithTempTable ( IDatabase  $dbw,
  $key,
UserIdentity  $user 
)

Get UPDATE fields for the actor.

Parameters
IDatabase$dbwDatabase to use for creating an actor ID, if necessary
string$keyA key such as "rev_user" identifying the actor field being fetched.
UserIdentity$userUser to set in the update
Returns
array with two values:
  • array to merge into $values to IDatabase->update() or $a to IDatabase->insert()
  • callback to call with the primary key for the main table insert and extra fields needed for the temp table.

Definition at line 342 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), getFieldInfo(), getFieldNames(), MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\getName(), SCHEMA_COMPAT_WRITE_NEW, SCHEMA_COMPAT_WRITE_OLD, SCHEMA_COMPAT_WRITE_TEMP, Wikimedia\Rdbms\IDatabase\upsert(), and wfDeprecated().

◆ getInstanceName()

ActorMigrationBase::getInstanceName ( )
protected

Get a name for this instance to use in error messages.

Stability: stable
to override
Returns
string
Exceptions
ReflectionException

Definition at line 160 of file ActorMigrationBase.php.

Referenced by getFieldInfo().

◆ getJoin()

ActorMigrationBase::getJoin (   $key)

Get SELECT fields and joins for the actor key.

Parameters
string$keyA key such as "rev_user" identifying the actor field being fetched.
Returns
array[] With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select()
  • fields: (string[]) to include in the $vars to IDatabase->select()
  • joins: (array) to include in the $join_conds to IDatabase->select() All tables, fields, and joins are aliased, so + is safe to use.

Definition at line 245 of file ActorMigrationBase.php.

References checkDeprecation(), getFieldNames(), getTempTableInfo(), SCHEMA_COMPAT_READ_OLD, and SCHEMA_COMPAT_READ_TEMP.

◆ getTempTableInfo()

ActorMigrationBase::getTempTableInfo (   $key)
private

Convenience function for getting temp table config.

Parameters
string$key
Returns
array|null

Definition at line 228 of file ActorMigrationBase.php.

References getFieldInfo().

Referenced by getInsertValues(), getJoin(), and getWhere().

◆ getWhere()

ActorMigrationBase::getWhere ( IDatabase  $db,
  $key,
  $users,
  $useId = true 
)

Get WHERE condition for the actor.

Parameters
IDatabase$dbDatabase to use for quoting and list-making
string$keyA key such as "rev_user" identifying the actor field being fetched.
UserIdentity | UserIdentity[] | null | false$usersUsers to test for. Passing null, false, or the empty array will return 'conds' that never match, and an empty array for 'orconds'.
bool$useIdIf false, don't try to query by the user ID. Intended for use with rc_user since it has an index on (rc_user_text,rc_timestamp) but not (rc_user,rc_timestamp).
Returns
array With three keys:
  • tables: (string[]) to include in the $table to IDatabase->select()
  • conds: (string) to include in the $cond to IDatabase->select()
  • orconds: (array[]) array of alternatives in case a union of multiple queries would be more efficient than a query with OR. May have keys 'actor', 'userid', 'username'. Since 1.32, this is guaranteed to contain just one alternative if $users contains a single user.
  • joins: (array) to include in the $join_conds to IDatabase->select() All tables and joins are aliased, so + is safe to use.

Definition at line 438 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), getFieldNames(), getTempTableInfo(), Wikimedia\Rdbms\IDatabase\makeList(), SCHEMA_COMPAT_READ_NEW, and SCHEMA_COMPAT_READ_TEMP.

◆ isAnon()

ActorMigrationBase::isAnon (   $field)

Return an SQL condition to test if a user field is anonymous.

Parameters
string$fieldField name or SQL fragment
Returns
string

Definition at line 197 of file ActorMigrationBase.php.

References SCHEMA_COMPAT_READ_TEMP.

◆ isNotAnon()

ActorMigrationBase::isNotAnon (   $field)

Return an SQL condition to test if a user field is non-anonymous.

Parameters
string$fieldField name or SQL fragment
Returns
string

Definition at line 206 of file ActorMigrationBase.php.

References SCHEMA_COMPAT_READ_TEMP.

Member Data Documentation

◆ $actorStoreFactory

ActorStoreFactory ActorMigrationBase::$actorStoreFactory
private

Definition at line 46 of file ActorMigrationBase.php.

Referenced by __construct().

◆ $allowUnknown

bool ActorMigrationBase::$allowUnknown
private

Definition at line 52 of file ActorMigrationBase.php.

◆ $fieldInfos

array ActorMigrationBase::$fieldInfos
private

Definition at line 49 of file ActorMigrationBase.php.

Referenced by __construct().

◆ $joinCache

array [] ActorMigrationBase::$joinCache = []
private

Cache for self::getJoin()

Definition at line 37 of file ActorMigrationBase.php.

◆ $readStage

int ActorMigrationBase::$readStage
private

One of the SCHEMA_COMPAT_READ_* values.

Definition at line 40 of file ActorMigrationBase.php.

Referenced by __construct().

◆ $writeStage

int ActorMigrationBase::$writeStage
private

A combination of the SCHEMA_COMPAT_WRITE_* flags.

Definition at line 43 of file ActorMigrationBase.php.

Referenced by __construct().


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