From cf971e0d4677fa6831ade4dabdfda82604dab00a Mon Sep 17 00:00:00 2001 From: lens0021 Date: Sat, 23 Oct 2021 15:53:07 +0900 Subject: [PATCH] RCDatabaseLogEntry: Stop returning an unknown actor if rc_user is given In all cases that rc_actor is not given the function returns an unknown actor as ActorStore::newActorFromRowFields() throw exception in that cases. It is too strict because, for instance, RecentChange::newLogEntry() does not provide the attribute. This changes it. Bug: T286979 Change-Id: I5668053c30c18755536bfcb98524e79eb2827dda --- includes/logging/RCDatabaseLogEntry.php | 46 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/includes/logging/RCDatabaseLogEntry.php b/includes/logging/RCDatabaseLogEntry.php index f1adf8eb5a0..39418f223a4 100644 --- a/includes/logging/RCDatabaseLogEntry.php +++ b/includes/logging/RCDatabaseLogEntry.php @@ -71,23 +71,39 @@ class RCDatabaseLogEntry extends DatabaseLogEntry { public function getPerformerIdentity(): UserIdentity { if ( !$this->performer ) { $actorStore = MediaWikiServices::getInstance()->getActorStore(); - try { - $this->performer = $actorStore->newActorFromRowFields( - $this->row->rc_user ?? 0, - $this->row->rc_user_text, - $this->row->rc_actor ?? null - ); - } catch ( InvalidArgumentException $e ) { - LoggerFactory::getInstance( 'logentry' )->warning( - 'Failed to instantiate RC log entry performer', [ - 'exception' => $e, - 'log_id' => $this->getId() - ] - ); - $this->performer = $actorStore->getUnknownActor(); + $userFactory = MediaWikiServices::getInstance()->getUserFactory(); + if ( isset( $this->row->rc_actor ) ) { + try { + $this->performer = $actorStore->newActorFromRowFields( + $this->row->rc_user ?? 0, + $this->row->rc_user_text, + $this->row->rc_actor + ); + } catch ( InvalidArgumentException $e ) { + LoggerFactory::getInstance( 'logentry' )->warning( + 'Failed to instantiate RC log entry performer', [ + 'exception' => $e, + 'log_id' => $this->getId() + ] + ); + } + } elseif ( isset( $this->row->rc_user ) ) { + $this->performer = $userFactory->newFromId( $this->row->rc_user )->getUser(); + } elseif ( isset( $this->row->rc_user_text ) ) { + $user = $userFactory->newFromName( $this->row->rc_user_text ); + if ( $user ) { + $this->performer = $user->getUser(); + } else { + LoggerFactory::getInstance( 'logentry' )->warning( + 'Failed to instantiate RC log entry performer', [ + 'rc_user_text' => $this->row->rc_user_text, + 'log_id' => $this->getId() + ] + ); + } } } - return $this->performer; + return $this->performer ?: $actorStore->getUnknownActor(); } public function getTarget() {