require_once __DIR__ . '/Maintenance.php';
+use MediaWiki\MediaWikiServices;
+
/**
* Maintenance script that reports the hostname of a replica DB server.
*
* @ingroup Maintenance
*/
-class GetSlaveServer extends Maintenance {
+class GetReplicaServer extends Maintenance {
public function __construct() {
parent::__construct();
$this->addOption( "group", "Query group to check specifically" );
}
public function execute() {
- global $wgAllDBsAreLocalhost;
- if ( $wgAllDBsAreLocalhost ) {
- $host = 'localhost';
- } elseif ( $this->hasOption( 'group' ) ) {
+ if ( $this->hasOption( 'group' ) ) {
$db = $this->getDB( DB_REPLICA, $this->getOption( 'group' ) );
$host = $db->getServer();
} else {
- $lb = wfGetLB();
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
$i = $lb->getReaderIndex();
$host = $lb->getServerName( $i );
}
}
}
-$maintClass = "GetSlaveServer";
+$maintClass = GetReplicaServer::class;
require_once RUN_MAINTENANCE_IF_MAIN;