* @file
*/
+use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\LoadBalancer;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\DBConnRef;
use Wikimedia\Rdbms\MaintainableDBConnRef;
/**
- * DB accessable external objects.
+ * DB accessible external objects.
*
* In this system, each store "location" maps to a database "cluster".
* The clusters must be defined in the normal LBFactory configuration.
return "DB://$location/$id";
}
+ public function isReadOnly( $location ) {
+ return ( $this->getLoadBalancer( $location )->getReadOnlyReason() !== false );
+ }
+
/**
* Get a LoadBalancer for the specified cluster
*
* @return LoadBalancer
*/
private function getLoadBalancer( $cluster ) {
- return wfGetLBFactory()->getExternalLB( $cluster );
+ $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ return $lbFactory->getExternalLB( $cluster );
}
/**
public function getSlave( $cluster ) {
global $wgDefaultExternalStore;
- $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false;
+ $wiki = $this->params['wiki'] ?? false;
$lb = $this->getLoadBalancer( $cluster );
if ( !in_array( "DB://" . $cluster, (array)$wgDefaultExternalStore ) ) {
* @return MaintainableDBConnRef
*/
public function getMaster( $cluster ) {
- $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : false;
+ $wiki = $this->params['wiki'] ?? false;
$lb = $this->getLoadBalancer( $cluster );
$db = $lb->getMaintenanceConnectionRef( DB_MASTER, [], $wiki );
return [
$path[2], // cluster
$path[3], // id
- isset( $path[4] ) ? $path[4] : false // itemID
+ $path[4] ?? false // itemID
];
}
}