| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
use MediaWiki\MediaWikiServices; |
| 25 |
use MediaWiki\Storage\BlobStore; |
| 26 |
use Wikimedia\Rdbms\DatabaseDomain; |
| 27 |
use Wikimedia\Rdbms\IDatabase; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class ForeignDBRepo extends LocalRepo implements IForeignRepoWithDB { |
| 35 |
|
| 36 |
protected $dbType; |
| 37 |
|
| 38 |
|
| 39 |
protected $dbServer; |
| 40 |
|
| 41 |
|
| 42 |
protected $dbUser; |
| 43 |
|
| 44 |
|
| 45 |
protected $dbPassword; |
| 46 |
|
| 47 |
|
| 48 |
protected $dbName; |
| 49 |
|
| 50 |
|
| 51 |
protected $dbFlags; |
| 52 |
|
| 53 |
|
| 54 |
protected $tablePrefix; |
| 55 |
|
| 56 |
|
| 57 |
protected $dbConn; |
| 58 |
|
| 59 |
|
| 60 |
protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ]; |
| 61 |
|
| 62 |
protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ]; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public function __construct( $info ) { |
| 68 |
parent::__construct( $info ); |
| 69 |
|
| 70 |
'@phan-var array $info'; |
| 71 |
$this->dbType = $info['dbType']; |
| 72 |
$this->dbServer = $info['dbServer']; |
| 73 |
$this->dbUser = $info['dbUser']; |
| 74 |
$this->dbPassword = $info['dbPassword']; |
| 75 |
$this->dbName = $info['dbName']; |
| 76 |
$this->dbFlags = $info['dbFlags']; |
| 77 |
$this->tablePrefix = $info['tablePrefix']; |
| 78 |
$this->hasAccessibleSharedCache = $info['hasSharedCache']; |
| 79 |
|
| 80 |
$dbDomain = new DatabaseDomain( $this->dbName, null, $this->tablePrefix ); |
| 81 |
$this->dbDomain = $dbDomain->getId(); |
| 82 |
} |
| 83 |
|
| 84 |
public function getPrimaryDB() { |
| 85 |
if ( !isset( $this->dbConn ) ) { |
| 86 |
$func = $this->getDBFactory(); |
| 87 |
$this->dbConn = $func( DB_PRIMARY ); |
| 88 |
} |
| 89 |
|
| 90 |
return $this->dbConn; |
| 91 |
} |
| 92 |
|
| 93 |
public function getReplicaDB() { |
| 94 |
return $this->getPrimaryDB(); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
protected function getDBFactory() { |
| 101 |
$type = $this->dbType; |
| 102 |
$params = [ |
| 103 |
'host' => $this->dbServer, |
| 104 |
'user' => $this->dbUser, |
| 105 |
'password' => $this->dbPassword, |
| 106 |
'dbname' => $this->dbName, |
| 107 |
'flags' => $this->dbFlags, |
| 108 |
'tablePrefix' => $this->tablePrefix |
| 109 |
]; |
| 110 |
|
| 111 |
return static function ( $index ) use ( $type, $params ) { |
| 112 |
$factory = MediaWikiServices::getInstance()->getDatabaseFactory(); |
| 113 |
return $factory->create( $type, $params ); |
| 114 |
}; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
protected function assertWritableRepo() { |
| 121 |
throw new LogicException( static::class . ': write operations are not supported.' ); |
| 122 |
} |
| 123 |
|
| 124 |
public function getBlobStore(): ?BlobStore { |
| 125 |
return null; |
| 126 |
} |
| 127 |
} |