Log in

View Full Version : sql querys to delete a member in vbulletin


mlee
12-19-2005, 08:02 PM
Greetings all together.

Im writting a vbulleting integration script for an other cms at the moment and
need to know which sql querys i have to run to delete a user.

i know about

delete from $prefix."_user" where userid = '$id'
delete from $prefix."_userfield" where userid = '$id'

are there any more?

In fact i need to know what happens (sql querys) when i delete a user using the control panel.

Can someone help me out with this please?

With kind regards,

mlee

Lea Verou
12-19-2005, 08:07 PM
Greetings all together.

Im writting a vbulleting integration script for an other cms at the moment and
need to know which sql querys i have to run to delete a user.

i know about

delete from $prefix."_user" where userid = '$id'
delete from $prefix."_userfield" where userid = '$id'

are there any more?

In fact i need to know what happens (sql querys) when i delete a user using the control panel.

Can someone help me out with this please?

With kind regards,

mlee

It is not $prefix, it is TABLE_PREFIX.
It is not _user/_userfield, it is user/userfield. ;) :)

mlee
12-19-2005, 08:14 PM
It is not $prefix, it is TABLE_PREFIX.
It is not _user/_userfield, it is user/userfield. ;) :)

Well i quoted that from my script :)
And yes you are right the underline is not needed there. Thx!

I guess you guys know what i mean.

I need the sql querys which are executed if you delete a member using the controlpanel.

So can anyone help me out?

Regards mlee

Delphiprogrammi
12-19-2005, 08:15 PM
hi,



$db->query("DELETE FROM " . TABLE_PREFIX . "user WHERE userid='$vbulletin->userinfo[userid]'");


or you could


$id = $vbulletin->userinfo['userid']
$db->qyery("DELETE FROM " . TABLE_PREFIX . "user WHERE userid=$id");


that should work

mlee
12-19-2005, 08:17 PM
hi,

that should work

Hello Delphiprogrammi,

no you got me wrong, sorry my english is not the best.

I am not writting an vbulletin script but im modifing an other cms to work together with vbulletin.
I need to be able to delete vbulletin members by using the admin panel of the other cms. Therefore i need to know all sql querys which are executed if an user is deleted by the vbulletin control panel.
I dont want to make useless data stay in the database.
There are a lot of tables using userid as foreign key in vbulletin but i need to know which i i should delete when deleting a member.

Regards mlee

Lea Verou
12-19-2005, 08:22 PM
Hello Delphiprogrammi,

no you got me wrong, sorry my english is not the best.

I am not writting an vbulletin script but im modifing an other cms to work together with vbulletin.
I need to be able to delete vbulletin members by using the admin panel of the other cms. Therefore i need to know all sql querys which are executed if an user is deleted by the vbulletin control panel.
I dont want to make useless data stay in the database.
There are a lot of tables using userid as foreign key in vbulletin but i need to know which i i should delete when deleting a member.

Regards mlee

Try to look at the code that is executed when vb itself deletes a user ;)

mlee
12-19-2005, 08:28 PM
Try to look at the code that is executed when vb itself deletes a user ;)

That was what i tryed first but i was not able to find it.

Lea Verou
12-19-2005, 08:33 PM
That was what i tryed first but i was not able to find it.

Yeah, I know... Those files are huge :(
I haven't seriously looked at a single vbulletin file for all the hacks I've made... I just can't find my way over there :ermm:
So, the correct answer imho (and more likely to be replied) is "Where can I find the code that vbulletin uses to delete users?" ;)

mlee
12-19-2005, 08:36 PM
I just can't find my way over there...
"Where can I find the code that vbulletin uses to delete users?" ;)

Same here.

I can agree on that one :)
So my new question is:

Where can I find the code that vbulletin uses to delete users?

Regards mlee

Paul M
12-19-2005, 08:41 PM
vbulletin deletes the user from user, userfield & usertextfield and sets the userid to zero in all posts they have made. It also removes userid based entries from a whole host of other tables.

It's a bit harder to track the code now because it uses the datamanager.

mlee
12-25-2005, 09:53 PM
Just in case someone else needs this in the future:


$user = $DB_site->query_first("
SELECT userid, username, avatarrevision
FROM " . TABLE_PREFIX . "user
WHERE userid = $userid
");

$DB_site->query("
UPDATE " . TABLE_PREFIX . "post
SET username = '" . addslashes($user['username']) . "',
userid = 0
WHERE userid = $userid
");

$DB_site->query("
UPDATE " . TABLE_PREFIX . "usernote
SET username = '" . addslashes($user['username']) . "',
posterid = 0
WHERE posterid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "usernote
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "user
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "userfield
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "usertextfield
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "access
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "event
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "customavatar
WHERE userid = $userid
");


$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "customprofilepic
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "moderator
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "subscribeforum
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "subscribethread
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "subscriptionlog
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "session
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "userban
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "administrator
WHERE userid = $userid
");

$DB_site->query("
DELETE FROM " . TABLE_PREFIX . "usergrouprequest
WHERE userid = $userid
");

$DB_site->query("DELETE FROM " . TABLE_PREFIX . "pmreceipt WHERE userid = $userid");

$DB_site->query("DELETE FROM " . TABLE_PREFIX . "pm WHERE userid = $userid");

merk
12-25-2005, 10:39 PM
You can use the datamanager to do all of that. (the queries you posted is still not a complete list :))

init a datamanager then use set_existing() then use delete().

mlee
12-26-2005, 10:02 AM
You can use the datamanager to do all of that. (the queries you posted is still not a complete list :))

init a datamanager then use set_existing() then use delete().

And again:
"Im writing an import script to use vbulletin usersdatabase together with an other cms thats why i can not use any vbulletin functions.

OR in other words:
I need to write my own script to safty delete vbulletins user.

Thats the complete liste except the deletion of the pms and the update of the forums data.

merk
12-26-2005, 10:04 AM
Did you delete the users avatar or profile picture from the filesystem if it existed?

Even if you cant use the function, there is a complete list of operations that needs to be completed in the function i referenced.

mlee
12-26-2005, 11:46 AM
Did you delete the users avatar or profile picture from the filesystem if it existed?

Even if you cant use the function, there is a complete list of operations that needs to be completed in the function i referenced.

Yes, I saw where they where unlinked but since they use the userid as a part of the file name i thought it is not necessary to delete them.