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 MediaWiki\Page\PageIdentity;
8use Wikimedia\Rdbms\ILoadBalancer;
9use const DB_PRIMARY;
10use const DB_REPLICA;
11
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}