Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
TranslationUnitStoreFactory | |
0.00% |
0 / 9 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getReader | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getWriter | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\PageTranslation; |
5 | |
6 | use LogicException; |
7 | use MediaWiki\Page\PageIdentity; |
8 | use Wikimedia\Rdbms\ILoadBalancer; |
9 | use const DB_PRIMARY; |
10 | use const DB_REPLICA; |
11 | |
12 | /** |
13 | * @author Niklas Laxström |
14 | * @license GPL-2.0-or-later |
15 | * @since 2021.05 |
16 | */ |
17 | class TranslationUnitStoreFactory { |
18 | private ILoadBalancer $lb; |
19 | |
20 | public function __construct( ILoadBalancer $lb ) { |
21 | $this->lb = $lb; |
22 | } |
23 | |
24 | public function getReader( PageIdentity $page ): TranslationUnitReader { |
25 | $pageId = $page->getId(); |
26 | if ( $pageId === 0 ) { |
27 | throw new LogicException( 'Page must exist' ); |
28 | } |
29 | |
30 | return new TranslationUnitStore( $this->lb->getConnection( DB_REPLICA ), $pageId ); |
31 | } |
32 | |
33 | public function getWriter( PageIdentity $page ): TranslationUnitStore { |
34 | $pageId = $page->getId(); |
35 | if ( $pageId === 0 ) { |
36 | throw new LogicException( 'Page must exist' ); |
37 | } |
38 | |
39 | return new TranslationUnitStore( $this->lb->getConnection( DB_PRIMARY ), $pageId ); |
40 | } |
41 | } |