[ABD] prune inactive users

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

[ABD] prune inactive users

Post by Niels Chr. Denmark » Tue Apr 09, 2002 10:41 pm

There have been a request making a mod that will delete inactive users, I have made this, witch work as a "drop-in"

simply make a new file in the same path as you forum files, name it delete_users.php

here are how it should look

Code: Select all

<?
#########################################################
## Author: Niels Chr. Rød
## Nickname: Niels Chr. Denmark
## Email: ncr@db9.dk
##
## Ver 1.0.1
## Developed as a drop-in to phpBB2 ver 2.0.0
##
##
## phpBB2 drop-in mod, that checks for unused accounts for X days
## use the script while logged in as ADMIN, add the days=X as a extra parameter
## e.g. www.yourdomain.com/delete_users.php?days=10
## will delete all inactive accounts that are older than 10 days 
##
## Development history
## 1.0.0 - beta release
## 1.0.1 - fixed deletion of usergroups 
##
##
#########################################################

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

############################################### Do not change anything below this line #######################################

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

if ($userdata['user_level']!=ADMIN)
      message_die(GENERAL_ERROR, $lang['Not_Authorised']);

$sql=' FROM '. USERS_TABLE .' WHERE user_id<>"-1" AND user_lastvisit=0 AND user_regdate<'.(time()-(86400*$days));
if(!$result = $db->sql_query('SELECT user_id '.$sql))
	message_die(GENERAL_ERROR, 'Error obtaining userdata', '', __LINE__, __FILE__, $sql);
$user_list = $db->sql_fetchrow($result); 
if(!$result = $db->sql_query('DELETE ' .$sql))
	message_die(GENERAL_ERROR, 'Error obtaining userdata', '', __LINE__, __FILE__, $sql);
$i=0;
while ($user_list[$i]['user_id'])
{
	$sql='DELETE FROM ' . USER_GROUP_TABLE . ' WHERE user_id='.$user_list[$i++]['user_id'];
	if(!$result = $db->sql_query($sql)) 
		message_die(GENERAL_ERROR, 'Error deleting '.$counts['old_users'].'user group', '', __LINE__, __FILE__, $sql);
}
$messages.=$i.' users have never logged into the board the past '.$days.' days, they have been removed';

message_die(GENERAL_MESSAGE,$messages.'</br> click <A HREF="'.append_sid("index.$phpEx").'">here</A> to return '); 
?>
Last edited by Niels Chr. Denmark on Wed Apr 10, 2002 6:55 pm, edited 2 times in total.

User avatar
Rocketeer
Registered User
Posts: 108
Joined: Thu Sep 06, 2001 11:43 pm
Location: Coventry, UK
Contact:

Post by Rocketeer » Tue Apr 09, 2002 10:53 pm

Just a quick point... your script instructs people to use the GET variable days (ie ?days=10), but you use the variable $d in the rest of the script.

Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

Post by Niels Chr. Denmark » Tue Apr 09, 2002 11:01 pm

you are so right, thanks for showing me, I will correct this :D

blulegend
Registered User
Posts: 83
Joined: Wed Jan 30, 2002 5:41 pm

Post by blulegend » Tue Apr 09, 2002 11:11 pm

It would be good if you could set a minimum post count requirement before they are deleted.

So you can delete for example users who have been inactive for x days AND have less than x posts. Perhaps default is 0 posts.

User avatar
Coasters2k
Registered User
Posts: 106
Joined: Sat Oct 13, 2001 5:56 am
Location: Layer 2
Contact:

Post by Coasters2k » Wed Apr 10, 2002 1:47 am

Before I run it, it only deletes users that have not activated their account or never logged in right? It has nothing to do with user post numbers, correct?
Brandon Rodriguez
http://www.coasters2k.com

Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

Post by Niels Chr. Denmark » Wed Apr 10, 2002 1:55 am

Coasters2k wrote: Before I run it, it only deletes users that have not activated their account or never logged in right? It has nothing to do with user post numbers, correct?


the script will delete users who have never logged in (user_lastvisit=0), but only if they have registed more than X days ago, the script doesent look for if the user is inactive or not

e.g. 2 users have registed and never loged in, the one have registed for 1 month ago, while the other regiterd yesterday

if you then run this script with a parameter of 5 days, then only the first user will be deleted

User avatar
Coasters2k
Registered User
Posts: 106
Joined: Sat Oct 13, 2001 5:56 am
Location: Layer 2
Contact:

Post by Coasters2k » Wed Apr 10, 2002 2:14 am

Niels Chr. Denmark wrote:
Coasters2k wrote:Before I run it, it only deletes users that have not activated their account or never logged in right? It has nothing to do with user post numbers, correct?


the script will delete users who have never logged in (user_lastvisit=0), but only if they have registed more than X days ago, the script doesent look for if the user is inactive or not

e.g. 2 users have registed and never loged in, the one have registed for 1 month ago, while the other regiterd yesterday

if you then run this script with a parameter of 5 days, then only the first user will be deleted

