Hi There, I run a 4.7 site where the sites primary user has just accidentally deleted themselves! I have SQL backups from yesterday but I'd prefer not to restore the whole DB (and overwrite the last 24hrs forum posts etc) in order to fix this. I pulled their 'users' table entry out the backup and reinserted that in the live DB but although that has re-enabled their account all the content they have ever posted to the site shows as 'Submitted by Anonymous' and all their forum posts show their user name but it is grayed out and suffixed with '(not verified)'.

Please can someone throw me a clue which other table entries I will need to restore to get this users history back in place?

Many thanks,

Roger Heathcote.

ps: incidentally, do newer Drupal versions have any provision for stopping users deleting themselves, it strikes me that in many cases this should be done only by an administrator, not the users themselves.

Comments

r0g’s picture

I see the issue what should happen when a user deletes themselves is a contentious issue, node 8 on the drupal website! This doesn't help me much still though. What I need to know is what ACTUALLY DOES happen when a user deletes themselves, ideally in drupal 4.7, more specifically which tables are affected by user deletions.

From what I can see in all tables containing uid the uid is reset to 0. Can someone pls tell me if this is the case?

If so, and it seemingly is, do you think it would be safe to do the following:

'UPDATE comments SET uid = 1234 WHERE uid = 0' for each affected table?

AFAICS no other users have actually deleted themselves in the history of the site and even if that was so that would only put their contributions under the restored users name (not a biggie). Am I right, or is there a lot more to this than I'm thinking?

What think all please?

Kindest regards,

Roger Heathcote.

r0g’s picture

Maybe someone else will need to do this in the future!..

I reset the UIDs in the comments table with the following SQL...

'UPDATE comments SET uid = 1234 WHERE uid = 0'

And that has got all the forum topics and posts back into their history and their name is now a link again.

Do note though that my site doesn't allow anonymous users to post content. If you do allow anon users to post then doing this will claim all the anon articles on behalf of the user you are restoring, probably not what you want! Also, if more than one user has deleted their account (in my case not true) you may end up claiming all their posts too so be careful and don't just use this on a live site unless you really understand what it is doing!

Thankfully, even if it's ambiguous who the UID 1 content belongs to you can get the comments table fixed as luckily it has the field 'name' stored in it :-)

UPDATE comments SET uid = 1234 WHERE name = 'the deleted users name'

From what I can see the other tables with UIDs don't have any similarly useful field for identifying the user so unless your site doesn't allow anon content and no other users have deleted their accounts you're probably out of luck.

Anyway, onwards...

I'm still getting the "Submitted by Anonymous" on stories by that user so I guess the next step is to do the same to the node table *GULP!* i.e.

'UPDATE node SET uid = 1234 WHERE uid = 0'

If anyone has any advice, wisdom or warnings on doing this or knows which, if any, other tables may need to be changed, or even forsees side effects I haven't forseen now would be a good time to pipe up! :-)

Roger Heathcote - www.technicalbloke.com

r0g’s picture

And over a month down the line I haven't noticed any side effects. If there are any side effects they are clearly negligible :-) The site in question only runs core stuff and a few homebrew mods though, maybe it isn't quite so simple if you have a bunch of 3rd part modules,or maybe it is :-)

Roger Heathcote - www.technicalbloke.com