*/
public static function getSelectQueryData() {
$commentQuery = CommentStore::getStore()->getJoin( 'log_comment' );
+ $actorQuery = ActorMigration::newMigration()->getJoin( 'log_user' );
- $tables = [ 'logging', 'user' ] + $commentQuery['tables'];
+ $tables = array_merge(
+ [ 'logging' ], $commentQuery['tables'], $actorQuery['tables'], [ 'user' ]
+ );
$fields = [
'log_id', 'log_type', 'log_action', 'log_timestamp',
- 'log_user', 'log_user_text',
'log_namespace', 'log_title', // unused log_page
'log_params', 'log_deleted',
'user_id', 'user_name', 'user_editcount',
- ] + $commentQuery['fields'];
+ ] + $commentQuery['fields'] + $actorQuery['fields'];
$joins = [
// IPs don't have an entry in user table
- 'user' => [ 'LEFT JOIN', 'log_user=user_id' ],
- ] + $commentQuery['joins'];
+ 'user' => [ 'LEFT JOIN', 'user_id=' . $actorQuery['fields']['log_user'] ],
+ ] + $commentQuery['joins'] + $actorQuery['joins'];
return [
'tables' => $tables,
}
}
+ /**
+ * Loads a LogEntry with the given id from database
+ *
+ * @param int $id
+ * @param IDatabase $db
+ * @return DatabaseLogEntry|null
+ */
+ public static function newFromId( $id, IDatabase $db ) {
+ $queryInfo = self::getSelectQueryData();
+ $queryInfo['conds'] += [ 'log_id' => $id ];
+ $row = $db->selectRow(
+ $queryInfo['tables'],
+ $queryInfo['fields'],
+ $queryInfo['conds'],
+ __METHOD__,
+ $queryInfo['options'],
+ $queryInfo['join_conds']
+ );
+ if ( !$row ) {
+ return null;
+ }
+ return self::newFromRow( $row );
+ }
+
/** @var stdClass Database result row. */
protected $row;
public function getPerformer() {
if ( !$this->performer ) {
+ $actorId = isset( $this->row->log_actor ) ? (int)$this->row->log_actor : 0;
$userId = (int)$this->row->log_user;
- if ( $userId !== 0 ) {
+ if ( $userId !== 0 || $actorId !== 0 ) {
// logged-in users
if ( isset( $this->row->user_name ) ) {
$this->performer = User::newFromRow( $this->row );
+ } elseif ( $actorId !== 0 ) {
+ $this->performer = User::newFromActorId( $actorId );
} else {
$this->performer = User::newFromId( $userId );
}
public function getPerformer() {
if ( !$this->performer ) {
+ $actorId = isset( $this->row->rc_actor ) ? (int)$this->row->rc_actor : 0;
$userId = (int)$this->row->rc_user;
- if ( $userId !== 0 ) {
+ if ( $actorId !== 0 ) {
+ $this->performer = User::newFromActorId( $actorId );
+ } elseif ( $userId !== 0 ) {
$this->performer = User::newFromId( $userId );
} else {
$userText = $this->row->rc_user_text;
* @throws MWException
*/
public function insert( IDatabase $dbw = null ) {
+ global $wgActorTableSchemaMigrationStage;
+
$dbw = $dbw ?: wfGetDB( DB_MASTER );
if ( $this->timestamp === null ) {
$params = $this->getParameters();
$relations = $this->relations;
+ // Ensure actor relations are set
+ if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_BOTH &&
+ empty( $relations['target_author_actor'] )
+ ) {
+ $actorIds = [];
+ if ( !empty( $relations['target_author_id'] ) ) {
+ foreach ( $relations['target_author_id'] as $id ) {
+ $actorIds[] = User::newFromId( $id )->getActorId( $dbw );
+ }
+ }
+ if ( !empty( $relations['target_author_ip'] ) ) {
+ foreach ( $relations['target_author_ip'] as $ip ) {
+ $actorIds[] = User::newFromName( $ip, false )->getActorId( $dbw );
+ }
+ }
+ if ( $actorIds ) {
+ $relations['target_author_actor'] = $actorIds;
+ $params['authorActors'] = $actorIds;
+ }
+ }
+ if ( $wgActorTableSchemaMigrationStage >= MIGRATION_WRITE_NEW ) {
+ unset( $relations['target_author_id'], $relations['target_author_ip'] );
+ unset( $params['authorIds'], $params['authorIPs'] );
+ }
+
// Additional fields for which there's no space in the database table schema
$revId = $this->getAssociatedRevId();
if ( $revId ) {
'log_type' => $this->getType(),
'log_action' => $this->getSubtype(),
'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ),
- 'log_user' => $this->getPerformer()->getId(),
- 'log_user_text' => $this->getPerformer()->getName(),
'log_namespace' => $this->getTarget()->getNamespace(),
'log_title' => $this->getTarget()->getDBkey(),
'log_page' => $this->getTarget()->getArticleID(),
$data['log_deleted'] = $this->deleted;
}
$data += CommentStore::getStore()->insert( $dbw, 'log_comment', $comment );
+ $data += ActorMigration::newMigration()
+ ->getInsertValues( $dbw, 'log_user', $this->getPerformer() );
$dbw->insert( 'logging', $data, __METHOD__ );
$this->id = $dbw->insertId();