Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EditCountListener
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 onAfterInsert
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace Flow\Data\Listener;
4
5use Flow\Exception\InvalidDataException;
6use Flow\FlowActions;
7use Flow\Model\AbstractRevision;
8use MediaWiki\MediaWikiServices;
9
10class EditCountListener extends AbstractListener {
11    /**
12     * @var FlowActions
13     */
14    protected $actions;
15
16    public function __construct( FlowActions $actions ) {
17        $this->actions = $actions;
18    }
19
20    public function onAfterInsert( $revision, array $new, array $metadata ) {
21        if ( !$revision instanceof AbstractRevision ) {
22            throw new InvalidDataException( 'EditCountListener can only attach to AbstractRevision storage' );
23        }
24
25        $action = $revision->getChangeType();
26        $increase = $this->actions->getValue( $action, 'editcount' );
27
28        if ( $increase ) {
29            MediaWikiServices::getInstance()->getUserEditTracker()
30                ->incrementUserEditCount( $revision->getUser() );
31        }
32    }
33}