本文整理汇总了PHP中IDatabase::nextSequenceValue方法的典型用法代码示例。如果您正苦于以下问题:PHP IDatabase::nextSequenceValue方法的具体用法?PHP IDatabase::nextSequenceValue怎么用?PHP IDatabase::nextSequenceValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase::nextSequenceValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertOn
/**
* Insert a new empty page record for this article.
* This *must* be followed up by creating a revision
* and running $this->updateRevisionOn( ... );
* or else the record will be left in a funky state.
* Best if all done inside a transaction.
*
* @param IDatabase $dbw
* @param int|null $pageId Custom page ID that will be used for the insert statement
*
* @return bool|int The newly created page_id key; false if the row was not
* inserted, e.g. because the title already existed or because the specified
* page ID is already in use.
*/
public function insertOn($dbw, $pageId = null)
{
$pageIdForInsert = $pageId ?: $dbw->nextSequenceValue('page_page_id_seq');
$dbw->insert('page', ['page_id' => $pageIdForInsert, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_restrictions' => '', 'page_is_redirect' => 0, 'page_is_new' => 1, 'page_random' => wfRandom(), 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, 'page_len' => 0], __METHOD__, 'IGNORE');
if ($dbw->affectedRows() > 0) {
$newid = $pageId ?: $dbw->insertId();
$this->mId = $newid;
$this->mTitle->resetArticleID($newid);
return $newid;
} else {
return false;
// nothing changed
}
}
示例2: insertOn
/**
* Insert a new revision into the database, returning the new revision ID
* number on success and dies horribly on failure.
*
* @param IDatabase $dbw (master connection)
* @throws MWException
* @return int
*/
public function insertOn($dbw)
{
global $wgDefaultExternalStore, $wgContentHandlerUseDB;
// Not allowed to have rev_page equal to 0, false, etc.
if (!$this->mPage) {
$title = $this->getTitle();
if ($title instanceof Title) {
$titleText = ' for page ' . $title->getPrefixedText();
} else {
$titleText = '';
}
throw new MWException("Cannot insert revision{$titleText}: page ID must be nonzero");
}
$this->checkContentModel();
$data = $this->mText;
$flags = self::compressRevisionText($data);
# Write to external storage if required
if ($wgDefaultExternalStore) {
// Store and get the URL
$data = ExternalStore::insertToDefault($data);
if (!$data) {
throw new MWException("Unable to store text to external storage");
}
if ($flags) {
$flags .= ',';
}
$flags .= 'external';
}
# Record the text (or external storage URL) to the text table
if ($this->mTextId === null) {
$old_id = $dbw->nextSequenceValue('text_old_id_seq');
$dbw->insert('text', array('old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags), __METHOD__);
$this->mTextId = $dbw->insertId();
}
if ($this->mComment === null) {
$this->mComment = "";
}
# Record the edit in revisions
$rev_id = $this->mId !== null ? $this->mId : $dbw->nextSequenceValue('revision_rev_id_seq');
$row = array('rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_comment' => $this->mComment, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, 'rev_user' => $this->mUser, 'rev_user_text' => $this->mUserText, 'rev_timestamp' => $dbw->timestamp($this->mTimestamp), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, 'rev_parent_id' => $this->mParentId === null ? $this->getPreviousRevisionId($dbw) : $this->mParentId, 'rev_sha1' => $this->mSha1 === null ? Revision::base36Sha1($this->mText) : $this->mSha1);
if ($wgContentHandlerUseDB) {
// NOTE: Store null for the default model and format, to save space.
// XXX: Makes the DB sensitive to changed defaults.
// Make this behavior optional? Only in miser mode?
$model = $this->getContentModel();
$format = $this->getContentFormat();
$title = $this->getTitle();
if ($title === null) {
throw new MWException("Insufficient information to determine the title of the " . "revision's page!");
}
$defaultModel = ContentHandler::getDefaultModelFor($title);
$defaultFormat = ContentHandler::getForModelID($defaultModel)->getDefaultFormat();
$row['rev_content_model'] = $model === $defaultModel ? null : $model;
$row['rev_content_format'] = $format === $defaultFormat ? null : $format;
}
$dbw->insert('revision', $row, __METHOD__);
$this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
// Assertion to try to catch T92046
if ((int) $this->mId === 0) {
throw new UnexpectedValueException('After insert, Revision mId is ' . var_export($this->mId, 1) . ': ' . var_export($row, 1));
}
Hooks::run('RevisionInsertComplete', array(&$this, $data, $flags));
return $this->mId;
}