Automatically remind / delete unactivated members?

Started by mytreo, May 11, 2006, 05:04:03 AM

Previous topic - Next topic

mytreo

Has anyone automated the process of reminding and deleting unactivated members? (Don't want to reinvent the wheel if you have!)

We get a lot of unactivated members, maybe 10%, and going through the registration management every week reminding and deleting them all is tedious.

I envisage either a cron or some function triggered by the registration process which will remind all unactivated members after say 24 hours, and delete unactivated members older than 7 days.

Anyone tried this? Or have any suggestion how to do it?

Cheers
Chris
Treo forum - Powered by SMF, of course
Treo news - powered by MovableType and integrated with SMF
Treo downloads - hacked from phpNuke and integrated with SMF
Treo knowledge base - powered by Wikka and integrated with SMF
Treo 650 | Treo 700w | Treo 700p

mytreo

#1
Well noone answered (I am impatient!) and I can't find anything so I wrote two admin functions to help me out. Code below for anyone else who wants it. Don't ask me for support though :)

Problems I encountered:

"function deleteMembers" is INCREDIBLY SLOW on a large forum because it goes through all the log files, not really neccessary for a member who was never activated, so I didn't use it.

Couldn't work out a way to automate it fully, so just made a button in my admin section instead. Anyone has any ideas on automating this then feel free to chip in.

Some SQL, ADJUST AS NECCESSARY.

ALTER TABLE `smforum_members` ADD `regReminderSent` INT( 2 ) NOT NULL DEFAULT '0' AFTER `validation_code` ;

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoSendReminders', '0'
);

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoSendFirstReminder', '1'
);

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoSendRemindersLimit', '3'
);

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoLastSendReminders', '1'
);

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoDeleteUnactivated', '14'
);

INSERT INTO `smforum_settings` ( `variable` , `value` )
VALUES (
'autoLastPruneUnactivated', '1'
);



Add new functions to bottom of Sources/Register.php

// Automatically send registration reminders
function AdminAutoReminders()
{
global $txt, $context, $db_prefix, $scripturl, $modSettings, $sourcedir;

require_once($sourcedir . '/Subs-Post.php');

// Basic stuff.
//$context['sub_template'] = 'admin_nothing';

// Is it time to do this again? Don't want to bug people!
if (empty($modSettings['autoSendReminders']) || $modSettings['autoLastSendReminders'] + $modSettings['autoSendReminders'] * 3600 * 24 >= time())
return;

// Find the unactivated members that need reminding
$request = db_query("
SELECT ID_MEMBER, memberName, emailAddress, memberIP, dateRegistered, validation_code, regReminderSent
FROM {$db_prefix}members
WHERE is_activated = 0
AND validation_code !=''
AND ((dateRegistered + ( " .$modSettings['autoSendFirstReminder']. " * 3600 * 24)) <= ". time() .")
AND regReminderSent < " .$modSettings['autoSendRemindersLimit']. "
ORDER BY ID_MEMBER", __FILE__, __LINE__);

// Send them each an email
while ($row = mysql_fetch_assoc($request))
{
sendmail($row['emailAddress'], $txt['admin_approve_remind'],
"".$row['memberName'].",\n\n" .
"$txt[admin_approve_remind_desc] $context[forum_name].\n\n$txt[admin_approve_remind_desc2]\n\n" .
"$scripturl?action=activate;u=".$row['ID_MEMBER'].";code=".$row['validation_code']."\n\n" .
$txt[130]);

// Update regReminderSent + 1
db_query("
UPDATE {$db_prefix}members
SET regReminderSent = (".$row['regReminderSent']." + 1)
WHERE ID_MEMBER = ".$row['ID_MEMBER']."
LIMIT 1", __FILE__, __LINE__);
//print(date("Y-m-d H:i:s",$row['dateRegistered'])." | ".$row['ID_MEMBER']." | ".$row['emailAddress']."<br/>");
}
mysql_free_result($request);

updateSettings(array('autoLastSendReminders' => time()));

// Update the member's stats.
updateStats('member');

redirectexit('action=regcenter;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';start=' . $_REQUEST['start']);

}


// Automatically delete unactivated members
function AdminAutoPruneUnactivated()
{
global $txt, $context, $db_prefix, $scripturl, $modSettings, $sourcedir;

require_once($sourcedir . '/Subs-Post.php');

//Basic stuff.
//$context['sub_template'] = 'admin_nothing';

// Is it time to do this again?
//if (empty($modSettings['autoSendReminders']) || $modSettings['autoLastSendReminders'] + $modSettings['autoSendReminders'] * 3600 * 24 >= time())
// return;

// Find the unactivated members that need deleting
$request = db_query("
SELECT ID_MEMBER, memberName, emailAddress, memberIP, dateRegistered, validation_code, regReminderSent
FROM {$db_prefix}members
WHERE is_activated = 0
AND validation_code !=''
AND ((dateRegistered + (" .$modSettings['autoDeleteUnactivated']. " * 3600 * 24)) <= ". time() .")", __FILE__, __LINE__);

// Send them each an email
while ($row = mysql_fetch_assoc($request))
{
//require_once($sourcedir . '/ManageMembers.php');
//deleteMembers($row['ID_MEMBER']);

db_query("
DELETE FROM {$db_prefix}members
WHERE ID_MEMBER = ".$row['ID_MEMBER']."
LIMIT 1", __FILE__, __LINE__);

// Send email telling them they aren't welcome?
/*if ($_POST['todo'] == 'deleteemail')
sendmail($email, $txt['admin_approve_delete'],
"$username,\n\n" .
"$txt[admin_approve_delete_desc]\n\n" .
$txt[130]); */

//print(date("Y-m-d H:i:s",$row['dateRegistered'])." | ".$row['ID_MEMBER']." | ".$row['emailAddress']."<br/>");
}
mysql_free_result($request);

updateSettings(array('autoLastPruneUnactivated' => time()));

// Update the member's stats.
updateStats('member');

redirectexit('action=regcenter;sa=browse;type=' . $_REQUEST['type'] . ';sort=' . $_REQUEST['sort'] . ';start=' . $_REQUEST['start']);

}


Change

$subActions = array(
'register' => 'AdminRegister',
'register2' => 'Register2',
'browse' => 'AdminBrowse',
'approve' => 'AdminApprove'
);


to

$subActions = array(
'register' => 'AdminRegister',
'register2' => 'Register2',
'browse' => 'AdminBrowse',
'approve' => 'AdminApprove',
'remindall' => 'AdminAutoReminders',
'pruneold' => 'AdminAutoPruneUnactivated'
);


And that is it really. Make the action available in your template with ?action=regcenter;sa=remindall or ?action=regcenter;sa=pruneold. I haven't yet put the options into the Admin settings template.
Treo forum - Powered by SMF, of course
Treo news - powered by MovableType and integrated with SMF
Treo downloads - hacked from phpNuke and integrated with SMF
Treo knowledge base - powered by Wikka and integrated with SMF
Treo 650 | Treo 700w | Treo 700p

Advertisement: