MediaWiki  master
ForeignDBRepo.php
Go to the documentation of this file.
1 <?php
28 
34 class ForeignDBRepo extends LocalRepo {
36  protected $dbType;
37 
39  protected $dbServer;
40 
42  protected $dbUser;
43 
45  protected $dbPassword;
46 
48  protected $dbName;
49 
51  protected $dbFlags;
52 
54  protected $tablePrefix;
55 
57  protected $dbConn;
58 
60  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
62  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
63 
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 
100  protected function getDBFactory() {
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  return Database::factory( $type, $params );
113  };
114  }
115 
116  protected function assertWritableRepo() {
117  throw new MWException( static::class . ': write operations are not supported.' );
118  }
119 
126  public function getInfo() {
127  return FileRepo::getInfo();
128  }
129 
130  public function getBlobStore(): ?BlobStore {
131  return null;
132  }
133 }
ForeignDBRepo\$dbUser
string $dbUser
Definition: ForeignDBRepo.php:42
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:52
ForeignDBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBRepo.php:100
ForeignDBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBRepo.php:126
ForeignDBRepo\$dbName
string $dbName
Definition: ForeignDBRepo.php:48
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1983
ForeignDBRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: ForeignDBRepo.php:93
ForeignDBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBRepo.php:116
ForeignDBRepo\$fileFactory
callable $fileFactory
Definition: ForeignDBRepo.php:60
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ForeignDBRepo\$dbServer
string $dbServer
Definition: ForeignDBRepo.php:39
ForeignDBRepo\$dbConn
IDatabase $dbConn
Definition: ForeignDBRepo.php:57
MWException
MediaWiki exception.
Definition: MWException.php:29
ForeignDBRepo\$dbPassword
string $dbPassword
Definition: ForeignDBRepo.php:45
ForeignDBRepo\getPrimaryDB
getPrimaryDB()
Get a connection to the primary DB.
Definition: ForeignDBRepo.php:84
ForeignDBRepo\$tablePrefix
string $tablePrefix
Definition: ForeignDBRepo.php:54
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
ForeignDBRepo
A foreign repository with an accessible MediaWiki database.
Definition: ForeignDBRepo.php:34
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition: BlobStore.php:35
ForeignDBRepo\getBlobStore
getBlobStore()
Get a BlobStore for storing and retrieving large metadata, or null if that can't be done.
Definition: ForeignDBRepo.php:130
ForeignDBRepo\$dbType
string $dbType
Definition: ForeignDBRepo.php:36
ForeignDBRepo\$dbFlags
string $dbFlags
Definition: ForeignDBRepo.php:51
ForeignDBRepo\__construct
__construct( $info)
Definition: ForeignDBRepo.php:67
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/schema/prefix specifications for IDatabase.
Definition: DatabaseDomain.php:40
ForeignDBRepo\$fileFromRowFactory
callable $fileFromRowFactory
Definition: ForeignDBRepo.php:62
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:41
LocalRepo\$dbDomain
string $dbDomain
DB domain of the repo wiki.
Definition: LocalRepo.php:56
$type
$type
Definition: testCompression.php:52