/** * Handle a DBQueryError which occurred during a write operation. */ protected function handleWriteError(DBError $exception) { if ($exception instanceof DBConnectionError) { $this->connFailureTime = time(); $this->connFailureError = $exception; } if ($this->db && $this->db->wasReadOnlyError()) { try { $this->db->rollback(__METHOD__); } catch (DBError $e) { } } wfDebugLog('SQLBagOStuff', "DBError: {$exception->getMessage()}"); if ($this->db) { wfDebug(__METHOD__ . ": ignoring query error\n"); } else { wfDebug(__METHOD__ . ": ignoring connection error\n"); } }
public function startWrite($code) { if ($this->readOnly) { return; } if (!$code) { throw new MWException(__METHOD__ . ": Invalid language \"{$code}\""); } $this->dbw = wfGetDB(DB_MASTER); try { $this->dbw->begin(__METHOD__); $this->dbw->delete('l10n_cache', array('lc_lang' => $code), __METHOD__); } catch (DBQueryError $e) { if ($this->dbw->wasReadOnlyError()) { $this->readOnly = true; $this->dbw->rollback(__METHOD__); return; } else { throw $e; } } $this->currentLang = $code; $this->batch = array(); }
public function finishWrite() { if ($this->readOnly) { return; } elseif (is_null($this->currentLang)) { throw new MWException(__CLASS__ . ': must call startWrite() before finishWrite()'); } $this->dbw->begin(__METHOD__); try { $this->dbw->delete('l10n_cache', array('lc_lang' => $this->currentLang), __METHOD__); foreach (array_chunk($this->batch, 500) as $rows) { $this->dbw->insert('l10n_cache', $rows, __METHOD__); } $this->writesDone = true; } catch (DBQueryError $e) { if ($this->dbw->wasReadOnlyError()) { $this->readOnly = true; // just avoid site down time } else { throw $e; } } $this->dbw->commit(__METHOD__); $this->currentLang = null; $this->batch = array(); }