本文整理汇总了PHP中wfGetLBFactory函数的典型用法代码示例。如果您正苦于以下问题:PHP wfGetLBFactory函数的具体用法?PHP wfGetLBFactory怎么用?PHP wfGetLBFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfGetLBFactory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newConnection
/**
* Open a connection to the master server with the admin rights.
* @return Database
* @access private
*/
function newConnection()
{
$lb = wfGetLBFactory()->newMainLB();
$db = $lb->getConnection(DB_MASTER);
$this->loadBalancers[] = $lb;
return $db;
}
示例2: process
public function process()
{
// Erweiterung der Elternfunktion process()
$post = $this->request->data('post');
$get = $this->request->data('get');
unset($get['title']);
// dirty MediaWiki fix: /wiki/foo -> /w/index.php?title=foo
if (isset($get['allowed_filetarpathes'])) {
$this->echoJson(self::$allowed_filetarpathes);
exit;
}
if (!empty($this->request->file())) {
$this->handleChunk();
if (isset($this->returnData)) {
$this->echoJson($this->returnData);
}
// Fehlermeldung "Uncommitted DB writes": MediaWiki mag es wahrscheinlich nicht,
// wenn man exit() aufruft. vgl. http://stackoverflow.com/a/22695318
$lb = wfGetLBFactory();
$lb->shutdown();
exit;
# prevent MediaWiki to output something
} elseif (!empty($get)) {
$this->handleTestChunk();
if (isset($this->returnData)) {
$this->echoJson($this->returnData);
}
exit;
# prevent MediaWiki to output something
}
$this->pruneChunks(true);
# [true=always|false=random base]. Other option is to implement a cron script
}
示例3: getLB
/**
* @return \LoadBalancer
*/
public function getLB()
{
if ($this->cluster !== false) {
return wfGetLBFactory()->getExternalLB($this->cluster, $this->wiki);
} else {
return wfGetLB($this->wiki);
}
}
示例4: write
/**
* @param array $updates Array of arrays each containing two keys, 'primaryKey'
* and 'changes'. primaryKey must contain a map of column names to values
* sufficient to uniquely identify the row changes must contain a map of column
* names to update values to apply to the row.
*/
public function write(array $updates)
{
$this->db->begin();
foreach ($updates as $update) {
$this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
}
$this->db->commit();
wfGetLBFactory()->waitForReplication();
}
示例5: getDB
/**
* Wrapper function for wfGetDB
*
* @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);
}
示例6: run
function run()
{
if (!empty($this->params['mainDbMasterPos'])) {
wfGetLB()->waitFor($this->params['mainDbMasterPos']);
}
if (!empty($this->params['echoDbMasterPos'])) {
global $wgEchoCluster;
wfGetLBFactory()->getExternalLB($wgEchoCluster)->waitFor($this->params['echoDbMasterPos']);
}
EchoNotificationController::notify($this->event, false);
return true;
}
示例7: execute
public function execute()
{
wfProfileIn(__METHOD__);
//run the download:
Http::doSessionIdDownload($this->getOption('sid'), $this->getOption('usk'));
// close up shop:
// Execute any deferred updates
wfDoUpdates();
// Log what the user did, for book-keeping purposes.
wfLogProfilingData();
// Shut down the database before exit
wfGetLBFactory()->shutdown();
wfProfileOut(__METHOD__);
}
示例8: getOpenIDStore
function getOpenIDStore( $storeType, $prefix, $options ) {
global $wgOut, $wgMemc, $wgDBtype;
switch ( $storeType ) {
case 'file':
# Auto-create path if it doesn't exist
if ( !is_dir( $options['path'] ) ) {
if ( !mkdir( $options['path'], 0770, true ) ) {
$wgOut->showErrorPage( 'openidconfigerror', 'openidconfigerrortext' );
return null;
}
}
return new Auth_OpenID_FileStore( $options['path'] );
case 'db':
if ( $wgDBtype == 'sqlite' ) {
$db = new MediaWikiOpenIDDatabaseConnection( wfGetDB( DB_MASTER ) );
require_once( 'Auth/OpenID/SQLiteStore.php' );
return new Auth_OpenID_SQLiteStore( $db );
} else {
$lb = wfGetLBFactory()->newMainLB();
$db = new MediaWikiOpenIDDatabaseConnection( $lb->getConnection( DB_MASTER ) );
switch( $wgDBtype ) {
case 'mysql':
require_once( 'Auth/OpenID/MySQLStore.php' );
return new Auth_OpenID_MySQLStore( $db );
case 'postgres':
require_once( 'Auth/OpenID/PostgreSQLStore.php' );
return new Auth_OpenID_PostgreSQLStore( $db );
default:
$wgOut->showErrorPage( 'openidconfigerror', 'openidconfigerrortext' );
return null;
}
}
case 'memcached':
return new MediaWikiOpenIDMemcachedStore( $wgMemc );
default:
$wgOut->showErrorPage( 'openidconfigerror', 'openidconfigerrortext' );
}
}
示例9: getDB
/**
* @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;
}
示例10: testDoUpdatesCLI
public function testDoUpdatesCLI()
{
$this->setMwGlobals('wgCommandLineMode', true);
$updates = ['1' => "deferred update 1;\n", '2' => "deferred update 2;\n", '2-1' => "deferred update 1 within deferred update 2;\n", '2-2' => "deferred update 2 within deferred update 2;\n", '3' => "deferred update 3;\n", '3-1' => "deferred update 1 within deferred update 3;\n", '3-2' => "deferred update 2 within deferred update 3;\n", '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n", '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n"];
wfGetLBFactory()->commitMasterChanges(__METHOD__);
// clear anything
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-2'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-1'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-1-1'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-2-1'];
});
});
});
$this->expectOutputString(implode('', $updates));
DeferredUpdates::doUpdates();
}
示例11: execute
public function execute()
{
$wiki = $this->getOption('wikidb') ?: false;
// Get the appropriate load balancer (for this wiki)
if ($this->hasOption('cluster')) {
$lb = wfGetLBFactory()->getExternalLB($this->getOption('cluster'), $wiki);
} else {
$lb = wfGetLB($wiki);
}
// Figure out which server to use
if ($this->hasOption('slave')) {
$server = $this->getOption('slave');
if ($server === 'any') {
$index = DB_SLAVE;
} else {
$index = null;
for ($i = 0; $i < $lb->getServerCount(); ++$i) {
if ($lb->getServerName($i) === $server) {
$index = $i;
break;
}
}
if ($index === null) {
$this->error("No slave server configured with the name '{$server}'.", 1);
}
}
} else {
$index = DB_MASTER;
}
// Get a DB handle (with this wiki's DB selected) from the appropriate load balancer
$db = $lb->getConnection($index, array(), $wiki);
if ($this->hasOption('slave') && $db->getLBInfo('master') !== null) {
$this->error("The server selected ({$db->getServer()}) is not a slave.", 1);
}
if ($this->hasArg(0)) {
$file = fopen($this->getArg(0), 'r');
if (!$file) {
$this->error("Unable to open input file", true);
}
$error = $db->sourceStream($file, false, array($this, 'sqlPrintResult'));
if ($error !== true) {
$this->error($error, true);
} else {
exit(0);
}
}
$useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0);
if ($useReadline) {
global $IP;
$historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history";
readline_read_history($historyFile);
}
$wholeLine = '';
$newPrompt = '> ';
$prompt = $newPrompt;
while (($line = Maintenance::readconsole($prompt)) !== false) {
if (!$line) {
# User simply pressed return key
continue;
}
$done = $db->streamStatementEnd($wholeLine, $line);
$wholeLine .= $line;
if (!$done) {
$wholeLine .= ' ';
$prompt = ' -> ';
continue;
}
if ($useReadline) {
# Delimiter is eated by streamStatementEnd, we add it
# up in the history (bug 37020)
readline_add_history($wholeLine . $db->getDelimiter());
readline_write_history($historyFile);
}
try {
$res = $db->query($wholeLine);
$this->sqlPrintResult($res, $db);
$prompt = $newPrompt;
$wholeLine = '';
} catch (DBQueryError $e) {
$doDie = !Maintenance::posix_isatty(0);
$this->error($e, $doDie);
}
}
wfWaitForSlaves();
}
示例12: restInPeace
/**
* Ends this task peacefully
*/
public function restInPeace()
{
// Do any deferred jobs
DeferredUpdates::doUpdates('commit');
// Execute a job from the queue
$this->doJobs();
// Log profiling data, e.g. in the database or UDP
wfLogProfilingData();
// Commit and close up!
$factory = wfGetLBFactory();
$factory->commitMasterChanges();
$factory->shutdown();
wfDebug("Request ended normally\n");
}
示例13: setWFVariables
/**
* setWFVariables
*
* add all default variables into city_variables table
*
* @author Krzysztof Krzyzaniak <eloy@wikia-inc.com>
* @author Piotr Molski <moli@wikia-inc.com>
* @access private
*
*/
private function setWFVariables()
{
// WF Variables containter
$this->mWFSettingVars = array();
$this->mWFSettingVars['wgSitename'] = $this->mNewWiki->sitename;
$this->mWFSettingVars['wgLogo'] = self::DEFAULT_WIKI_LOGO;
$this->mWFSettingVars['wgUploadPath'] = $this->mNewWiki->images_url;
$this->mWFSettingVars['wgUploadDirectory'] = $this->mNewWiki->images_dir;
$this->mWFSettingVars['wgDBname'] = $this->mNewWiki->dbname;
$this->mWFSettingVars['wgLocalInterwiki'] = $this->mNewWiki->sitename;
$this->mWFSettingVars['wgLanguageCode'] = $this->mNewWiki->language;
$this->mWFSettingVars['wgServer'] = rtrim($this->mNewWiki->url, "/");
$this->mWFSettingVars['wgEnableSectionEdit'] = true;
$this->mWFSettingVars['wgEnableSwiftFileBackend'] = true;
$this->mWFSettingVars['wgOasisLoadCommonCSS'] = true;
if ($this->getInitialNjordExtValue()) {
$this->mWFSettingVars['wgEnableNjordExt'] = true;
}
// rt#60223: colon allowed in sitename, breaks project namespace
if (mb_strpos($this->mWFSettingVars['wgSitename'], ':') !== false) {
$this->mWFSettingVars['wgMetaNamespace'] = str_replace(array(':', ' '), array('', '_'), $this->mWFSettingVars['wgSitename']);
}
if (self::ACTIVE_CLUSTER) {
wfGetLBFactory()->sectionsByDB[$this->mNewWiki->dbname] = $this->mWFSettingVars['wgDBcluster'] = self::ACTIVE_CLUSTER;
}
$oRes = $this->mDBw->select("city_variables_pool", array("cv_id, cv_name"), array("cv_name in ('" . implode("', '", array_keys($this->mWFSettingVars)) . "')"), __METHOD__);
$this->mWFVars = array();
while ($oRow = $this->mDBw->fetchObject($oRes)) {
$this->mWFVars[$oRow->cv_name] = $oRow->cv_id;
}
$this->mDBw->freeResult($oRes);
foreach ($this->mWFSettingVars as $variable => $value) {
/**
* first, get id of variable
*/
$cv_id = 0;
if (isset($this->mWFVars[$variable])) {
$cv_id = $this->mWFVars[$variable];
}
/**
* then, insert value for wikia
*/
if (!empty($cv_id)) {
$this->mDBw->insert("city_variables", array("cv_value" => serialize($value), "cv_city_id" => $this->mNewWiki->city_id, "cv_variable_id" => $cv_id), __METHOD__);
}
}
}
示例14: rollbackMasterChangesAndLog
/**
* If there are any open database transactions, roll them back and log
* the stack trace of the exception that should have been caught so the
* transaction could be aborted properly.
*
* @since 1.23
* @param Exception|Throwable $e
*/
public static function rollbackMasterChangesAndLog($e)
{
$factory = wfGetLBFactory();
if ($factory->hasMasterChanges()) {
$logger = LoggerFactory::getInstance('Bug56269');
$logger->warning('Exception thrown with an uncommited database transaction: ' . self::getLogMessage($e), self::getLogContext($e));
$factory->rollbackMasterChanges(__METHOD__);
}
}
示例15: rollbackMasterChangesAndLog
/**
* If there are any open database transactions, roll them back and log
* the stack trace of the exception that should have been caught so the
* transaction could be aborted properly.
*
* @since 1.23
* @param Exception $e
*/
public static function rollbackMasterChangesAndLog(Exception $e)
{
$factory = wfGetLBFactory();
if ($factory->hasMasterChanges()) {
wfDebugLog('Bug56269', 'Exception thrown with an uncommited database transaction: ' . MWExceptionHandler::getLogMessage($e) . "\n" . $e->getTraceAsString());
$factory->rollbackMasterChanges();
}
}