+ /**
+ * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry
+ * for a single action (upload only, at the moment, but potentially also move, protect, ...).
+ */
+ private function rebuildRecentChangesTablePass5() {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $this->output( "Removing duplicate revision and logging entries...\n" );
+
+ $res = $dbw->select(
+ [ 'logging', 'log_search' ],
+ [ 'ls_value', 'ls_log_id' ],
+ [
+ 'ls_log_id = log_id',
+ 'ls_field' => 'associated_rev_id',
+ 'log_type' => 'upload',
+ ],
+ __METHOD__
+ );
+ foreach ( $res as $obj ) {
+ $rev_id = $obj->ls_value;
+ $log_id = $obj->ls_log_id;
+
+ // Mark the logging row as having an associated rev id
+ $dbw->update(
+ 'recentchanges',
+ /*SET*/ [ 'rc_this_oldid' => $rev_id ],
+ /*WHERE*/ [ 'rc_logid' => $log_id ],
+ __METHOD__
+ );
+
+ // Delete the revision row
+ $dbw->delete(
+ 'recentchanges',
+ /*WHERE*/ [ 'rc_this_oldid' => $rev_id, 'rc_logid' => 0 ],
+ __METHOD__
+ );
+ }
+ }
+