MediaWiki  1.32.0
ForeignDBViaLBRepo.php
Go to the documentation of this file.
1 <?php
27 
35  protected $wiki;
36 
38  protected $dbName;
39 
41  protected $tablePrefix;
42 
44  protected $fileFactory = [ ForeignDBFile::class, 'newFromTitle' ];
45 
47  protected $fileFromRowFactory = [ ForeignDBFile::class, 'newFromRow' ];
48 
50  protected $hasSharedCache;
51 
55  function __construct( $info ) {
56  parent::__construct( $info );
57  $this->wiki = $info['wiki'];
58  list( $this->dbName, $this->tablePrefix ) = wfSplitWikiID( $this->wiki );
59  $this->hasSharedCache = $info['hasSharedCache'];
60  }
61 
65  function getMasterDB() {
66  return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->wiki );
67  }
68 
72  function getReplicaDB() {
73  return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->wiki );
74  }
75 
79  protected function getDBFactory() {
80  return function ( $index ) {
81  return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki );
82  };
83  }
84 
88  protected function getDBLoadBalancer() {
89  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
90  return $lbFactory->getMainLB( $this->wiki );
91  }
92 
93  function hasSharedCache() {
94  return $this->hasSharedCache;
95  }
96 
103  function getSharedCacheKey( /*...*/ ) {
104  if ( $this->hasSharedCache() ) {
105  $args = func_get_args();
106  array_unshift( $args, $this->wiki );
107 
108  return implode( ':', $args );
109  } else {
110  return false;
111  }
112  }
113 
114  protected function assertWritableRepo() {
115  throw new MWException( static::class . ': write operations are not supported.' );
116  }
117 
118  public function getInfo() {
119  return FileRepo::getInfo();
120  }
121 }
ForeignDBViaLBRepo\getDBFactory
getDBFactory()
Definition: ForeignDBViaLBRepo.php:79
wiki
Prior to maintenance scripts were a hodgepodge of code that had no cohesion or formal method of action Beginning maintenance scripts have been cleaned up to use a unified class Directory structure How to run a script How to write your own DIRECTORY STRUCTURE The maintenance directory of a MediaWiki installation contains several all of which have unique purposes HOW TO RUN A SCRIPT Ridiculously just call php someScript php that s in the top level maintenance directory if not default wiki
Definition: maintenance.txt:1
FileRepo\getInfo
getInfo()
Return information about the repository.
Definition: FileRepo.php:1907
wfSplitWikiID
wfSplitWikiID( $wiki)
Split a wiki ID into DB name and table prefix.
Definition: GlobalFunctions.php:2660
ForeignDBViaLBRepo\$fileFromRowFactory
array $fileFromRowFactory
Definition: ForeignDBViaLBRepo.php:47
ForeignDBViaLBRepo\$wiki
string $wiki
Definition: ForeignDBViaLBRepo.php:35
ForeignDBViaLBRepo\$dbName
string $dbName
Definition: ForeignDBViaLBRepo.php:38
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
ForeignDBViaLBRepo\getInfo
getInfo()
Return information about the repository.
Definition: ForeignDBViaLBRepo.php:118
MWException
MediaWiki exception.
Definition: MWException.php:26
ForeignDBViaLBRepo
A foreign repository with a MediaWiki database accessible via the configured LBFactory.
Definition: ForeignDBViaLBRepo.php:33
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ForeignDBViaLBRepo\$tablePrefix
string $tablePrefix
Definition: ForeignDBViaLBRepo.php:41
ForeignDBViaLBRepo\$fileFactory
array $fileFactory
Definition: ForeignDBViaLBRepo.php:44
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
Wikimedia\Rdbms\LoadBalancer
Database connection, tracking, load balancing, and transaction manager for a cluster.
Definition: LoadBalancer.php:41
ForeignDBViaLBRepo\getReplicaDB
getReplicaDB()
Definition: ForeignDBViaLBRepo.php:72
ForeignDBViaLBRepo\$hasSharedCache
bool $hasSharedCache
Definition: ForeignDBViaLBRepo.php:50
ForeignDBViaLBRepo\getMasterDB
getMasterDB()
Definition: ForeignDBViaLBRepo.php:65
ForeignDBViaLBRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: ForeignDBViaLBRepo.php:114
ForeignDBViaLBRepo\getSharedCacheKey
getSharedCacheKey()
Get a key on the primary cache for this repository.
Definition: ForeignDBViaLBRepo.php:103
ForeignDBViaLBRepo\hasSharedCache
hasSharedCache()
Definition: ForeignDBViaLBRepo.php:93
$args
if( $line===false) $args
Definition: cdb.php:64
ForeignDBViaLBRepo\getDBLoadBalancer
getDBLoadBalancer()
Definition: ForeignDBViaLBRepo.php:88
ForeignDBViaLBRepo\__construct
__construct( $info)
Definition: ForeignDBViaLBRepo.php:55
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:36