FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » Prune stale users?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Prune stale users? [message #36088] Sat, 03 March 2007 18:51 Go to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
Hello, all. I'd like to remove stale unused user accounts. I have 6 pages of users who have old accounts but never posted anything. I'm sure I could write something to directly manipulate the database but I'm afraid that would cause problems for me. I'd like it to do whatever the delete account option does because I still don't have a firm grasp on the inner workings of fud and its database structure. Any thoughts on this?

[Updated on: Sat, 03 March 2007 18:51]

Report message to a moderator

Re: Prune stale users? [message #36097 is a reply to message #36088] Sun, 04 March 2007 17:46 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
You can use the fud_delete_user() function if FUDAPI and pass it an array of user id of the users you would like to delete.

FUDforum Core Developer
Re: Prune stale users? [message #36284 is a reply to message #36097] Tue, 13 March 2007 13:54 Go to previous messageGo to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
Pondering... It might be cool to have check boxes on the member list, (un)check all links, and a perform action pull down for delete/disable/ban/whatever, and then a confirmation page with a listing of those which were checked. Any thoughts on this?

I'm looking into writing a script using the fud api to check for and remove members with 0 post count and membership older than 3 months or so. I might even export the data to an undo sql script. I will have a few questions beginning my own script.

[Updated on: Tue, 13 March 2007 14:53]

Report message to a moderator

Re: Prune stale users? [message #36285 is a reply to message #36284] Tue, 13 March 2007 15:20 Go to previous messageGo to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
It is already complaining about fud_use. What other files must I include along with fudapi.inc.php and GLOBALS.php?
Re: Prune stale users? [message #36286 is a reply to message #36285] Tue, 13 March 2007 15:57 Go to previous messageGo to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
I managed to resolve the includes issue, but now I fail to understand why the following sql syntax is failing.

WHERE posted_msg_count=0

When I don't include that, it works. The following works. Now I need to add the deletions.

require_once("GLOBALS.php");
include_once($GLOBALS['DATA_DIR'] . "scripts/fudapi.inc.php");
fud_use('db.inc');
define('forum_debug', 1);

$query = "SELECT * FROM " . $GLOBALS['DBHOST_TBL_PREFIX']
            . "users ORDER BY join_date ASC";
$listing = _fud_simple_fetch_query(0, $query);
foreach ($listing as $user) {
    if (($user->posted_msg_count == 0) && ((time() - $user->join_date) >= 7257600) && ($user->id != 1)) {
        print "ID: " . $user->id . " ";
        print "Login: " . $user->login . " ";
        print "Joined: " . date('m/d/Y',$user->join_date) . " ";
        print "Posts: " . $user->posted_msg_count . " ";
        print "<br>\n";
    }
}

[Updated on: Tue, 13 March 2007 16:23]

Report message to a moderator

Re: Prune stale users? [message #36288 is a reply to message #36286] Tue, 13 March 2007 18:02 Go to previous messageGo to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
I have the following code now and it fails at the deletion line:

require_once ( "GLOBALS.php" );
include_once ( $GLOBALS['DATA_DIR'] . "scripts/fudapi.inc.php" );
fud_use ( 'db.inc' );
define ( 'forum_debug', 1 );

$num_days = 60; /* Number of days to keep stale users */

$query = "SELECT * FROM " . $GLOBALS['DBHOST_TBL_PREFIX']
            . "users ORDER BY join_date ASC ";

$listing = _fud_simple_fetch_query( 0, $query );

$fh = fopen ( 'users.dump', 'w' );

foreach ( $listing as $user ) {
    if ( ( $user->posted_msg_count == 0 ) && ( $user->id != 1 )
            && ( time() - $user->join_date >= ( $num_days * 24 * 60 * 60 ) ) ) {
        print "Deleted ID: " . $user->id . " ";
        print "Login: " . $user->login . " ";
        print "Joined: " . date('m/d/Y',$user->join_date) . " ";
        print "Posts: " . $user->posted_msg_count . "\n";
        while ( list ( $key, $val ) = each ($user) )
            $vals[] = "'".$val."'";
        $sqlcode = 'INSERT INTO users VALUES ('.join(', ', $vals).');';
        fwrite ( $fh, $sqlcode."\n" );
        fud_delete_user ( $user->id );
    }
    $vals = "";
}

fclose ( $fh );


1054: Unknown column 'Object' in 'where clause'
Query: DELETE FROM fud26_mod WHERE user_id IN(Object)
Re: Prune stale users? [message #36289 is a reply to message #36288] Tue, 13 March 2007 18:21 Go to previous messageGo to next message
Marticus   United States
Messages: 272
Registered: June 2002
Karma: 1
Senior Member
My Finished product. Not using fudAPI user delete. This creates a sql dump file of the deleted users in case they need to be reinserted, but using the api would probably be better. I run the command './purge.php > log' and the log file shows a nicely formatted listing of deleted users.

require_once ( "GLOBALS.php" );
include_once ( $GLOBALS['DATA_DIR'] . "scripts/fudapi.inc.php" );
fud_use ( 'db.inc' );
include_once ( '../include/users_adm.inc' );

define ( 'forum_debug', 1 );

$num_days = 60; /* Number of days to keep stale users */

$query = "SELECT * FROM " . $GLOBALS['DBHOST_TBL_PREFIX']
            . "users ORDER BY join_date ASC ";

$listing = _fud_simple_fetch_query( 0, $query );

$fh = fopen ( 'users.dump', 'w' );

foreach ( $listing as $user ) {
    if ( ( $user->posted_msg_count == 0 ) && ( $user->id != 1 )
            && ( time() - $user->join_date >= ( $num_days * 24 * 60 * 60 ) ) ) {
        print "Deleted ID: " . $user->id . " ";
        print "Login: " . $user->login . " ";
        print "Joined: " . date('m/d/Y',$user->join_date) . " ";
        print "Posts: " . $user->posted_msg_count . "\n";
        while ( list ( $key, $val ) = each ($user) )
            $vals[] = "'".$val."'";
        $sqlcode = 'INSERT INTO users VALUES ('.join(', ', $vals).');';
        fwrite ( $fh, $sqlcode."\n" );
        usr_delete($user->id);
    }
    $vals = "";
}

fclose ( $fh );
Re: Prune stale users? [message #163633 is a reply to message #36289] Sat, 20 November 2010 17:32 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
User Pruning is now a standard feature of FUDforum 3.0.2.
Re: Prune stale users? [message #163634 is a reply to message #163633] Sat, 20 November 2010 18:51 Go to previous messageGo to next message
Ernesto is currently offline  Ernesto   Sweden
Messages: 413
Registered: August 2005
Karma: 0
Senior Member
Generally user pruning is a pretty bad practice and it is rarely done, if ever, by bigger websites. If I was inactive for 30 days and suddenly when I come back from vacation, my account is gone, I surely would not register again, I would stop using the site for all eternity.

If the issue is to show active users or something like that in the memberlist or in the membercount, there are much much much better ways to do this than to purge user accounts.


Perhaps you could share with us the goal with the purging and we can perhaps find a better way than deleting user accounts? They don't take any room in your database and I really can't see any benefits from doing it, so please share and make me a more knowledgable man!


icon6.gif  Re: Prune stale users? [message #163635 is a reply to message #163634] Sat, 20 November 2010 22:11 Go to previous messageGo to next message
The Witcher is currently offline  The Witcher   United States
Messages: 675
Registered: May 2009
Location: USA
Karma: 3
Senior Member
Like most things in life it depends on certain variables, FUDforum org is global by its very nature as a development forum. So it seems pretty normal for it to have thousands of registered users who register just to keep informed about things peculiar to FUDforum even though they don't actually participate beyond reading what they are subscribed to.

The same would apply to Ginnunga (where I am a member with zero posts) although I frequently use it as an example of FUDforum's versatility.

Personally I would like to see more flexibility in this aspect of the forum (it will happen eventually) but for now deleting users with zero posts that haven't logged on after a certain date is a reasonable action (though not one I'd prefer in every instance).




"I'm a Witcher, I solve human problems; not always using a sword!"
Re: Prune stale users? [message #163636 is a reply to message #163635] Sun, 21 November 2010 03:13 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
It's just a check box feature. Running it is optional and if you think it's a bad idea, you don't have to use it.

Who knows, if your forum is 10 years old (some fudforum sites are now approaching the 10 year mark) and you want to remove users that haven't logged on for the past 5 years, it may even make sense.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Embedding audio via html
Next Topic: Problem sending e-mail from the forum
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat May 11 06:42:03 GMT 2024

Total time taken to generate the page: 0.02506 seconds