That explains it. Thanks for the great mod! It's a much needed feature (ahem2.2ahem). :D
Brandon Rodriguez
http://www.coasters2k.com

Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

Post by Niels Chr. Denmark » Wed Apr 10, 2002 6:56 pm

New version is 1.0.1

The old version did only remove the users, not there assosiated user group, this new version also deletes the users personal usergroup

please update the plug-in

User avatar
Balak Racing
Registered User
Posts: 4
Joined: Fri Sep 21, 2001 8:29 pm
Location: Staten Island, NY
Contact:

Post by Balak Racing » Mon Apr 15, 2002 6:49 pm

I just ran this on my board, and for some reason, it also deletes all the posts associated with those users it deleted. I now have some weird threads where people are discussing something that was previously posted by someone who no longer exists.

Bryan
No man with a cool car needs to be justified - Gibby Haynes
My R/C Touring Car Page -> BALAKRACING.COM
My Message Board -> BALAKRACING BOARDS

evilenglishman
Registered User
Posts: 190
Joined: Mon Jan 14, 2002 2:19 pm
Location: UK
Contact:

Post by evilenglishman » Tue Apr 16, 2002 2:06 pm

Neils,
any chance of expanding your 'plug in' to include zero posters?

something along the lines of deleting posters with 0 amount of posts who registered more than XX days ago.

I guess its a lot to ask but this would help out a lot of admins I think.

evilenglishman
Registered User
Posts: 190
Joined: Mon Jan 14, 2002 2:19 pm
Location: UK
Contact:

Post by evilenglishman » Tue Apr 16, 2002 2:07 pm

Balak Racing wrote: I just ran this on my board, and for some reason, it also deletes all the posts associated with those users it deleted. I now have some weird threads where people are discussing something that was previously posted by someone who no longer exists.

Bryan


don't see how that is possible as it only removes people who haven't completed the registration process :?

Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

Post by Niels Chr. Denmark » Wed Apr 17, 2002 9:05 am

Balak Racing wrote: I just ran this on my board, and for some reason, it also deletes all the posts associated with those users it deleted. I now have some weird threads where people are discussing something that was previously posted by someone who no longer exists.

Bryan


It is true, that this mod should only delete users who have newer logged into the board (Last_visit=0), this means that a user can't have posted any post, since they have newer been loged into the board.
if the script anyway have deleted some users who have posted, then I guess you already had an error in your DB, witch ofcouse I can't help with
sorry to say that this mod have no cind of "roll back" function, so I hope you did a backup of the DB before using this mod....

User avatar
Balak Racing
Registered User
Posts: 4
Joined: Fri Sep 21, 2001 8:29 pm
Location: Staten Island, NY
Contact:

Post by Balak Racing » Wed Apr 17, 2002 12:31 pm

I think a lot of the people who were deleted were people who had created a user name back when my board was version 1.4.4. I ran this after converting to 2.0.0. I just thought it was weird that it deleted the posts as well as the user.

Bryan
No man with a cool car needs to be justified - Gibby Haynes
My R/C Touring Car Page -> BALAKRACING.COM
My Message Board -> BALAKRACING BOARDS

Niels Chr. Denmark
Registered User
Posts: 1320
Joined: Thu Jan 10, 2002 1:00 pm
Contact:

Post by Niels Chr. Denmark » Thu Apr 18, 2002 3:28 pm

Balak Racing wrote: I think a lot of the people who were deleted were people who had created a user name back when my board was version 1.4.4. I ran this after converting to 2.0.0. I just thought it was weird that it deleted the posts as well as the user.

Bryan

The script has not deleted the posts, they are for shure still there, but the way phpBB2 works, makes it not displaying posts made py none existing users...
a manual change to the DB can however correct this, e.g.
make a "dummy user", find the posts in the posts/posts_text table, and change the user_id in the posts table to the dummy users.


if someone is a SQL geek, I guess they can also make a SQL command that can do it all in one chuck, personally I am not shure how it should look, but here are the basic (it does NOT WORK) - maybe somone will se this and make one that does

Code: Select all

UPDATE p.poster_id VALUES (NEW_USER_ID) IN posts p, users u WHERE .......

the WHERE part of the SQL should only UPDATE those p.poster_id witch does not contain a valid p.poster_id, a p.poster_id is not valid if it is not found in u.user_id
if you are experimenting with the SQL command instead of the manual thing, then use the SELECT until it works, and then change to a UPDATE, otherwise you will end up having missed up your DB

PM me if you need more help about the manual update (if it is only a few posts)

User avatar
Teufel
Registered User
Posts: 13
Joined: Thu Apr 18, 2002 8:13 pm
Location: Canada
Contact:

automation?

Post by Teufel » Tue Apr 23, 2002 10:30 pm

I'm just curious if it would be difficult to automate this the same way you can with the pruning of forums where you can Auto-Prune every X number of days and look for more items to prune every Y number of days. I personally think that small function would be a nice improvement, if it's not already built in (haven't tried it just yet, will today).

Locked

Return to “[2.0.x] MODs in Development”

Who is online

Users browsing this forum: No registered users and 10 guests