MediaWiki  master
ForeignDBRepo.php
Go to the documentation of this file.
1 <?php
27 
33 class ForeignDBRepo extends LocalRepo {
35  protected $dbType;
36 
38  protected $dbServer;
39 
41  protected $dbUser;
42 
44  protected $dbPassword;
45 
47  protected $dbName;
48 
50  protected $dbFlags;
51 
53  protected $tablePrefix;
54 
56  protected $dbConn;
57 
59  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
61  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
62 
66  public function __construct( $info ) {
67  parent::__construct( $info );
68 
69  '@phan-var array $info';
70  $this->dbType = $info['dbType'];
71  $this->dbServer = $info['dbServer'];
72  $this->dbUser = $info['dbUser'];
73  $this->dbPassword = $info['dbPassword'];
74  $this->dbName = $info['dbName'];
75  $this->dbFlags = $info['dbFlags'];
76  $this->tablePrefix = $info['tablePrefix'];
77  $this->hasAccessibleSharedCache = $info['hasSharedCache'];
78 
79  $dbDomain = new DatabaseDomain( $this->dbName, null, $this->tablePrefix );
80  $this->dbDomain = $dbDomain->getId();
81  }
82 
83  public function getMasterDB() {
84  if ( !isset( $this->dbConn ) ) {
85  $func = $this->getDBFactory();
86  $this->dbConn = $func( DB_MASTER );
87  }
88 
89  return $this->dbConn;
90  }
91 
92  public function getReplicaDB() {
93  return $this->getMasterDB();
94  }
95 
99  protected function getDBFactory() {
101  $params = [
102  'host' => $this->dbServer,
103  'user' => $this->dbUser,
104  'password' => $this->dbPassword,
105  'dbname' => $this->dbName,
106  'flags' => $this->dbFlags,
107  'tablePrefix' => $this->tablePrefix
108  ];
109 
110  return static function ( $index ) use ( $type, $params ) {
111  return Database::factory( $type, $params );
112  };
113  }
114 
115  protected function assertWritableRepo() {
116  throw new MWException( static::class . ': write operations are not supported.' );
117  }
118 
125  public function getInfo() {
126  return FileRepo::getInfo();
127  }
128 }
ForeignDBRepo\$dbUser
string $dbUser
Definition: ForeignDBRepo.php:41
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:50
ForeignDBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBRepo.php:99
ForeignDBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBRepo.php:125
ForeignDBRepo\$dbName
string $dbName
Definition: ForeignDBRepo.php:47
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1986
ForeignDBRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: ForeignDBRepo.php:92
ForeignDBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBRepo.php:115
ForeignDBRepo\$fileFactory
callable $fileFactory
Definition: ForeignDBRepo.php:59
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:38
ForeignDBRepo\$dbConn
IDatabase $dbConn
Definition: ForeignDBRepo.php:56
MWException
MediaWiki exception.
Definition: MWException.php:29
ForeignDBRepo\$dbPassword
string $dbPassword
Definition: ForeignDBRepo.php:44
DB_MASTER
const DB_MASTER
Definition: defines.php:26
ForeignDBRepo\$tablePrefix
string $tablePrefix
Definition: ForeignDBRepo.php:53
ForeignDBRepo
A foreign repository with an accessible MediaWiki database.
Definition: ForeignDBRepo.php:33
ForeignDBRepo\getMasterDB
getMasterDB()
Get a connection to the master DB.
Definition: ForeignDBRepo.php:83
ForeignDBRepo\$dbType
string $dbType
Definition: ForeignDBRepo.php:35
ForeignDBRepo\$dbFlags
string $dbFlags
Definition: ForeignDBRepo.php:50
ForeignDBRepo\__construct
__construct( $info)
Definition: ForeignDBRepo.php:66
Wikimedia\Rdbms\DatabaseDomain
Class to handle database/schema/prefix specifications for IDatabase.
Definition: DatabaseDomain.php:40
ForeignDBRepo\$fileFromRowFactory
callable $fileFromRowFactory
Definition: ForeignDBRepo.php:61
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:37
LocalRepo\$dbDomain
string $dbDomain
DB domain of the repo wiki.
Definition: LocalRepo.php:52
$type
$type
Definition: testCompression.php:52