MediaWiki  master
ActorMigration Class Reference

This class handles the logic for the actor table migration and should always be used in lieu of directly accessing database tables. More...

Collaboration diagram for ActorMigration:

Public Member Functions

 __construct ( $stage, ActorStoreFactory $actorStoreFactory)
 
 getExistingActorId (IDatabase $db, UserIdentity $user)
 Get actor ID from UserIdentity, if it exists. More...
 
 getInsertValues (IDatabase $dbw, $key, UserIdentity $user)
 Get UPDATE fields for the actor. More...
 
 getInsertValuesWithTempTable (IDatabase $dbw, $key, UserIdentity $user)
 Get UPDATE fields for the actor. More...
 
 getJoin ( $key)
 Get SELECT fields and joins for the actor key. More...
 
 getNewActorId (IDatabase $dbw, UserIdentity $user)
 Attempt to assign an actor ID to the given user. More...
 
 getWhere (IDatabase $db, $key, $users, $useId=true)
 Get WHERE condition for the actor. More...
 
 isAnon ( $field)
 Return an SQL condition to test if a user field is anonymous. More...
 
 isNotAnon ( $field)
 Return an SQL condition to test if a user field is non-anonymous. More...
 

Static Public Member Functions

static newMigration ()
 Static constructor. More...
 

Public Attributes

const MIGRATION_STAGE_SCHEMA_COMPAT = 1
 Constant for extensions to feature-test whether $wgActorTableSchemaMigrationStage (in MW <1.34) expects MIGRATION_* or SCHEMA_COMPAT_*. More...
 

Protected Attributes

const DEPRECATED
 Define fields that are deprecated for use with this class. More...
 
const FORMER_TEMP_TABLES = []
 Fields that formerly used TEMP_TABLES Array keys are field names, values are the MediaWiki version when it was removed. More...
 
const REMOVED = []
 Define fields that are removed for use with this class. More...
 
const SPECIAL_FIELDS
 Define fields that use non-standard mapping Array keys are the user id column name, values are arrays with two elements (the user text column name and the actor id column name) More...
 
const TEMP_TABLES
 Define fields that use temporary tables for transitional purposes Array keys are field names, values are arrays with these possible fields: More...
 

Static Private Member Functions

static checkDeprecation ( $key)
 Issue deprecation warning/error as appropriate. More...
 
static getFieldNames ( $key)
 

Private Attributes

ActorStoreFactory $actorStoreFactory
 
array[] $joinCache = []
 Cache for self::getJoin() More...
 
int $stage
 Combination of SCHEMA_COMPAT_* constants. More...
 

Detailed Description

This class handles the logic for the actor table migration and should always be used in lieu of directly accessing database tables.

This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once actor migration is complete.

Since
1.31
1.34 Use with 'ar_user', 'img_user', 'oi_user', 'fa_user', 'rc_user', 'log_user', and 'ipb_by' is deprecated. Callers should reference the corresponding actor fields directly.

Definition at line 41 of file ActorMigration.php.

Constructor & Destructor Documentation

◆ __construct()

ActorMigration::__construct (   $stage,
ActorStoreFactory  $actorStoreFactory 
)
Parameters
int$stage
ActorStoreFactory$actorStoreFactory
Access: internal

Definition at line 120 of file ActorMigration.php.

References $actorStoreFactory, $stage, SCHEMA_COMPAT_READ_BOTH, SCHEMA_COMPAT_READ_NEW, SCHEMA_COMPAT_READ_OLD, SCHEMA_COMPAT_WRITE_BOTH, SCHEMA_COMPAT_WRITE_NEW, and SCHEMA_COMPAT_WRITE_OLD.

Member Function Documentation

◆ checkDeprecation()

static ActorMigration::checkDeprecation (   $key)
staticprivate

Issue deprecation warning/error as appropriate.

Parameters
string$key

Definition at line 156 of file ActorMigration.php.

References wfDeprecated().

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

◆ getExistingActorId()

ActorMigration::getExistingActorId ( IDatabase  $db,
UserIdentity  $user 
)

Get actor ID from UserIdentity, if it exists.

Since
1.35.0
Deprecated:
since 1.36. Use ActorStore::findActorId instead.
Parameters
IDatabase$db
UserIdentity$user
Returns
int|false

Definition at line 260 of file ActorMigration.php.

References Wikimedia\Rdbms\IDatabase\getDomainID(), and wfDeprecated().

◆ getFieldNames()

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

Definition at line 190 of file ActorMigration.php.

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

◆ getInsertValues()

ActorMigration::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 303 of file ActorMigration.php.

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

◆ getInsertValuesWithTempTable()

ActorMigration::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 336 of file ActorMigration.php.

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

◆ getJoin()

ActorMigration::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 206 of file ActorMigration.php.

References $t, checkDeprecation(), getFieldNames(), and SCHEMA_COMPAT_READ_OLD.

◆ getNewActorId()

ActorMigration::getNewActorId ( IDatabase  $dbw,
UserIdentity  $user 
)

Attempt to assign an actor ID to the given user.

If it is already assigned, return the existing ID.

Since
1.35.0
Deprecated:
since 1.36. Use ActorStore::acquireActorId instead.
Parameters
IDatabase$dbw
UserIdentity$user
Returns
int The new actor ID

Definition at line 283 of file ActorMigration.php.

References Wikimedia\Rdbms\IDatabase\getDomainID(), and wfDeprecated().

◆ getWhere()

ActorMigration::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 421 of file ActorMigration.php.

