Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
TranslationUnitStore | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getUnits | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
getNames | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
delete | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\PageTranslation; |
5 | |
6 | use Wikimedia\Rdbms\IDatabase; |
7 | |
8 | /** |
9 | * @author Niklas Laxström |
10 | * @license GPL-2.0-or-later |
11 | * @since 2021.05 |
12 | */ |
13 | class TranslationUnitStore implements TranslationUnitReader { |
14 | private const TABLE = 'translate_sections'; |
15 | private IDatabase $db; |
16 | private int $pageId; |
17 | |
18 | public function __construct( IDatabase $db, int $pageId ) { |
19 | $this->db = $db; |
20 | $this->pageId = $pageId; |
21 | } |
22 | |
23 | public function getUnits(): array { |
24 | $res = $this->db->newSelectQueryBuilder() |
25 | ->select( [ 'trs_key', 'trs_text' ] ) |
26 | ->from( self::TABLE ) |
27 | ->where( [ 'trs_page' => $this->pageId ] ) |
28 | ->caller( __METHOD__ ) |
29 | ->fetchResultSet(); |
30 | |
31 | $units = []; |
32 | foreach ( $res as $row ) { |
33 | $units[$row->trs_key] = new TranslationUnit( $row->trs_text, $row->trs_key ); |
34 | } |
35 | |
36 | return $units; |
37 | } |
38 | |
39 | /** @return string[] */ |
40 | public function getNames(): array { |
41 | return $this->db->newSelectQueryBuilder() |
42 | ->select( 'trs_key' ) |
43 | ->from( self::TABLE ) |
44 | ->where( [ 'trs_page' => $this->pageId ] ) |
45 | ->caller( __METHOD__ ) |
46 | ->fetchFieldValues(); |
47 | } |
48 | |
49 | public function delete(): void { |
50 | $this->db->newDeleteQueryBuilder() |
51 | ->deleteFrom( self::TABLE ) |
52 | ->where( [ 'trs_page' => $this->pageId ] ) |
53 | ->caller( __METHOD__ ) |
54 | ->execute(); |
55 | } |
56 | } |