本文整理汇总了PHP中IDatabase::update方法的典型用法代码示例。如果您正苦于以下问题:PHP IDatabase::update方法的具体用法?PHP IDatabase::update怎么用?PHP IDatabase::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase::update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
wfWaitForSlaves(false, false, $this->clusterName);
}
示例2: 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();
}
示例3: 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)
{
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
foreach ($updates as $update) {
$this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
}
$lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
}
示例4: set
/**
* 更新ID为$id的记录,值为$data关联数组
* @param $id
* @param $data
* @param $where 指定匹配字段,默认为主键
* @return true/false
*/
public final function set($id, $data, $where = '')
{
if (empty($where)) {
$where = $this->primary;
}
return $this->db->update($id, $data, $this->table, $where);
}
示例5: invalidatePages
/**
* Invalidate the cache of a list of pages from a single namespace.
* This is intended for use by subclasses.
*
* @param IDatabase $dbw
* @param int $namespace Namespace number
* @param array $dbkeys
*/
public static function invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
{
if ($dbkeys === []) {
return;
}
$dbw->onTransactionIdle(function () use($dbw, $namespace, $dbkeys) {
$services = MediaWikiServices::getInstance();
$lbFactory = $services->getDBLoadBalancerFactory();
// Determine which pages need to be updated.
// This is necessary to prevent the job queue from smashing the DB with
// large numbers of concurrent invalidations of the same page.
$now = $dbw->timestamp();
$ids = $dbw->selectFieldValues('page', 'page_id', ['page_namespace' => $namespace, 'page_title' => $dbkeys, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
if (!$ids) {
return;
}
$batchSize = $services->getMainConfig()->get('UpdateRowsPerQuery');
$ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
foreach (array_chunk($ids, $batchSize) as $idBatch) {
$dbw->update('page', ['page_touched' => $now], ['page_id' => $idBatch, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
$lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
}
}, __METHOD__);
}
示例6: updateRevisionOn
/**
* Update the page record to point to a newly saved revision.
*
* @param IDatabase $dbw
* @param Revision $revision For ID number, and text used to set
* length and redirect status fields
* @param int $lastRevision If given, will not overwrite the page field
* when different from the currently set value.
* Giving 0 indicates the new page flag should be set on.
* @param bool $lastRevIsRedirect If given, will optimize adding and
* removing rows in redirect table.
* @return bool Success; false if the page row was missing or page_latest changed
*/
public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
{
global $wgContentHandlerUseDB;
// Assertion to try to catch T92046
if ((int) $revision->getId() === 0) {
throw new InvalidArgumentException(__METHOD__ . ': Revision has ID ' . var_export($revision->getId(), 1));
}
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
$conditions = ['page_id' => $this->getId()];
if (!is_null($lastRevision)) {
// An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
$row = ['page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($revision->getTimestamp()), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len];
if ($wgContentHandlerUseDB) {
$row['page_content_model'] = $revision->getContentModel();
}
$dbw->update('page', $row, $conditions, __METHOD__);
$result = $dbw->affectedRows() > 0;
if ($result) {
$this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
$this->setLastEdit($revision);
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool) $rt;
// Update the LinkCache.
LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
}
return $result;
}
示例7: cacheUpdate
/**
* @param IDatabase $dbw
* @return bool|mixed
*/
public static function cacheUpdate($dbw)
{
global $wgActiveUserDays;
$dbr = wfGetDB(DB_SLAVE, 'vslow');
# Get non-bot users than did some recent action other than making accounts.
# If account creation is included, the number gets inflated ~20+ fold on enwiki.
$activeUsers = $dbr->selectField('recentchanges', 'COUNT( DISTINCT rc_user_text )', array('rc_user != 0', 'rc_bot' => 0, 'rc_log_type != ' . $dbr->addQuotes('newusers') . ' OR rc_log_type IS NULL', 'rc_timestamp >= ' . $dbr->addQuotes($dbr->timestamp(wfTimestamp(TS_UNIX) - $wgActiveUserDays * 24 * 3600))), __METHOD__);
$dbw->update('site_stats', array('ss_active_users' => intval($activeUsers)), array('ss_row_id' => 1), __METHOD__);
return $activeUsers;
}