Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
QueueLookup
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getByPageId
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
2
 newFromRow
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace MediaWiki\Extension\PageTriage;
4
5use stdClass;
6use Wikimedia\Rdbms\IConnectionProvider;
7
8/**
9 * Service class for retrieving PageTriage queue records.
10 */
11class QueueLookup {
12
13    /** @var IConnectionProvider */
14    private IConnectionProvider $dbProvider;
15
16    /**
17     * @param IConnectionProvider $dbProvider
18     */
19    public function __construct( IConnectionProvider $dbProvider ) {
20        $this->dbProvider = $dbProvider;
21    }
22
23    /**
24     * @param int $pageId
25     * @return QueueRecord|null
26     */
27    public function getByPageId( int $pageId ): ?QueueRecord {
28        $dbr = $this->dbProvider->getReplicaDatabase();
29        $row = $dbr->newSelectQueryBuilder()
30            ->select( [
31                'ptrp_page_id',
32                'ptrp_reviewed',
33                'ptrp_created',
34                'ptrp_deleted',
35                'ptrp_tags_updated',
36                'ptrp_reviewed_updated',
37                'ptrp_last_reviewed_by',
38            ] )
39            ->from( 'pagetriage_page' )
40            ->where( [ 'ptrp_page_id' => $pageId ] )
41            ->caller( __METHOD__ )
42            ->fetchRow();
43
44        if ( !$row ) {
45            return null;
46        }
47        return $this->newFromRow( $row );
48    }
49
50    /**
51     * @param stdClass $row
52     * @return QueueRecord
53     */
54    private function newFromRow( stdClass $row ): QueueRecord {
55        return new QueueRecord(
56            $row->ptrp_page_id,
57            $row->ptrp_reviewed,
58            // '0' casts to false so this will work as expected.
59            (bool)$row->ptrp_deleted,
60            $row->ptrp_created,
61            $row->ptrp_tags_updated,
62            $row->ptrp_reviewed_updated,
63            $row->ptrp_last_reviewed_by
64        );
65    }
66
67}