MediaWiki master
LocalUserRegistrationProvider.php
Go to the documentation of this file.
1<?php
2
4
8
10
11 public const TYPE = 'local';
12
13 private UserFactory $userFactory;
14 private IConnectionProvider $connectionProvider;
15
16 public function __construct(
17 UserFactory $userFactory,
18 IConnectionProvider $connectionProvider
19 ) {
20 $this->userFactory = $userFactory;
21 $this->connectionProvider = $connectionProvider;
22 }
23
27 public function fetchRegistration( UserIdentity $user ) {
28 // TODO: Factor this out from User::getRegistration to this method (T352871)
29 $user = $this->userFactory->newFromUserIdentity( $user );
30 return $user->getRegistration();
31 }
32
36 public function fetchRegistrationBatch( iterable $users ): array {
37 $timestampsById = [];
38
39 foreach ( $users as $user ) {
40 // Make the list of user IDs unique.
41 $timestampsById[$user->getId()] = null;
42 }
43
44 $batches = array_chunk( array_keys( $timestampsById ), 1_000 );
45
46 $dbr = $this->connectionProvider->getReplicaDatabase();
47
48 foreach ( $batches as $userIdBatch ) {
49 $res = $dbr->newSelectQueryBuilder()
50 ->select( [ 'user_id', 'user_registration' ] )
51 ->from( 'user' )
52 ->where( [ 'user_id' => $userIdBatch ] )
53 ->caller( __METHOD__ )
54 ->fetchResultSet();
55
56 foreach ( $res as $row ) {
57 $timestampsById[$row->user_id] = wfTimestampOrNull( TS_MW, $row->user_registration );
58 }
59 }
60
61 return $timestampsById;
62 }
63}
wfTimestampOrNull( $outputtype=TS_UNIX, $ts=null)
Return a formatted timestamp, or null if input is null.
fetchRegistration(UserIdentity $user)
Get user registration timestamp.string|false|null Registration timestamp (TS_MW), null if not availab...
__construct(UserFactory $userFactory, IConnectionProvider $connectionProvider)
fetchRegistrationBatch(iterable $users)
Get user registration timestamps for a batch of users.1.44 string[]|null[] Map of registration timest...
Create User objects.
Interface for objects representing user identity.
Provide primary and replica IDatabase connections.