ApiFlowThank: Replace deprecated User::newFromId

Change-Id: I857ce647a1374600c952107b92c3c35440c83b6c
This commit is contained in:
Fomafix 2024-04-20 20:31:46 +00:00
parent 801e5a56d1
commit 139c83b1a9
2 changed files with 20 additions and 2 deletions

View file

@ -3,14 +3,18 @@
namespace MediaWiki\Extension\Thanks\Api;
use ApiBase;
use ApiMain;
use Flow\Container;
use Flow\Conversion\Utils;
use Flow\Exception\FlowException;
use Flow\Model\PostRevision;
use Flow\Model\UUID;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Extension\Thanks\Storage\LogStore;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Title\Title;
use MediaWiki\User\User;
use MediaWiki\User\UserFactory;
use Wikimedia\ParamValidator\ParamValidator;
/**
@ -25,6 +29,19 @@ use Wikimedia\ParamValidator\ParamValidator;
class ApiFlowThank extends ApiThank {
private UserFactory $userFactory;
public function __construct(
ApiMain $main,
$action,
PermissionManager $permissionManager,
LogStore $storage,
UserFactory $userFactory
) {
parent::__construct( $main, $action, $permissionManager, $storage );
$this->userFactory = $userFactory;
}
public function execute() {
$user = $this->getUser();
$this->dieOnBadUser( $user );
@ -107,7 +124,7 @@ class ApiFlowThank extends ApiThank {
* @return User
*/
private function getRecipientFromPost( PostRevision $post ) {
$recipient = User::newFromId( $post->getCreatorId() );
$recipient = $this->userFactory->newFromId( $post->getCreatorId() );
if ( !$recipient->loadFromId() ) {
$this->dieWithError( 'thanks-error-invalidrecipient', 'invalidrecipient' );
}

View file

@ -411,7 +411,8 @@ class Hooks implements
"class" => ApiFlowThank::class,
"services" => [
"PermissionManager",
"ThanksLogStore"
"ThanksLogStore",
"UserFactory",
]
]
);