cluster = $cluster; $this->wiki = $wiki; } /** * Create a db factory instance from default Echo configuration * DO NOT use singleton in here because job queue may run * against multiple wikis, having a singleton would result in * wrong db configuration. In addition, singleton is not necessary * because it's actually handled inside core database object * * @return MWEchoDbFactory */ public static function newFromDefault() { global $wgEchoCluster; return new self( $wgEchoCluster ); } /** * Get the database load balancer * @param $wiki string|bool The wiki ID, or false for the current wiki * @return LoadBalancer */ protected function getLB() { // Use the external db defined for Echo if ( $this->cluster ) { $lb = wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki ); } else { $lb = wfGetLB( $this->wiki ); } return $lb; } /** * Get the database connection for Echo * @param $db int Index of the connection to get * @param $groups mixed Query groups. * @return DatabaseBase */ public function getEchoDb( $db, $groups = array() ) { return $this->getLB()->getConnection( $db, $groups, $this->wiki ); } /** * Wrapper function for wfGetDB, some extensions like MobileFrontend is * using this to issue sql queries against Echo database directly. This * is totally not accepted and should be updated to use Echo database access * objects * * @deprecated Use newFromDefault() instead to create a db factory * @param $db int Index of the connection to get * @param $groups mixed Query groups. * @param $wiki string|bool The wiki ID, or false for the current wiki * @return DatabaseBase */ public static function getDB( $db, $groups = array(), $wiki = false ) { global $wgEchoCluster; // Use the external db defined for Echo if ( $wgEchoCluster ) { $lb = wfGetLBFactory()->getExternalLB( $wgEchoCluster, $wiki ); } else { $lb = wfGetLB( $wiki ); } return $lb->getConnection( $db, $groups, $wiki ); } /** * Wait for the slaves of the database */ public function waitForSlaves() { wfWaitForSlaves( false, $this->wiki, $this->cluster ); } }