Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
NewcomerTasksLogFactory | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getQueryBuilder | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks; |
4 | |
5 | use DateTime; |
6 | use MediaWiki\User\Options\UserOptionsLookup; |
7 | use MediaWiki\User\UserIdentity; |
8 | use MediaWiki\User\UserTimeCorrection; |
9 | use MediaWiki\Utils\MWTimestamp; |
10 | use Wikimedia\Rdbms\IConnectionProvider; |
11 | use Wikimedia\Rdbms\SelectQueryBuilder; |
12 | |
13 | class NewcomerTasksLogFactory { |
14 | |
15 | private IConnectionProvider $connectionProvider; |
16 | private UserOptionsLookup $userOptionsLookup; |
17 | |
18 | /** |
19 | * @param IConnectionProvider $connectionProvider |
20 | * @param UserOptionsLookup $userOptionsLookup |
21 | */ |
22 | public function __construct( IConnectionProvider $connectionProvider, UserOptionsLookup $userOptionsLookup ) { |
23 | $this->connectionProvider = $connectionProvider; |
24 | $this->userOptionsLookup = $userOptionsLookup; |
25 | } |
26 | |
27 | protected function getQueryBuilder( UserIdentity $user, string $logAction ): SelectQueryBuilder { |
28 | // We want to know if the user made edits during the current day for that user. |
29 | // The log_timestamp is saved in the database using UTC timezone, so we need to get the |
30 | // current day for the user, get a timestamp for the local midnight for that date, then |
31 | // get the UNIX timestamp and convert it to MW format for use in the query. |
32 | $userTimeCorrection = new UserTimeCorrection( |
33 | $this->userOptionsLookup->getOption( $user, 'timecorrection' ) |
34 | ); |
35 | $localMidnight = new DateTime( 'T00:00', $userTimeCorrection->getTimeZone() ); |
36 | $utcTimestamp = MWTimestamp::convert( TS_MW, $localMidnight->getTimestamp() ); |
37 | |
38 | $dbr = $this->connectionProvider->getReplicaDatabase(); |
39 | return $dbr->newSelectQueryBuilder() |
40 | ->select( [ 'log_action' ] ) |
41 | ->from( 'logging' ) |
42 | ->where( [ |
43 | 'log_type' => 'growthexperiments', |
44 | 'log_action' => $logAction, |
45 | 'actor_name' => $user->getName(), |
46 | $dbr->buildComparison( '>', [ 'log_timestamp' => $utcTimestamp ] ) |
47 | ] ) |
48 | ->join( 'actor', null, 'log_actor=actor_id' ); |
49 | } |
50 | } |