| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\MediaWikiServices; |
| 22 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
class ForeignDBViaLBRepo extends LocalRepo implements IForeignRepoWithDB { |
| 30 |
|
| 31 |
protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ]; |
| 32 |
|
| 33 |
|
| 34 |
protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ]; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function __construct( $info ) { |
| 40 |
parent::__construct( $info ); |
| 41 |
'@phan-var array $info'; |
| 42 |
$this->dbDomain = $info['wiki']; |
| 43 |
$this->hasAccessibleSharedCache = $info['hasSharedCache']; |
| 44 |
} |
| 45 |
|
| 46 |
public function getPrimaryDB() { |
| 47 |
return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain ); |
| 48 |
} |
| 49 |
|
| 50 |
public function getReplicaDB() { |
| 51 |
return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain ); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
protected function getDBFactory() { |
| 58 |
return function ( $index ) { |
| 59 |
if ( $index == DB_PRIMARY ) { |
| 60 |
return $this->getDbProvider()->getPrimaryDatabase( $this->dbDomain ); |
| 61 |
} else { |
| 62 |
return $this->getDbProvider()->getReplicaDatabase( $this->dbDomain ); |
| 63 |
} |
| 64 |
}; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
protected function getDbProvider(): IConnectionProvider { |
| 71 |
return MediaWikiServices::getInstance()->getConnectionProvider(); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
protected function assertWritableRepo() { |
| 78 |
throw new LogicException( static::class . ': write operations are not supported.' ); |
| 79 |
} |
| 80 |
|
| 81 |
public function getInfo() { |
| 82 |
return FileRepo::getInfo(); |
| 83 |
} |
| 84 |
} |