/**
  * Create database tables from scratch.
  *
  * @return Status
  */
 public function createTables()
 {
     $status = $this->getConnection();
     if (!$status->isOK()) {
         return $status;
     }
     $this->db->selectDB($this->getVar('wgDBname'));
     if ($this->db->tableExists('archive', __METHOD__)) {
         $status->warning('config-install-tables-exist');
         $this->enableLB();
         return $status;
     }
     $this->db->setFlag(DBO_DDLMODE);
     // For Oracle's handling of schema files
     $this->db->begin(__METHOD__);
     $error = $this->db->sourceFile($this->db->getSchemaPath());
     if ($error !== true) {
         $this->db->reportQueryError($error, 0, '', __METHOD__);
         $this->db->rollback(__METHOD__);
         $status->fatal('config-install-tables-failed', $error);
     } else {
         $this->db->commit(__METHOD__);
     }
     // Resume normal operations
     if ($status->isOk()) {
         $this->enableLB();
     }
     return $status;
 }
 protected function tearDown()
 {
     wfProfileIn(__METHOD__);
     // Cleaning up temporary files
     foreach ($this->tmpfiles as $fname) {
         if (is_file($fname) || is_link($fname)) {
             unlink($fname);
         } elseif (is_dir($fname)) {
             wfRecursiveRemoveDir($fname);
         }
     }
     if ($this->needsDB() && $this->db) {
         // Clean up open transactions
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback();
         }
         // don't ignore DB errors
         $this->db->ignoreErrors(false);
     }
     // Restore mw globals
     foreach ($this->mwGlobals as $key => $value) {
         $GLOBALS[$key] = $value;
     }
     $this->mwGlobals = array();
     $phpErrorLevel = intval(ini_get('error_reporting'));
     if ($phpErrorLevel !== $this->phpErrorLevel) {
         ini_set('error_reporting', $this->phpErrorLevel);
         $oldHex = strtoupper(dechex($this->phpErrorLevel));
         $newHex = strtoupper(dechex($phpErrorLevel));
         $message = "PHP error_reporting setting was left dirty: was 0x{$oldHex} before test, 0x{$newHex} after test!";
         $this->fail($message);
     }
     parent::tearDown();
     wfProfileOut(__METHOD__);
 }
示例#3
0
 /**
  * Create the tables for each extension the user enabled
  * @return Status
  */
 public function createExtensionTables()
 {
     $status = $this->getConnection();
     if (!$status->isOK()) {
         return $status;
     }
     $updater = DatabaseUpdater::newForDB($this->db);
     $extensionUpdates = $updater->getNewExtensions();
     $ourExtensions = array_map('strtolower', $this->getVar('_Extensions'));
     foreach ($ourExtensions as $ext) {
         if (isset($extensionUpdates[$ext])) {
             $this->db->begin(__METHOD__);
             $error = $this->db->sourceFile($extensionUpdates[$ext]);
             if ($error !== true) {
                 $this->db->rollback(__METHOD__);
                 $status->warning('config-install-tables-failed', $error);
             } else {
                 $this->db->commit(__METHOD__);
             }
         }
     }
     // Now run updates to create tables for old extensions
     $updater->doUpdates(array('extensions'));
     return $status;
 }
 /**
  * Apply a SQL source file to the database as part of running an installation step.
  *
  * @param string $sourceFileMethod
  * @param string $stepName
  * @param string $archiveTableMustNotExist
  * @return Status
  */
 private function stepApplySourceFile($sourceFileMethod, $stepName, $archiveTableMustNotExist = false)
 {
     $status = $this->getConnection();
     if (!$status->isOK()) {
         return $status;
     }
     $this->db->selectDB($this->getVar('wgDBname'));
     if ($archiveTableMustNotExist && $this->db->tableExists('archive', __METHOD__)) {
         $status->warning("config-{$stepName}-tables-exist");
         $this->enableLB();
         return $status;
     }
     $this->db->setFlag(DBO_DDLMODE);
     // For Oracle's handling of schema files
     $this->db->begin(__METHOD__);
     $error = $this->db->sourceFile(call_user_func(array($this->db, $sourceFileMethod)));
     if ($error !== true) {
         $this->db->reportQueryError($error, 0, '', __METHOD__);
         $this->db->rollback(__METHOD__);
         $status->fatal("config-{$stepName}-tables-failed", $error);
     } else {
         $this->db->commit(__METHOD__);
     }
     // Resume normal operations
     if ($status->isOk()) {
         $this->enableLB();
     }
     return $status;
 }
示例#5
0
 protected function tearDown()
 {
     wfProfileIn(__METHOD__);
     // Cleaning up temporary files
     foreach ($this->tmpfiles as $fname) {
         if (is_file($fname) || is_link($fname)) {
             unlink($fname);
         } elseif (is_dir($fname)) {
             wfRecursiveRemoveDir($fname);
         }
     }
     if ($this->needsDB() && $this->db) {
         // Clean up open transactions
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback();
         }
         // don't ignore DB errors
         $this->db->ignoreErrors(false);
     }
     // Restore mw globals
     foreach ($this->mwGlobals as $key => $value) {
         $GLOBALS[$key] = $value;
     }
     $this->mwGlobals = array();
     parent::tearDown();
     wfProfileOut(__METHOD__);
 }
