MediaWiki REL1_39
ActorMigrationBase Class Reference

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

Inheritance 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.
 

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 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(), and getInsertValuesWithTempTable().

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

Reimplemented in ActorMigration.

Definition at line 307 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), MediaWiki\User\UserIdentity\getId(), MediaWiki\User\UserIdentity\getName(), 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.

Reimplemented in ActorMigration.

Definition at line 342 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), getFieldInfo(), 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() or SelectQueryBuilder::tables
  • fields: (string[]) to include in the $vars to IDatabase->select() or SelectQueryBuilder::fields
  • joins: (array) to include in the $join_conds to IDatabase->select() or SelectQueryBuilder::joinConds All tables, fields, and joins are aliased, so + is safe to use.

Reimplemented in ActorMigration.

Definition at line 245 of file ActorMigrationBase.php.

References checkDeprecation(), SCHEMA_COMPAT_READ_OLD, and SCHEMA_COMPAT_READ_TEMP.

◆ 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 four keys:
  • tables: (string[]) to include in the $table to IDatabase->select() or SelectQueryBuilder::tables
  • conds: (string) to include in the $cond to IDatabase->select() or SelectQueryBuilder::conds
  • 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() or SelectQueryBuilder::joinConds All tables and joins are aliased, so + is safe to use.

Reimplemented in ActorMigration.

Definition at line 439 of file ActorMigrationBase.php.

References checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), Wikimedia\Rdbms\Platform\ISQLPlatform\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.


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