Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LogIPInfoAccessJob | |
100.00% |
21 / 21 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | namespace MediaWiki\IPInfo\Jobs; |
4 | |
5 | use Job; |
6 | use MediaWiki\MediaWikiServices; |
7 | |
8 | /** |
9 | * Log when a user access information about an ip |
10 | */ |
11 | class LogIPInfoAccessJob extends Job { |
12 | /** |
13 | * @inheritDoc |
14 | */ |
15 | public function __construct( $title, $params ) { |
16 | parent::__construct( 'ipinfoLogIPInfoAccess', $params ); |
17 | } |
18 | |
19 | /** |
20 | * @return bool |
21 | */ |
22 | public function run() { |
23 | $performer = MediaWikiServices::getInstance()->getUserIdentityLookup() |
24 | ->getUserIdentityByName( $this->params['performer'] ); |
25 | $ip = $this->params['ip']; |
26 | $timestamp = $this->params['timestamp']; |
27 | $level = $this->params['access_level']; |
28 | |
29 | if ( !$performer ) { |
30 | $this->setLastError( 'Invalid performer' ); |
31 | return false; |
32 | } |
33 | |
34 | $factory = MediaWikiServices::getInstance()->get( 'IPInfoLoggerFactory' ); |
35 | $logger = $factory->getLogger(); |
36 | |
37 | switch ( $this->params['dataContext'] ) { |
38 | case 'infobox': |
39 | $logger->logViewInfobox( $performer, $ip, $timestamp, $level ); |
40 | break; |
41 | case 'popup': |
42 | $logger->logViewPopup( $performer, $ip, $timestamp, $level ); |
43 | break; |
44 | default: |
45 | $this->setLastError( 'Invalid dataContext: ' . $this->params['dataContext'] ); |
46 | return false; |
47 | } |
48 | return true; |
49 | } |
50 | } |