function __call($name, array $arguments) { if ($this->conn === null) { list($db, $groups, $wiki) = $this->params; $this->conn = $this->lb->getConnection($db, $groups, $wiki); } return call_user_func_array(array($this->conn, $name), $arguments); }
/** * Clears the list of sites stored in the database. * * @see SiteStore::clear() * * @return bool Success */ public function clear() { $dbw = $this->dbLoadBalancer->getConnection(DB_MASTER); $dbw->startAtomic(__METHOD__); $ok = $dbw->delete('sites', '*', __METHOD__); $ok = $dbw->delete('site_identifiers', '*', __METHOD__) && $ok; $dbw->endAtomic(__METHOD__); $this->reset(); return $ok; }
/** * @return DatabaseBase */ protected function getDB() { if (!isset($this->db)) { # If server connection info was given, use that if ($this->serverInfo) { $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo))); $this->db = $this->lb->getConnection(DB_MASTER); $this->db->clearFlag(DBO_TRX); } else { # We must keep a separate connection to MySQL in order to avoid deadlocks # However, SQLite has an opposite behaviour. # @todo Investigate behaviour for other databases if (wfGetDB(DB_MASTER)->getType() == 'sqlite') { $this->db = wfGetDB(DB_MASTER); } else { $this->lb = wfGetLBFactory()->newMainLB(); $this->db = $this->lb->getConnection(DB_MASTER); $this->db->clearFlag(DBO_TRX); } } } return $this->db; }
/** * Get a connection to the specified database * * @param $serverIndex integer * @return DatabaseBase */ protected function getDB( $serverIndex ) { global $wgDebugDBTransactions; if ( !isset( $this->conns[$serverIndex] ) ) { if ( $serverIndex >= $this->numServers ) { throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" ); } # Don't keep timing out trying to connect for each call if the DB is down if ( isset( $this->connFailureErrors[$serverIndex] ) && ( time() - $this->connFailureTimes[$serverIndex] ) < 60 ) { throw $this->connFailureErrors[$serverIndex]; } # If server connection info was given, use that if ( $this->serverInfos ) { if ( $wgDebugDBTransactions ) { wfDebug( "Using provided serverInfo for SqlBagOStuff\n" ); } $info = $this->serverInfos[$serverIndex]; $type = isset( $info['type'] ) ? $info['type'] : 'mysql'; $host = isset( $info['host'] ) ? $info['host'] : '[unknown]'; wfDebug( __CLASS__ . ": connecting to $host\n" ); $db = DatabaseBase::factory( $type, $info ); $db->clearFlag( DBO_TRX ); } else { /* * We must keep a separate connection to MySQL in order to avoid deadlocks * However, SQLite has an opposite behavior. And PostgreSQL needs to know * if we are in transaction or no */ if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) { $this->lb = wfGetLBFactory()->newMainLB(); $db = $this->lb->getConnection( DB_MASTER ); $db->clearFlag( DBO_TRX ); // auto-commit mode } else { $db = wfGetDB( DB_MASTER ); } } if ( $wgDebugDBTransactions ) { wfDebug( sprintf( "Connection %s will be used for SqlBagOStuff\n", $db ) ); } $this->conns[$serverIndex] = $db; } return $this->conns[$serverIndex]; }
/** * Get a connection to the specified database * * @param int $serverIndex * @return IDatabase * @throws MWException */ protected function getDB($serverIndex) { if (!isset($this->conns[$serverIndex])) { if ($serverIndex >= $this->numServers) { throw new MWException(__METHOD__ . ": Invalid server index \"{$serverIndex}\""); } # Don't keep timing out trying to connect for each call if the DB is down if (isset($this->connFailureErrors[$serverIndex]) && time() - $this->connFailureTimes[$serverIndex] < 60) { throw $this->connFailureErrors[$serverIndex]; } # If server connection info was given, use that if ($this->serverInfos) { $info = $this->serverInfos[$serverIndex]; $type = isset($info['type']) ? $info['type'] : 'mysql'; $host = isset($info['host']) ? $info['host'] : '[unknown]'; $this->logger->debug(__CLASS__ . ": connecting to {$host}"); // Use a blank trx profiler to ignore expections as this is a cache $info['trxProfiler'] = new TransactionProfiler(); $db = DatabaseBase::factory($type, $info); $db->clearFlag(DBO_TRX); } else { /* * We must keep a separate connection to MySQL in order to avoid deadlocks * However, SQLite has an opposite behavior. And PostgreSQL needs to know * if we are in transaction or no */ $index = $this->slaveOnly ? DB_SLAVE : DB_MASTER; if (wfGetDB($index)->getType() == 'mysql') { $this->lb = wfGetLBFactory()->newMainLB(); $db = $this->lb->getConnection($index); $db->clearFlag(DBO_TRX); // auto-commit mode } else { $db = wfGetDB($index); } } $this->logger->debug(sprintf("Connection %s will be used for SqlBagOStuff", $db)); $this->conns[$serverIndex] = $db; } return $this->conns[$serverIndex]; }
/** * @return DatabaseBase */ protected function getDB() { global $wgDebugDBTransactions; # Don't keep timing out trying to connect for each call if the DB is down if ($this->connFailureError && time() - $this->connFailureTime < 60) { throw $this->connFailureError; } if (!isset($this->db)) { # If server connection info was given, use that if ($this->serverInfo) { if ($wgDebugDBTransactions) { wfDebug(sprintf("Using provided serverInfo for SqlBagOStuff\n")); } $this->lb = new LoadBalancer(array('servers' => array($this->serverInfo))); $this->db = $this->lb->getConnection(DB_MASTER); $this->db->clearFlag(DBO_TRX); } else { /* * We must keep a separate connection to MySQL in order to avoid deadlocks * However, SQLite has an opposite behaviour. And PostgreSQL needs to know * if we are in transaction or no */ if (wfGetDB(DB_MASTER)->getType() == 'mysql') { $this->lb = wfGetLBFactory()->newMainLB(); $this->db = $this->lb->getConnection(DB_MASTER); $this->db->clearFlag(DBO_TRX); // auto-commit mode } else { $this->db = wfGetDB(DB_MASTER); } } if ($wgDebugDBTransactions) { wfDebug(sprintf("Connection %s will be used for SqlBagOStuff\n", $this->db)); } } return $this->db; }
/** * @param int $slaveOrMaster DB_MASTER or DB_SLAVE * * @return DatabaseBase * @throws MWException */ private function getConnection($slaveOrMaster) { return $this->loadBalancer->getConnection($slaveOrMaster, ['watchlist']); }