Fix usage of $db->nextSequenceValue()
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 10 May 2017 21:28:24 +0000 (17:28 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Wed, 10 May 2017 21:28:24 +0000 (17:28 -0400)
The return value from the method is only suitable for passing to
$db->insert(). To get the inserted ID, you need to call $db->insertId()
even if $db->nextSequenceValue() returned non-null.

Bug: T164900
Change-Id: I6beb6243ccb9425372623307ef23ae6571ce8c0d

includes/Revision.php
includes/logging/LogEntry.php
includes/logging/LogPage.php

index b20f843..c3782ba 100644 (file)
@@ -1496,7 +1496,10 @@ class Revision implements IDBAccessObject {
 
                $dbw->insert( 'revision', $row, __METHOD__ );
 
-               $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId();
+               if ( $this->mId === null ) {
+                       // Only if nextSequenceValue() was called
+                       $this->mId = $dbw->insertId();
+               }
 
                // Assertion to try to catch T92046
                if ( (int)$this->mId === 0 ) {
index 1c5899b..e7095f0 100644 (file)
@@ -634,7 +634,7 @@ class ManualLogEntry extends LogEntryBase {
                }
 
                $dbw->insert( 'logging', $data, __METHOD__ );
-               $this->id = !is_null( $id ) ? $id : $dbw->insertId();
+               $this->id = $dbw->insertId();
 
                $rows = [];
                foreach ( $relations as $tag => $values ) {
index 64102b7..f2b1670 100644 (file)
@@ -110,7 +110,7 @@ class LogPage {
                        'log_params' => $this->params
                ];
                $dbw->insert( 'logging', $data, __METHOD__ );
-               $newId = !is_null( $log_id ) ? $log_id : $dbw->insertId();
+               $newId = $dbw->insertId();
 
                # And update recentchanges
                if ( $this->updateRecentChanges ) {