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 accesses information about an ip |
10 | */ |
11 | class LogIPInfoAccessJob extends Job { |
12 | /** @inheritDoc */ |
13 | public function __construct( $title, $params ) { |
14 | parent::__construct( 'ipinfoLogIPInfoAccess', $params ); |
15 | } |
16 | |
17 | /** |
18 | * @return bool |
19 | */ |
20 | public function run() { |
21 | $performer = MediaWikiServices::getInstance()->getUserIdentityLookup() |
22 | ->getUserIdentityByName( $this->params['performer'] ); |
23 | $ip = $this->params['ip']; |
24 | $timestamp = $this->params['timestamp']; |
25 | $level = $this->params['access_level']; |
26 | |
27 | if ( !$performer ) { |
28 | $this->setLastError( 'Invalid performer' ); |
29 | return false; |
30 | } |
31 | |
32 | $factory = MediaWikiServices::getInstance()->get( 'IPInfoLoggerFactory' ); |
33 | $logger = $factory->getLogger(); |
34 | |
35 | switch ( $this->params['dataContext'] ) { |
36 | case 'infobox': |
37 | $logger->logViewInfobox( $performer, $ip, $timestamp, $level ); |
38 | break; |
39 | case 'popup': |
40 | $logger->logViewPopup( $performer, $ip, $timestamp, $level ); |
41 | break; |
42 | default: |
43 | $this->setLastError( 'Invalid dataContext: ' . $this->params['dataContext'] ); |
44 | return false; |
45 | } |
46 | return true; |
47 | } |
48 | } |