示例#6
0
 protected function tearDown()
 {
     $this->called['tearDown'] = true;
     // Cleaning up temporary files
     foreach ($this->tmpFiles as $fileName) {
         if (is_file($fileName) || is_link($fileName)) {
             unlink($fileName);
         } elseif (is_dir($fileName)) {
             wfRecursiveRemoveDir($fileName);
         }
     }
     if ($this->needsDB() && $this->db) {
         // Clean up open transactions
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback();
         }
     }
     // Restore mw globals
     foreach ($this->mwGlobals as $key => $value) {
         $GLOBALS[$key] = $value;
     }
     $this->mwGlobals = array();
     RequestContext::resetMain();
     MediaHandler::resetCache();
     $phpErrorLevel = intval(ini_get('error_reporting'));
     if ($phpErrorLevel !== $this->phpErrorLevel) {
         ini_set('error_reporting', $this->phpErrorLevel);
         $oldHex = strtoupper(dechex($this->phpErrorLevel));
         $newHex = strtoupper(dechex($phpErrorLevel));
         $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!";
         $this->fail($message);
     }
     parent::tearDown();
 }
 protected function tearDown()
 {
     global $wgRequest;
     $status = ob_get_status();
     if (isset($status['name']) && $status['name'] === 'MediaWikiTestCase::wfResetOutputBuffersBarrier') {
         ob_end_flush();
     }
     $this->called['tearDown'] = true;
     // Cleaning up temporary files
     foreach ($this->tmpFiles as $fileName) {
         if (is_file($fileName) || is_link($fileName)) {
             unlink($fileName);
         } elseif (is_dir($fileName)) {
             wfRecursiveRemoveDir($fileName);
         }
     }
     if ($this->needsDB() && $this->db) {
         // Clean up open transactions
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback(__METHOD__, 'flush');
         }
     }
     // Restore mw globals
     foreach ($this->mwGlobals as $key => $value) {
         $GLOBALS[$key] = $value;
     }
     $this->mwGlobals = [];
     $this->restoreLoggers();
     if (self::$serviceLocator && MediaWikiServices::getInstance() !== self::$serviceLocator) {
         MediaWikiServices::forceGlobalInstance(self::$serviceLocator);
     }
     // TODO: move global state into MediaWikiServices
     RequestContext::resetMain();
     MediaHandler::resetCache();
     if (session_id() !== '') {
         session_write_close();
         session_id('');
     }
     $wgRequest = new FauxRequest();
     MediaWiki\Session\SessionManager::resetCache();
     MediaWiki\Auth\AuthManager::resetCache();
     $phpErrorLevel = intval(ini_get('error_reporting'));
     if ($phpErrorLevel !== $this->phpErrorLevel) {
         ini_set('error_reporting', $this->phpErrorLevel);
         $oldHex = strtoupper(dechex($this->phpErrorLevel));
         $newHex = strtoupper(dechex($phpErrorLevel));
         $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!";
         $this->fail($message);
     }
     parent::tearDown();
 }
 protected function tearDown()
 {
     // Cleaning up temporary files
     foreach ($this->tmpfiles as $fname) {
         if (is_file($fname) || is_link($fname)) {
             unlink($fname);
         } elseif (is_dir($fname)) {
             wfRecursiveRemoveDir($fname);
         }
     }
     // clean up open transactions
     if ($this->needsDB() && $this->db) {
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback();
         }
     }
     parent::tearDown();
 }
示例#9
0
 /**
  * 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();
 }
示例#11
0
 /**
  * This function should *not* be called outside of JobQueueDB
  *
  * @param DatabaseBase $dbw
  * @param array $jobs
  * @param int $flags
  * @param string $method
  * @return boolean
  * @throws type
  */
 public function doBatchPushInternal(DatabaseBase $dbw, array $jobs, $flags, $method)
 {
     if (!count($jobs)) {
         return true;
     }
     $rowSet = array();
     // (sha1 => job) map for jobs that are de-duplicated
     $rowList = array();
     // list of jobs for jobs that are are not de-duplicated
     foreach ($jobs as $job) {
         $row = $this->insertFields($job);
         if ($job->ignoreDuplicates()) {
             $rowSet[$row['job_sha1']] = $row;
         } else {
             $rowList[] = $row;
         }
     }
     if ($flags & self::QOS_ATOMIC) {
         $dbw->begin($method);
         // wrap all the job additions in one transaction
     }
     try {
         // Strip out any duplicate jobs that are already in the queue...
         if (count($rowSet)) {
             $res = $dbw->select('job', 'job_sha1', array('job_sha1' => array_keys($rowSet), 'job_token' => ''), $method);
             foreach ($res as $row) {
                 wfDebug("Job with hash '{$row->job_sha1}' is a duplicate.\n");
                 unset($rowSet[$row->job_sha1]);
                 // already enqueued
             }
         }
         // Build the full list of job rows to insert
         $rows = array_merge($rowList, array_values($rowSet));
         // Insert the job rows in chunks to avoid slave lag...
         foreach (array_chunk($rows, 50) as $rowBatch) {
             $dbw->insert('job', $rowBatch, $method);
         }
         JobQueue::incrStats('job-insert', $this->type, count($rows));
         JobQueue::incrStats('job-insert-duplicate', $this->type, count($rowSet) + count($rowList) - count($rows));
     } catch (DBError $e) {
         if ($flags & self::QOS_ATOMIC) {
             $dbw->rollback($method);
         }
         throw $e;
     }
     if ($flags & self::QOS_ATOMIC) {
         $dbw->commit($method);
     }
     $this->cache->set($this->getCacheKey('empty'), 'false', JobQueueDB::CACHE_TTL_LONG);
     return true;
 }