From: Brad Jorsch Date: Fri, 1 Sep 2017 13:46:43 +0000 (-0400) Subject: Remove reference to deprecated IDatabase->nextSequenceValue() X-Git-Tag: 1.31.0-rc.0~2235^2 X-Git-Url: http://git.cyclocoop.org/%24dirpuce/puce%24spip_lang_rtl.gif?a=commitdiff_plain;h=01a10dba5a38101fcd92d4cc9e6684b938af0911;p=lhc%2Fweb%2Fwiklou.git Remove reference to deprecated IDatabase->nextSequenceValue() The method was deprecated and made unnecessary in Ib308190c. Change-Id: I1729ac0b3a88270a4c2f064187a2472112aaeb1e --- diff --git a/includes/Block.php b/includes/Block.php index 0b17e93f3f..40095f18b8 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -493,7 +493,6 @@ class Block { } $row = $this->getDatabaseArray( $dbw ); - $row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" ); $dbw->insert( 'ipblocks', $row, __METHOD__, [ 'IGNORE' ] ); $affected = $dbw->affectedRows(); diff --git a/includes/CommentStore.php b/includes/CommentStore.php index 0c86c1e871..fdfa6d963d 100644 --- a/includes/CommentStore.php +++ b/includes/CommentStore.php @@ -400,11 +400,9 @@ class CommentStore { __METHOD__ ); if ( !$comment->id ) { - $comment->id = $dbw->nextSequenceValue( 'comment_comment_id_seq' ); $dbw->insert( 'comment', [ - 'comment_id' => $comment->id, 'comment_hash' => $hash, 'comment_text' => $comment->text, 'comment_data' => $dbData, diff --git a/includes/Revision.php b/includes/Revision.php index ff4a284386..99d15a72ba 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -1442,10 +1442,8 @@ class Revision implements IDBAccessObject { # 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', [ - 'old_id' => $old_id, 'old_text' => $data, 'old_flags' => $flags, ], __METHOD__ @@ -1458,11 +1456,7 @@ class Revision implements IDBAccessObject { } # Record the edit in revisions - $rev_id = $this->mId !== null - ? $this->mId - : $dbw->nextSequenceValue( 'revision_rev_id_seq' ); $row = [ - 'rev_id' => $rev_id, 'rev_page' => $this->mPage, 'rev_text_id' => $this->mTextId, 'rev_minor_edit' => $this->mMinorEdit ? 1 : 0, @@ -1478,6 +1472,9 @@ class Revision implements IDBAccessObject { ? self::base36Sha1( $this->mText ) : $this->mSha1, ]; + if ( $this->mId !== null ) { + $row['rev_id'] = $this->mId; + } list( $commentFields, $commentCallback ) = CommentStore::newKey( 'rev_comment' )->insertWithTempTable( $dbw, $this->mComment ); @@ -1508,7 +1505,7 @@ class Revision implements IDBAccessObject { $dbw->insert( 'revision', $row, __METHOD__ ); if ( $this->mId === null ) { - // Only if nextSequenceValue() was called + // Only if auto-increment was used $this->mId = $dbw->insertId(); } $commentCallback( $this->mId ); diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 588f602e64..cd11070002 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -320,7 +320,6 @@ class RecentChange { # Fixup database timestamps $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] ); - $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' ); # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL if ( $this->mAttribs['rc_cur_id'] == 0 ) { @@ -333,6 +332,10 @@ class RecentChange { unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] ); $row += CommentStore::newKey( 'rc_comment' )->insert( $dbw, $comment ); + # Don't reuse an existing rc_id for the new row, if one happens to be + # set for some reason. + unset( $row['rc_id'] ); + # Insert new row $dbw->insert( 'recentchanges', $row, __METHOD__ ); diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 18a87e8bf2..33d4e70826 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -548,7 +548,6 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { foreach ( $diffs as $url => $dummy ) { foreach ( wfMakeUrlIndexes( $url ) as $index ) { $arr[] = [ - 'el_id' => $this->getDB()->nextSequenceValue( 'externallinks_el_id_seq' ), 'el_from' => $this->mId, 'el_to' => $url, 'el_index' => $index, diff --git a/includes/externalstore/ExternalStoreDB.php b/includes/externalstore/ExternalStoreDB.php index 6bb1618ff6..e5d36e10cb 100644 --- a/includes/externalstore/ExternalStoreDB.php +++ b/includes/externalstore/ExternalStoreDB.php @@ -92,9 +92,8 @@ class ExternalStoreDB extends ExternalStoreMedium { public function store( $location, $data ) { $dbw = $this->getMaster( $location ); - $id = $dbw->nextSequenceValue( 'blob_blob_id_seq' ); $dbw->insert( $this->getTable( $dbw ), - [ 'blob_id' => $id, 'blob_text' => $data ], + [ 'blob_text' => $data ], __METHOD__ ); $id = $dbw->insertId(); if ( !$id ) { diff --git a/includes/import/WikiRevision.php b/includes/import/WikiRevision.php index 93a92ef8b5..edb0c9af1c 100644 --- a/includes/import/WikiRevision.php +++ b/includes/import/WikiRevision.php @@ -720,9 +720,7 @@ class WikiRevision { . $this->timestamp . "\n" ); return false; } - $log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' ); $data = [ - 'log_id' => $log_id, 'log_type' => $this->type, 'log_action' => $this->action, 'log_timestamp' => $dbw->timestamp( $this->timestamp ), diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index b5f331b35f..b68fdaefb3 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -734,7 +734,6 @@ class JobQueueDB extends JobQueue { 'job_title' => $job->getTitle()->getDBkey(), 'job_params' => self::makeBlob( $job->getParams() ), // Additional job metadata - 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), 'job_timestamp' => $dbw->timestamp(), 'job_sha1' => Wikimedia\base_convert( sha1( serialize( $job->getDeduplicationInfo() ) ), diff --git a/includes/libs/rdbms/database/IDatabase.php b/includes/libs/rdbms/database/IDatabase.php index 736447f46c..0283c4b48a 100644 --- a/includes/libs/rdbms/database/IDatabase.php +++ b/includes/libs/rdbms/database/IDatabase.php @@ -420,12 +420,9 @@ interface IDatabase { /** * Get the inserted value of an auto-increment row * - * The value inserted should be fetched from nextSequenceValue() - * - * Example: - * $id = $dbw->nextSequenceValue( 'page_page_id_seq' ); - * $dbw->insert( 'page', [ 'page_id' => $id ] ); - * $id = $dbw->insertId(); + * This should only be called after an insert that used an auto-incremented + * value. If no such insert was previously done in the current database + * session, the return value is undefined. * * @return int */ diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 6587304ffb..6197d407df 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -596,7 +596,6 @@ class ManualLogEntry extends LogEntryBase { global $wgContLang; $dbw = $dbw ?: wfGetDB( DB_MASTER ); - $id = $dbw->nextSequenceValue( 'logging_log_id_seq' ); if ( $this->timestamp === null ) { $this->timestamp = wfTimestampNow(); @@ -619,7 +618,6 @@ class ManualLogEntry extends LogEntryBase { } $data = [ - 'log_id' => $id, 'log_type' => $this->getType(), 'log_action' => $this->getSubtype(), 'log_timestamp' => $dbw->timestamp( $this->getTimestamp() ), diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 257f76d0bb..3b200fa8c7 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -90,12 +90,10 @@ class LogPage { global $wgLogRestrictions; $dbw = wfGetDB( DB_MASTER ); - $log_id = $dbw->nextSequenceValue( 'logging_log_id_seq' ); // @todo FIXME private/protected/public property? $this->timestamp = $now = wfTimestampNow(); $data = [ - 'log_id' => $log_id, 'log_type' => $this->type, 'log_action' => $this->action, 'log_timestamp' => $dbw->timestamp( $now ), diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 790845e35e..5f6e455e1f 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -1166,11 +1166,10 @@ class WikiPage implements Page, IDBAccessObject { * page ID is already in use. */ public function insertOn( $dbw, $pageId = null ) { - $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' ); + $pageIdForInsert = $pageId ? [ 'page_id' => $pageId ] : []; $dbw->insert( 'page', [ - 'page_id' => $pageIdForInsert, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_restrictions' => '', @@ -1180,7 +1179,7 @@ class WikiPage implements Page, IDBAccessObject { 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, // Fill this in shortly... 'page_len' => 0, // Fill this in shortly... - ], + ] + $pageIdForInsert, __METHOD__, 'IGNORE' ); @@ -2446,7 +2445,6 @@ class WikiPage implements Page, IDBAccessObject { $dbw->insert( 'page_restrictions', [ - 'pr_id' => $dbw->nextSequenceValue( 'page_restrictions_pr_id_seq' ), 'pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, diff --git a/includes/site/DBSiteStore.php b/includes/site/DBSiteStore.php index e106f37ecc..7fcfbe59e9 100644 --- a/includes/site/DBSiteStore.php +++ b/includes/site/DBSiteStore.php @@ -214,8 +214,6 @@ class DBSiteStore implements SiteStore { 'sites', $fields, [ 'site_id' => $rowId ], __METHOD__ ) && $success; } else { - $rowId = $dbw->nextSequenceValue( 'sites_site_id_seq' ); - $fields['site_id'] = $rowId; $success = $dbw->insert( 'sites', $fields, __METHOD__ ) && $success; $rowId = $dbw->insertId(); } diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 48477f8faa..755f9fdf7b 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -290,7 +290,6 @@ class UploadStash { } $this->fileMetadata[$key] = [ - 'us_id' => $dbw->nextSequenceValue( 'uploadstash_us_id_seq' ), 'us_user' => $this->userId, 'us_key' => $key, 'us_orig_path' => $path, diff --git a/includes/user/User.php b/includes/user/User.php index 08f054d286..8506846df6 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -4109,12 +4109,10 @@ class User implements IDBAccessObject { unset( $params['options'] ); } $dbw = wfGetDB( DB_MASTER ); - $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' ); $noPass = PasswordFactory::newInvalidPassword()->toString(); $fields = [ - 'user_id' => $seqVal, 'user_name' => $name, 'user_password' => $noPass, 'user_newpassword' => $noPass, @@ -4179,10 +4177,8 @@ class User implements IDBAccessObject { $noPass = PasswordFactory::newInvalidPassword()->toString(); $dbw = wfGetDB( DB_MASTER ); - $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' ); $dbw->insert( 'user', [ - 'user_id' => $seqVal, 'user_name' => $this->mName, 'user_password' => $noPass, 'user_newpassword' => $noPass, diff --git a/maintenance/fixExtLinksProtocolRelative.php b/maintenance/fixExtLinksProtocolRelative.php index 0fae63c3bf..97cd37e07e 100644 --- a/maintenance/fixExtLinksProtocolRelative.php +++ b/maintenance/fixExtLinksProtocolRelative.php @@ -68,13 +68,11 @@ class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance { $db->insert( 'externallinks', [ [ - 'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ), 'el_from' => $row->el_from, 'el_to' => $row->el_to, 'el_index' => "http:{$row->el_index}", ], [ - 'el_id' => $db->nextSequenceValue( 'externallinks_el_id_seq' ), 'el_from' => $row->el_from, 'el_to' => $row->el_to, 'el_index' => "https:{$row->el_index}", diff --git a/tests/phpunit/includes/CommentStoreTest.php b/tests/phpunit/includes/CommentStoreTest.php index b65136aded..4e0210a543 100644 --- a/tests/phpunit/includes/CommentStoreTest.php +++ b/tests/phpunit/includes/CommentStoreTest.php @@ -363,7 +363,6 @@ class CommentStoreTest extends MediaWikiLangTestCase { $this->assertArrayNotHasKey( "{$key}_id", $fields, "new field, stage=$writeStage" ); } - $extraFields[$pk] = $this->db->nextSequenceValue( "{$table}_{$pk}_seq" ); $this->db->insert( $table, $extraFields + $fields, __METHOD__ ); $id = $this->db->insertId(); if ( $usesTemp ) {