Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslationUnitStoreFactory.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use LogicException;
7use Title;
8use Wikimedia\Rdbms\ILoadBalancer;
9use const DB_PRIMARY;
10use const DB_REPLICA;
11
19 private $lb;
20
21 public function __construct( ILoadBalancer $lb ) {
22 $this->lb = $lb;
23 }
24
25 public function getReader( Title $page ): TranslationUnitReader {
26 $pageId = $page->getArticleID();
27 if ( $pageId === 0 ) {
28 throw new LogicException( 'Page must exist' );
29 }
30
31 return new TranslationUnitStore( $this->lb->getConnectionRef( DB_REPLICA ), $pageId );
32 }
33
34 public function getWriter( Title $page ): TranslationUnitStore {
35 $pageId = $page->getArticleID();
36 if ( $pageId === 0 ) {
37 throw new LogicException( 'Page must exist' );
38 }
39
40 return new TranslationUnitStore( $this->lb->getConnectionRef( DB_PRIMARY ), $pageId );
41 }
42}