Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
20.00% |
2 / 10 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
EventLogger | |
20.00% |
2 / 10 |
|
66.67% |
2 / 3 |
12.19 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
logEvent | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\CheckUser\Investigate\Utilities; |
4 | |
5 | use ExtensionRegistry; |
6 | use MediaWiki\Extension\EventLogging\EventLogging; |
7 | use Wikimedia\Timestamp\ConvertibleTimestamp; |
8 | |
9 | class EventLogger { |
10 | private ExtensionRegistry $extensionRegistry; |
11 | |
12 | /** |
13 | * @param ExtensionRegistry $extensionRegistry |
14 | */ |
15 | public function __construct( |
16 | ExtensionRegistry $extensionRegistry |
17 | ) { |
18 | $this->extensionRegistry = $extensionRegistry; |
19 | } |
20 | |
21 | /** |
22 | * If the EventLogging extension is loaded, then submit an analytics event to the event |
23 | * ingestion service. |
24 | * |
25 | * The event will be validated using the /analytics/legacy/specialinvestigate schema. |
26 | * |
27 | * @param array $event |
28 | */ |
29 | public function logEvent( $event ): void { |
30 | if ( $this->extensionRegistry->isLoaded( 'EventLogging' ) ) { |
31 | EventLogging::submit( |
32 | 'eventlogging_SpecialInvestigate', |
33 | [ |
34 | '$schema' => '/analytics/legacy/specialinvestigate/1.0.0', |
35 | 'event' => $event, |
36 | ] |
37 | ); |
38 | } |
39 | } |
40 | |
41 | /** |
42 | * Get a timestamp in milliseconds. |
43 | * |
44 | * @return int |
45 | */ |
46 | public function getTime(): int { |
47 | return (int)round( ConvertibleTimestamp::microtime() * 1000 ); |
48 | } |
49 | } |