References $t, checkDeprecation(), Wikimedia\Rdbms\IDatabase\getDomainID(), getFieldNames(), LIST_AND, LIST_OR, Wikimedia\Rdbms\IDatabase\makeList(), and SCHEMA_COMPAT_READ_NEW.

◆ isAnon()

ActorMigration::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 172 of file ActorMigration.php.

References SCHEMA_COMPAT_READ_NEW.

◆ isNotAnon()

ActorMigration::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 181 of file ActorMigration.php.

References SCHEMA_COMPAT_READ_NEW.

◆ newMigration()

static ActorMigration::newMigration ( )
static

Static constructor.

Returns
self

Definition at line 148 of file ActorMigration.php.

Referenced by ChangesListSpecialPage\__construct(), WikiPage\archiveRevisions(), SiteStatsUpdate\cacheUpdate(), Orphans\checkOrphans(), WikiPage\commitRollback(), LocalFileDeleteBatch\doDBInserts(), DeduplicateArchiveRevId\doDBUpdates(), PopulateIpChanges\doDBUpdates(), ReassignEdits\doReassignEdits(), WikiExporter\dumpLogs(), ApiQueryBlocks\execute(), ApiQueryContributors\execute(), ApiQueryDeletedrevs\execute(), ApiQueryLogEvents\execute(), LocalFileRestoreBatch\execute(), DeleteDefaultMessages\execute(), FixUserRegistration\execute(), InitEditCount\execute(), ChangesListSpecialPage\filterOnUserExperienceLevel(), WikiPage\getContributors(), EditPage\getLastDelete(), MediaWiki\Block\DatabaseBlock\getQueryInfo(), RecentChange\getQueryInfo(), ArchivedFile\getQueryInfo(), LocalFile\getQueryInfo(), OldLocalFile\getQueryInfo(), RollbackEdits\getRollbackTitles(), DatabaseLogEntry\getSelectQueryData(), WikiRevision\importLogItem(), ManualLogEntry\insert(), RemoveUnusedAccounts\isInactiveAccount(), MediaWiki\Storage\PageEditStash\lastEditTime(), ApiQueryUserContribs\prepareQuery(), RebuildRecentchanges\rebuildRecentChangesTablePass1(), RebuildRecentchanges\rebuildRecentChangesTablePass3(), RebuildRecentchanges\rebuildRecentChangesTablePass4(), OldLocalFile\recordOldUpload(), ApiQueryAllImages\run(), ApiQueryRecentChanges\run(), ApiQueryAllDeletedRevisions\run(), ApiQueryAllRevisions\run(), ApiQueryDeletedRevisions\run(), ApiQueryRevisions\run(), LogPage\saveContent(), and RecentChangesUpdateJob\updateActiveUsers().

Member Data Documentation

◆ $actorStoreFactory

ActorStoreFactory ActorMigration::$actorStoreFactory
private

Definition at line 113 of file ActorMigration.php.

Referenced by __construct().

◆ $joinCache

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

Cache for self::getJoin()

Definition at line 107 of file ActorMigration.php.

◆ $stage

int ActorMigration::$stage
private

Combination of SCHEMA_COMPAT_* constants.

Definition at line 110 of file ActorMigration.php.

Referenced by __construct().

◆ DEPRECATED

const ActorMigration::DEPRECATED
protected
Initial value:
= [
'ar_user' => null,
'img_user' => null,
'oi_user' => null,
'fa_user' => null,
'rc_user' => null,
'log_user' => null,
'ipb_by' => null,
]

Define fields that are deprecated for use with this class.

Array keys are field names, values are null for soft deprecation or a string naming the deprecated version for hard deprecation.

Definition at line 81 of file ActorMigration.php.

◆ FORMER_TEMP_TABLES

const ActorMigration::FORMER_TEMP_TABLES = []
protected

Fields that formerly used TEMP_TABLES Array keys are field names, values are the MediaWiki version when it was removed.

Definition at line 74 of file ActorMigration.php.

◆ MIGRATION_STAGE_SCHEMA_COMPAT

const ActorMigration::MIGRATION_STAGE_SCHEMA_COMPAT = 1

Constant for extensions to feature-test whether $wgActorTableSchemaMigrationStage (in MW <1.34) expects MIGRATION_* or SCHEMA_COMPAT_*.

Definition at line 47 of file ActorMigration.php.

◆ REMOVED

const ActorMigration::REMOVED = []
protected

Define fields that are removed for use with this class.

Array keys are field names, values are the MediaWiki version in which use was removed.

Definition at line 95 of file ActorMigration.php.

◆ SPECIAL_FIELDS

const ActorMigration::SPECIAL_FIELDS
protected
Initial value:
= [
'ipb_by' => [ 'ipb_by_text', 'ipb_by_actor' ],
]

Define fields that use non-standard mapping Array keys are the user id column name, values are arrays with two elements (the user text column name and the actor id column name)

Definition at line 102 of file ActorMigration.php.

◆ TEMP_TABLES

const ActorMigration::TEMP_TABLES
protected
Initial value:
= [
'rev_user' => [
'table' => 'revision_actor_temp',
'pk' => 'revactor_rev',
'field' => 'revactor_actor',
'joinPK' => 'rev_id',
'extra' => [
'revactor_timestamp' => 'rev_timestamp',
'revactor_page' => 'rev_page',
],
],
]

Define fields that use temporary tables for transitional purposes Array keys are field names, values are arrays with these possible fields:

  • 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

Definition at line 57 of file ActorMigration.php.


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