2005-01-19 05:03:07 +00:00
|
|
|
#!/usr/bin/php
|
|
|
|
|
<?php
|
|
|
|
|
##################################################
|
|
|
|
|
# this script has to be run once a month by cron #
|
|
|
|
|
# it's purpose is to clean the user's table. #
|
|
|
|
|
##################################################
|
|
|
|
|
|
|
|
|
|
include("path.php");
|
2005-01-30 00:57:34 +00:00
|
|
|
include(BASE."include/incl.php");
|
|
|
|
|
include(BASE."include/mail.php");
|
2005-01-19 05:03:07 +00:00
|
|
|
|
|
|
|
|
/*
|
2005-09-29 01:45:39 +00:00
|
|
|
* Warn users that have been inactive for some number of months
|
|
|
|
|
* If it has been some period of time since the user was warned
|
|
|
|
|
* the user is deleted if they don't have any pending appdb data
|
2005-01-19 05:03:07 +00:00
|
|
|
*/
|
|
|
|
|
|
2005-09-29 01:45:39 +00:00
|
|
|
$usersWarned = 0;
|
|
|
|
|
$usersDeleted = 0;
|
2005-09-30 01:37:57 +00:00
|
|
|
$usersWithData = 0; /* users marked for deletion that have data */
|
|
|
|
|
|
|
|
|
|
notifyAdminsOfCleanupStart();
|
2005-01-19 05:03:07 +00:00
|
|
|
|
2005-09-28 00:32:48 +00:00
|
|
|
/* users inactive for 6 months that haven't been warned already */
|
|
|
|
|
$hUsersToWarn = unwarnedAndInactiveSince(6);
|
2005-10-08 22:42:51 +00:00
|
|
|
notifyAdminsOfProgress("Got through unwarnedAndInactiveSince");
|
2005-09-28 00:32:48 +00:00
|
|
|
while($oRow = mysql_fetch_object($hUsersToWarn))
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-09-29 01:45:39 +00:00
|
|
|
$usersWarned++;
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($oRow->userid);
|
2005-09-28 00:32:48 +00:00
|
|
|
$oUser->warnForInactivity();
|
2005-10-05 00:42:35 +00:00
|
|
|
|
|
|
|
|
/* every 25 users send a progress email */
|
|
|
|
|
if(($usersWarned % 25) == 0)
|
|
|
|
|
emailProgress(0, $usersWarned);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
2005-10-05 00:42:35 +00:00
|
|
|
notifyAdminsOfProgress();
|
|
|
|
|
|
2005-09-28 00:32:48 +00:00
|
|
|
/* warned >= 1 month ago */
|
|
|
|
|
$hUsersToDelete = warnedSince(1);
|
2005-10-08 22:42:51 +00:00
|
|
|
notifyAdminsOfProgress("Got through warnedSince");
|
2005-09-28 00:32:48 +00:00
|
|
|
while($oRow = mysql_fetch_object($hUsersToDelete))
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($oRow->userid);
|
2005-09-29 01:45:39 +00:00
|
|
|
if(!$oUser->hasDataAssociated())
|
|
|
|
|
{
|
|
|
|
|
$usersDeleted++;
|
|
|
|
|
deleteUser($oRow->userid);
|
|
|
|
|
} else
|
|
|
|
|
{
|
2005-09-30 01:37:57 +00:00
|
|
|
/* is the user a maintainer? if so remove their maintainer privilages */
|
|
|
|
|
if($oUser->isMaintainer())
|
|
|
|
|
{
|
|
|
|
|
$oUser->deleteMaintainer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$usersWithData++;
|
2005-09-29 01:45:39 +00:00
|
|
|
}
|
2005-10-05 00:42:35 +00:00
|
|
|
|
|
|
|
|
/* every 25 users send a progress email */
|
|
|
|
|
if(($usersDeleted % 25) == 0)
|
|
|
|
|
emailProgress(1, $usersDeleted);
|
|
|
|
|
if(($usersWithData % 25) == 0)
|
|
|
|
|
emailProgress(2, $usersWithData);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
2005-09-30 01:37:57 +00:00
|
|
|
notifyAdminsOfCleanupExecution($usersWarned, $usersDeleted, $usersWithData);
|
2005-09-29 01:45:39 +00:00
|
|
|
|
2005-09-28 00:32:48 +00:00
|
|
|
|
|
|
|
|
/* Users that are unwarned and inactive since $iMonths */
|
|
|
|
|
function unwarnedAndInactiveSince($iMonths)
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-09-28 00:32:48 +00:00
|
|
|
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= stamp AND inactivity_warned='false'";
|
2005-10-08 22:42:51 +00:00
|
|
|
notifyAdminsOfProgress("in unwarnedAndInactiveSince ".$sQuery);
|
2005-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2005-10-08 22:42:51 +00:00
|
|
|
notifyAdminsOfProgress("in unwarnedAndInactiveSince after $hResult");
|
2005-01-19 05:03:07 +00:00
|
|
|
return $hResult;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-28 00:32:48 +00:00
|
|
|
/* users that were warned at least $iMonths ago */
|
|
|
|
|
function warnedSince($iMonths)
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-09-28 00:32:48 +00:00
|
|
|
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= inactivity_warn_stamp ";
|
|
|
|
|
$sQuery .= "AND inactivity_warned='true'";
|
2005-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2005-09-28 00:32:48 +00:00
|
|
|
return $hResult;
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteUser($iUserId)
|
|
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($iUserId);
|
2005-09-28 00:32:48 +00:00
|
|
|
warnUserDeleted($oUser->sEmail);
|
2005-02-14 18:21:27 +00:00
|
|
|
$oUser->delete();
|
2005-01-30 23:12:48 +00:00
|
|
|
echo "user ".$oUser->sEmail." deleted.\n";
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function warnUserDeleted($sEmail)
|
|
|
|
|
{
|
2005-01-30 00:57:34 +00:00
|
|
|
$sSubject = "Warning: account removed";
|
|
|
|
|
$sMsg = "You didn't log in in the past seven month to the AppDB.\r\n";
|
|
|
|
|
$sMsg .= "As you don't have any data associated to your account we have removed it.\r\n";
|
|
|
|
|
$sMsg .= "Please feel free to recreate an account anytime.\r\n";
|
|
|
|
|
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
2005-09-30 01:37:57 +00:00
|
|
|
function notifyAdminsOfCleanupStart()
|
|
|
|
|
{
|
|
|
|
|
$sSubject = "Cleanup script starting\r\n";
|
|
|
|
|
$sMsg = "Appdb cleanup cron script started.\r\n";
|
|
|
|
|
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
|
|
|
|
|
if($sEmail)
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-15 00:22:22 +00:00
|
|
|
/* email all admins that the appdb cleanup script is executing */
|
|
|
|
|
/* so we admins have some visibility into the background cleanup */
|
|
|
|
|
/* events of the appdb */
|
2005-09-30 01:37:57 +00:00
|
|
|
function notifyAdminsOfCleanupExecution($usersWarned, $usersDeleted, $usersWithData)
|
2005-09-15 00:22:22 +00:00
|
|
|
{
|
2005-09-30 01:37:57 +00:00
|
|
|
$sSubject = "Cleanup script summary\r\n";
|
2005-09-29 01:45:39 +00:00
|
|
|
$sMsg = "Appdb cleanup cron script executed.\r\n";
|
|
|
|
|
$sMsg .= "Status:\r\n";
|
|
|
|
|
$sMsg .= "Users warned:".$usersWarned." Users deleted:".$usersDeleted."\r\n";
|
2005-09-30 01:37:57 +00:00
|
|
|
$sMsg .= "Users pending deletion but have appdb data:".$usersWithData."\r\n";
|
2005-09-15 00:22:22 +00:00
|
|
|
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
|
|
|
|
|
if($sEmail)
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
|
|
|
|
}
|
2005-10-05 00:42:35 +00:00
|
|
|
|
|
|
|
|
/* email all admins that the appdb cleanup script is executing */
|
|
|
|
|
/* so we admins have some visibility into the background cleanup */
|
|
|
|
|
/* events of the appdb */
|
2005-10-08 22:42:51 +00:00
|
|
|
function notifyAdminsOfProgress($sMsg="")
|
2005-10-05 00:42:35 +00:00
|
|
|
{
|
|
|
|
|
$sSubject = "Cleanup script in the middle\r\n";
|
2005-10-08 22:42:51 +00:00
|
|
|
$sMsg .= "Appdb cleanup cron script is in between processing warnings and processing deletions.\r\n";
|
|
|
|
|
$sEmail = "cmorgan@alum.wpi.edu";
|
2005-10-05 00:42:35 +00:00
|
|
|
if($sEmail)
|
2005-10-08 22:42:51 +00:00
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
2005-10-05 00:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* email all admins that the appdb cleanup script is executing */
|
|
|
|
|
/* so we admins have some visibility into the background cleanup */
|
|
|
|
|
/* events of the appdb */
|
|
|
|
|
function emailProgress($value, $processedNumber)
|
|
|
|
|
{
|
|
|
|
|
$sSubject = "Cleanup script is processing\r\n";
|
|
|
|
|
if($value == 0)
|
|
|
|
|
$sMsg = "warning processed: ".$processedNumber;
|
|
|
|
|
else if($value == 1)
|
|
|
|
|
$sMsg = "deleting processed: ".$processedNumber;
|
|
|
|
|
else if($value == 2)
|
|
|
|
|
$sMsg = "deleting with data: ".$processedNumber;
|
|
|
|
|
|
2005-10-08 22:42:51 +00:00
|
|
|
$sEmail = "cmorgan@alum.wpi.edu";
|
2005-10-05 00:42:35 +00:00
|
|
|
if($sEmail)
|
2005-10-08 22:42:51 +00:00
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
2005-10-05 00:42:35 +00:00
|
|
|
}
|
2005-01-19 05:03:07 +00:00
|
|
|
?>
|