Simple Machines Community Forum

SMF Development => Feature Requests => Applied or Declined Requests => Aiheen aloitti: greyknight17 - heinäkuu 29, 2004, 08:26:41 AP

Otsikko: Delete Inactive Members
Kirjoitti: greyknight17 - heinäkuu 29, 2004, 08:26:41 AP
I did a search in the forums and found 3 threads on this.  Some gave scripts to do it (not sure how it works).  I want to delete the accounts for inactive members (say 30 or 60 days if they're not logged in).  Is this feature available in Beta 5 or maybe the next version?

Thanks.
Otsikko: Re: Delete Inactive Members
Kirjoitti: Tristan Perry - heinäkuu 29, 2004, 08:41:28 AP
You can always use the member search to do this but theres not that much point. I used to delete inactive members, but as my forum members pointed out, they may always come back. It also looks better to potentially new members if you have lots of members, just keeping the active ones may put new people off because your member count may be low.
Otsikko: Re: Delete Inactive Members
Kirjoitti: greyknight17 - heinäkuu 31, 2004, 09:17:31 AP
Yeah, I know about the searching up members method.  That will be tedious if there is a lot though.  I guess I could live with inactive members.  I don't have much members in my forum now anyway.

Thanks.
Otsikko: Re: Delete Inactive Members
Kirjoitti: Grudge - heinäkuu 31, 2004, 04:27:35 IP
In the admin center, if you go to "View Members" doesn't it allow you to sort by "last online". If so then just do that and use the checkboxes to quickly delete them...
Otsikko: Re: Delete Inactive Members
Kirjoitti: greyknight17 - elokuu 02, 2004, 10:38:19 AP
Yeah.  Tau mentioned that also.  I could do that for a few, but if there are a lot, it will be more work.  That's ok, I'll leave them alone for now.

Thanks.
Otsikko: Re: Delete Inactive Members
Kirjoitti: dschwab9 - elokuu 02, 2004, 03:00:23 IP
I've been working on a script for this.  You run it daily via a cron job.  It sends an email to everyone who hasn't logged on in 1 year and marks them as inactive in the database.  If they login without a week of getting the email, the inactive flag disapears.  If they haven't logged in after 1 week, they get deleted.

Only problem is I can't get it to actually delete people.  Everything else works.  I'll post it in a little while if someone wants to troubleshoot it.
Otsikko: Re: Delete Inactive Members
Kirjoitti: greyknight17 - elokuu 02, 2004, 03:10:54 IP
I probably won't understand it.  :)

Unless someone could work on it.
Otsikko: Re: Delete Inactive Members
Kirjoitti: dschwab9 - elokuu 02, 2004, 04:30:48 IP
Here's my script.  Something is wrong with the queries that actually do the deleting.  But, I just copied them from the delete member function in SMF, so I don't understand what's wrong with them.  Everything except that works.  It requires a tinyint field called "Inactive" added to the members table.

<?php
define
('SMF'1);
include_once 
"Settings.php";
include_once(
$sourcedir '/ManageMembers.php');
$dbcon mysql_connect($db_server$db_user$db_passwd);
mysql_select_db($db_name);
$old time() - (3600 24 365);
$delete time() - (3600 24 373);
$active time() - (3600 24 7);
$counter 0;

// Some inactive members may have gotten the reminder and logged in, so set them as active
mysql_query("UPDATE `{$db_prefix}members` SET Inactive=0 WHERE Inactive=1 AND `lastLogin` > $active AND `lastLogin` <>  '0';");

// Some don't care and will never login.  If they are marked at inactive, delete them after 373 days
$requestDel mysql_query("SELECT mem.`ID_MEMBER`, `memberName`,`realName` 
FROM `
{$db_prefix}members` AS mem
WHERE `lastLogin` < 
$delete AND `lastLogin`<>0 AND Inactive=1
ORDER BY `ID_MEMBER` ASC;"
);

// Loop through and actually do the deleting
while ($row mysql_fetch_array($requestDel)) 
{
// Make these peoples' posts guest posts.
$requestDel2 mysql_query("
UPDATE `
{$db_prefix}messages`
SET ID_MEMBER 0
WHERE ID_MEMBER 
$row['ID_MEMBER'];");

// Delete the member.
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}members`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");

// Delete the logs...
$requestDel2 mysql_query("DELETE FROM `{$db_prefix}log_topics`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}log_boards`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}log_mark_read`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}log_notify`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}log_online`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}collapsed_categories`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}themes`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");

// Delete personal messages.
include_once($sourcedir '/InstantMessage.php');
deleteMessages(nullnull$row['ID_MEMBER']);

$requestDel2 mysql_query("
UPDATE `
{$db_prefix}instant_messages`
SET ID_MEMBER_FROM = 0
WHERE ID_MEMBER_FROM 
$row['ID_MEMBER'];");

// Delete the moderator positions
$requestDel2 mysql_query("
DELETE FROM `
{$db_prefix}moderators`
WHERE ID_MEMBER 
$row['ID_MEMBER'];");

$delete++;
echo '<br/>Deleted user' $row['ID_MEMBER'] . ' (Username: ' $row['memberName'] . ', display name: ' $row['realName'] . ',';
}//end while

// Report what we did
echo "<br /><br />Deleted $delete users."

// Now, lets see if we have any inactive users to remind

// Email Template
$mail_subject "you have been inactive in $mbname";
$mail_body "you have been found inactive in $mbname for more 1 year. ";
$mail_body .= "\nForum maintenance will be done a week from now, and if you're still found inactive, your account will be deleted. ";
$mail_body .= "If you do not wish to have your account to be deleted, please log on and browse around the forum. ";
$mail_body .= "If you wish for your account to be deleted, just ignore this message. ";
$mail_body .= "Sorry for the inconvenience.\n\nRegards,\n$mbname team.\n$boardurl";

// Query the database for old members
$request mysql_query("SELECT mem.`ID_MEMBER`, `memberName`, `emailAddress` 
FROM `
{$db_prefix}members` AS mem
WHERE `lastLogin` < 
$old AND `lastLogin`<>0 AND Inactive=0
ORDER BY `ID_MEMBER` ASC;"
);

// Send them and email and mark them as inactive
while ($row mysql_fetch_array($request)) 
{
$mail_subject2 $row['memberName'] . ', ' $mail_subject;
$mail_body2 $row['memberName'] . ', ' $mail_body;
sendmail($row['emailAddress'], $mail_subject2$mail_body2);
echo ' <br/>Mail sent to: ' $row['emailAddress'] . ' (ID: ' $row['ID_MEMBER'] . ', Username: ' $row['memberName'] . ')';
$counter++;
$request2 mysql_query("UPDATE `{$db_prefix}members` SET Inactive=1 WHERE ID_MEMBER='$row[ID_MEMBER]'");
}
//end while

// Report what has been done
echo '<br/>Sent: '.$counter ' mails.';


// This actually sends the email
function sendmail($to$subject$message)
{
global $webmaster_email$mbname;
$chunkSize 50;

$to_array = (is_array($to) ? $to : array($to));

if ($from == null)
$from $webmaster_email;
$subject stripslashes($subject);
$subject str_replace(array('&quot;''&#039;''&amp;''&lt;''&gt;'), array('"''\'''&''<''>'), $subject);
$message stripslashes($message);
$headers "MIME-Version: 1.0\r\n";
$headers .= "From: \"$mbname\" <$webmaster_email>\r\n";
$headers .= "Return-Path: $webmaster_email";

foreach ($to_array as $to)
$mail_result mail($to$subject$message$headers);

return $mail_result;
}
?>
Otsikko: Re: Delete Inactive Members
Kirjoitti: greyknight17 - elokuu 03, 2004, 12:38:51 IP
Wow  :o

No idea on what to do with it.  :)

Are there any tutorials on this?
Otsikko: Re: Delete Inactive Members
Kirjoitti: Oldiesmann - elokuu 05, 2004, 03:06:52 IP
You forgot to tell it what to do with ID_MEMBER and $row[ID_MEMBER]. I don't know if something stripped out the = signs or what, but the first query in the while loop should say SET ID_MEMBER = 0 and all the others should say WHERE ID_MEMBER='$row[ID_MEMBER]'
Otsikko: Re: Delete Inactive Members
Kirjoitti: dschwab9 - elokuu 05, 2004, 05:38:46 IP
I copied and pasted most of that out of the delete members function in SMF, and there are no equal signs there.  I'll try them and see, but I'm pretty sure you don't need them.
Otsikko: Re: Delete Inactive Members
Kirjoitti: orange - elokuu 05, 2004, 06:19:28 IP
LainaaIn the admin center, if you go to "View Members" doesn't it allow you to sort by "last online". If so then just do that and use the checkboxes to quickly delete them...

The really annoying thing about this is that when you select some members and hit delete, it then returns to the Start Search page, so you have to enter all your search parameters again.

Please, Pretty please, could it be made to return to the search results after you delete members, to allow you to proceed onto the next page and delete some more.
Otsikko: Re: Delete Inactive Members
Kirjoitti: Davy-D - kesäkuu 14, 2005, 08:54:32 AP
Hi there,

although this feature request doesn't seem to be considered until SMF 1.0.4 I want to ask for it again.

Searching for users who haven't been online for a while is something one should not be forced to check manually.
Sometimes, search robots register in the board as well, they of course never login and/or post.
In my case, my server doesn't allow me to create cron- or at-jobs, so the only way for me would be to use a PHP script like dschwab9 did. By the way, dschwab9: did you manage to fix it in the meanwhile ?

Me personally as an admin, I would really appreciate, if you could add this feature within the admin panel.

Thank you,
Davy

Otsikko: Re: Delete Inactive Members
Kirjoitti: nokonium - kesäkuu 14, 2005, 03:48:11 IP
Doing it individually gives the option of deleting posts and whatnot, but a utility to delete zero post members who have been inactive for [whatever] y/n seems a good idea.
Otsikko: Re: Delete Inactive Members
Kirjoitti: [Unknown] - kesäkuu 14, 2005, 03:51:10 IP
Lainaus käyttäjältä: Davy-D - kesäkuu 14, 2005, 08:54:32 AP
although this feature request doesn't seem to be considered until SMF 1.0.4 I want to ask for it again.

No, it was *considered*.  Just because you think it is the greatest thing since sliced bread doesn't mean that considering is the same as immediately implementing.

-[Unknown]
Otsikko: Re: Delete Inactive Members
Kirjoitti: TarantinoArchives - elokuu 25, 2005, 09:21:48 AP
i deleted about 2000 accounts last night by hand (checkboxes...) duh...

i think SMF really should integrate a little function that would allow creating a member group based on "last online"... that would be cool. so you could just create a membergroup with "last online: longer than 10 months ago) or something. and delete those in one bit
Otsikko: Re: Delete Inactive Members
Kirjoitti: mennou - elokuu 25, 2005, 09:47:11 AP
how u do that?  cuz mine never  seem to work... it 's only give me  choice   .. the regular group won't showing up.. where i  have most of my  members....
Otsikko: Re: Delete Inactive Members
Kirjoitti: TarantinoArchives - syyskuu 01, 2005, 05:48:57 AP
i go to the members list and click the members i want to delete
Otsikko: Re: Delete Inactive Members
Kirjoitti: MTO - marraskuu 29, 2005, 08:59:09 IP
I have 18000 members and I really need this feature as well.
Otsikko: Re: Delete Inactive Members
Kirjoitti: TarantinoArchives - joulukuu 02, 2005, 02:51:20 IP
seems like features like this are not a priority for anyone right now.....
Otsikko: Re: Delete Inactive Members
Kirjoitti: Ben_S - joulukuu 02, 2005, 03:41:15 IP
No new features will be implemented untill 1.2 now that 1.1 is at release candidate.
Otsikko: Re: Delete Inactive Members
Kirjoitti: SONSiVRi - lokakuu 25, 2007, 08:25:53 AP
Lainaus käyttäjältä: Grudge - heinäkuu 31, 2004, 04:27:35 IP
In the admin center, if you go to "View Members" doesn't it allow you to sort by "last online". If so then just do that and use the checkboxes to quickly delete them...

After that messages posted by those "deleted users" wont be deleted.
I wanted to delete posts as well as users in a member search list but it seems no feature yet.
There are users who posted less than 10 and I want to rip them off completely.