From 9ca6b0f64cc58efd2a132f8b08fca8758ce1ab1f Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 10 May 2017 17:28:24 -0400 Subject: [PATCH] Fix usage of $db->nextSequenceValue() 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 | 5 ++++- includes/logging/LogEntry.php | 2 +- includes/logging/LogPage.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index b20f843497..c3782ba18a 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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 ) { diff --git a/includes/logging/LogEntry.php b/includes/logging/LogEntry.php index 1c5899ba85..e7095f0b39 100644 --- a/includes/logging/LogEntry.php +++ b/includes/logging/LogEntry.php @@ -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 ) { diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index 64102b7ec9..f2b16705c7 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -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 ) { -- 2.20.1