WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 21 months ago

#15644 new defect (bug)

When deleting a user, corresponding comment user IDs aren't reset

Reported by: nacin Owned by:
Milestone: Future Release Priority: lowest
Severity: minor Version:
Component: Comments Keywords: 2nd-opinion has-patch
Focuses: Cc:

Description

Delete a user with a comment.

The user ID stays.

Potential for clashes later.

We should run this: $wpdb->update( $wpdb->comments, array( 'user_id' => 0 ), array( 'user_id' => $user_id ) ); in wp_delete_user.

Alternative is to do a full query then manually run wp_insert_comment() on each, so all hooks get fired, which is fine too and is more in line with what we do elsewhere.

Attachments (2)

15644.diff (877 bytes) - added by logiclord 3 years ago.
user_id is set to 0 when a user is deleted
15644.patch (1.0 KB) - added by jakub.tyrcha 3 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 nacin3 years ago

  • Keywords needs-patch added; has-patch removed

@todo submit this for gci.

comment:2 westi3 years ago

That query could get ouchy on a large site though?

The comment table is more of a snapshot of data at the comment time.

comment:3 follow-up: nacin3 years ago

  • Keywords 2nd-opinion added; gci removed

I don't have a problem with the rest of the data as a snapshot, but this has the potential for a future user to then clash.

You're right though, this query could possibly hurt. Not my area of expertise.

comment:4 in reply to: ↑ 3 westi3 years ago

Replying to nacin:

I don't have a problem with the rest of the data as a snapshot, but this has the potential for a future user to then clash.

User id is auto increment which should deal with this AFAIK

ID bigint(20) unsigned NOT NULL auto_increment,

comment:5 nacin3 years ago

  • Priority changed from normal to lowest
  • Severity changed from normal to minor

Ah ha, I thought the increment gets reset on an optimize/repair, but it actually requires an ALTER TABLE AUTO_INCREMENT = 1.

logiclord3 years ago

user_id is set to 0 when a user is deleted

comment:6 solarissmoke3 years ago

@logiclord I think you diffed the wrong way :), those lines should be added not deleted. Also please make a diff from the root wp folder, not just the file in question.

jakub.tyrcha3 years ago

comment:7 SergeyBiryukov3 years ago

  • Keywords has-patch added; needs-patch removed

comment:8 kovshenin3 years ago

  • Cc kovshenin@… added

Hey there!

I was getting rid of the admin user on an existing website who had existing blog posts and comments. I created a new admin user and when I went to remove the admin user it asked me whether I want to move all posts and links to a different one where I can pick from the list. I think the same approach should go with comments. I had to manually run an update statement on the comments table to replace all comments with user_id = 1 to user_id = 9 (the ID of the newly created user) for my old gravatars to show up again. Thoughts?

comment:10 Mamaduka21 months ago

  • Cc georgemamadashvili@… added
Note: See TracTickets for help on using tickets.