Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Bulk deleting people

Quote Reply
Bulk deleting people
What needs to be deleted when you delete a user? We have a ton of people who haven't logged in (mostly because they didn't get their validation thingy) so I want to delete their accounts-- but going through the admin thing would take hours. I know how to write a script to do it but I want to see what needs to be deleted/modified so I don't screw something up.


Realiiity.com Forums
Quote Reply
Re: [ellipsiiis] Bulk deleting people In reply to
Something like this would help (untested code Smile).
Code:
#!/usr/bin/perl

use lib '/path/to/gforum/admin';
use strict;
use GForum qw/:all/;

$| = 1;
main();

sub main {
my @ids = $DB->table("User")->select("user_id", <conditions>)->fetchall_list();
# $DB->{_debug} = 1;
foreach my $id (@ids) {
print "Deleting user: $id\n";
$DB->table("User")->delete({ user_id => $id });
}
}

Adrian
Quote Reply
Re: [brewt] Bulk deleting people In reply to
My question though was shouldn't I also be deleting for instance any group assignments or new post records? I was wondering what other things are typically deleted when you delete a user-- or does it now only delete the actual user record?


Realiiity.com Forums
Quote Reply
Re: [ellipsiiis] Bulk deleting people In reply to
If you use similar code to the above, as opposed to just running an SQL query, it will handle deleting all the extra stuff related to those users (posts, etc).

Adrian
Quote Reply
Re: [brewt] Bulk deleting people In reply to
Right, my question is what are those things -- I don't know all the layers to GF enough to know what needs to be deleted, I know how to delete it, just not what :)


Realiiity.com Forums
Quote Reply
Re: [ellipsiiis] Bulk deleting people In reply to
My point being if you use similar code to the above, it will handle all that for you Smile. I myself don't know everything that happens when you delete a user. What I know happens is their user record is removed, all their posts are updated (to reflect that the user has been deleted), their messages are deleted, usernew data is deleted, and also any other tables which have a foreign key to the user_id. If you take a look at GForum/Table/User.pm, you can checkout the sub class and see what other stuff it does. I doubt you'd really want to do all this manually. Use the GForum code to do it, and save yourself the hassle.

Adrian
Quote Reply
Re: [ellipsiiis] Bulk deleting people In reply to
When you call $DB->table('User')->delete(...), everything related to users is deleted or updated appropriately.

When you run the query 'DELETE from gforum_User WHERE ...', well, basically, you break things.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com