示例#1
0
	/**
	 * Helper function: Add a key to the updatelog table
	 * Obviously, only use this for updates that occur after the updatelog table was
	 * created!
	 * @param string $key Name of key to insert
	 * @param string $val [optional] value to insert along with the key
	 */
	public function insertUpdateRow( $key, $val = null ) {
		$this->db->clearFlag( DBO_DDLMODE );
		$values = array( 'ul_key' => $key );
		if ( $val && $this->canUseNewUpdatelog() ) {
			$values['ul_value'] = $val;
		}
		$this->db->insert( 'updatelog', $values, __METHOD__, 'IGNORE' );
		$this->db->setFlag( DBO_DDLMODE );
	}
 /**
  * Get a master connection to the logging DB
  *
  * @return DatabaseBase
  * @throws DBError
  */
 protected function getMasterDB()
 {
     if (!$this->dbw) {
         // Get a separate connection in autocommit mode
         $lb = wfGetLBFactory()->newMainLB();
         $this->dbw = $lb->getConnection(DB_MASTER, array(), $this->wiki);
         $this->dbw->clearFlag(DBO_TRX);
     }
     return $this->dbw;
 }
 /**
  * Connect to the database using the administrative user/password currently
  * defined in the session. Returns a status object. On success, the status
  * object will contain a Database object in its value member.
  *
  * This will return a cached connection if one is available.
  *
  * @return Status
  */
 public function getConnection()
 {
     if ($this->db) {
         return Status::newGood($this->db);
     }
     $status = $this->openConnection();
     if ($status->isOK()) {
         $this->db = $status->value;
         // Enable autocommit
         $this->db->clearFlag(DBO_TRX);
         $this->db->commit(__METHOD__);
     }
     return $status;
 }
示例#4
0
 /**
  * @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;
 }
示例#5
0
 /**
  * @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;
 }