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