Prune stale users? [message #36088] |
Sat, 03 March 2007 18:51 |
Marticus
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 |
Ilia
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 |
Marticus
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 #36286 is a reply to message #36285] |
Tue, 13 March 2007 15:57 |
Marticus
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 |
Marticus
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 |
Marticus
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 #163634 is a reply to message #163633] |
Sat, 20 November 2010 18:51 |
Ernesto
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!
Ginnunga Gaming
|
|
|
|
|