Inject UserFactory into ActorMigration
Bug: T265311 Change-Id: Ie51ea0be0b09dc782365c4b201152b52fd5b3573
This commit is contained in:
parent
1db27ef095
commit
dcf682a521
3 changed files with 23 additions and 3 deletions
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserFactory;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MediaWiki\User\UserNameUtils;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
|
@ -110,15 +111,23 @@ class ActorMigration {
|
|||
/** @var int Combination of SCHEMA_COMPAT_* constants */
|
||||
private $stage;
|
||||
|
||||
/** @var UserFactory */
|
||||
private $userFactory;
|
||||
|
||||
/** @var UserNameUtils */
|
||||
private $userNameUtils;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param int $stage
|
||||
* @param UserFactory $userFactory
|
||||
* @param UserNameUtils $userNameUtils
|
||||
*/
|
||||
public function __construct( $stage, UserNameUtils $userNameUtils ) {
|
||||
public function __construct(
|
||||
$stage,
|
||||
UserFactory $userFactory,
|
||||
UserNameUtils $userNameUtils
|
||||
) {
|
||||
if ( ( $stage & SCHEMA_COMPAT_WRITE_BOTH ) === 0 ) {
|
||||
throw new InvalidArgumentException( '$stage must include a write mode' );
|
||||
}
|
||||
|
|
@ -136,6 +145,7 @@ class ActorMigration {
|
|||
}
|
||||
|
||||
$this->stage = $stage;
|
||||
$this->userFactory = $userFactory;
|
||||
$this->userNameUtils = $userNameUtils;
|
||||
}
|
||||
|
||||
|
|
@ -388,7 +398,11 @@ class ActorMigration {
|
|||
if ( $this->stage & SCHEMA_COMPAT_WRITE_NEW ) {
|
||||
// We need to be able to assign an actor ID if none exists
|
||||
if ( !$user instanceof User && !$user->getActorId() ) {
|
||||
$user = User::newFromAnyId( $user->getId(), $user->getName(), null );
|
||||
$user = $this->userFactory->newFromAnyId(
|
||||
$user->getId(),
|
||||
$user->getName(),
|
||||
null
|
||||
);
|
||||
}
|
||||
$id = $user->getActorId( $dbw );
|
||||
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ return [
|
|||
'ActorMigration' => function ( MediaWikiServices $services ) : ActorMigration {
|
||||
return new ActorMigration(
|
||||
SCHEMA_COMPAT_NEW,
|
||||
$services->getUserFactory(),
|
||||
$services->getUserNameUtils()
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -66,7 +66,12 @@ class ActorMigrationTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
private function getMigration( $stage ) {
|
||||
return new ActorMigration( $stage, MediaWikiServices::getInstance()->getUserNameUtils() );
|
||||
$mwServices = MediaWikiServices::getInstance();
|
||||
return new ActorMigration(
|
||||
$stage,
|
||||
$mwServices->getUserFactory(),
|
||||
$mwServices->getUserNameUtils()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue