Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
GetPostId
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
12
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
 getParamSettings
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\MathSearch\Rest\ArqTask;
4
5use MediaWiki\Rest\SimpleHandler;
6use Wikimedia\ParamValidator\ParamValidator;
7use Wikimedia\Rdbms\DBConnRef;
8use Wikimedia\Rdbms\ILoadBalancer;
9
10class GetPostId extends SimpleHandler {
11
12    /** @var DBConnRef */
13    private $dbr;
14
15    public function __construct( ILoadBalancer $lb ) {
16        $this->dbr = $lb->getConnectionRef( DB_REPLICA );
17    }
18
19    public function getParamSettings() {
20        return [
21            'fId' => [
22                self::PARAM_SOURCE => 'path',
23                ParamValidator::PARAM_TYPE => 'integer',
24                ParamValidator::PARAM_REQUIRED => true,
25            ],
26        ];
27    }
28
29    public function run( int $fId ) {
30        // Example query:
31        //SELECT t.math_body, m.math_external_id, m.math_local_qid
32        //FROM wiki_arqmath20.math_wbs_text_store t, math_wbs_entity_map m
33        //WHERE math_body LIKE '% id=\'238553\'%' and m.math_local_qid = t.math_local_qid;
34        return $this->dbr->selectRow(
35            [
36                'm' => 'math_wbs_entity_map',
37                't' => 'math_wbs_text_store',
38            ],
39            [
40                'm.math_external_id',
41                'm.math_local_qid'
42            ],
43            [
44                "t.math_body LIKE '% id=\\'{$fId}\\'%'",
45                'm.math_local_qid = t.math_local_qid'
46            ]
47        );
48    }
49
50}