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
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Let:
|
|
|
|
|
* 1) you did not log in for six month
|
|
|
|
|
* 2) you don't have any data associated
|
|
|
|
|
* 3) you are a maintainer
|
|
|
|
|
* 4) you receive a warning e-mail
|
|
|
|
|
* 5) you did not log in for seven month
|
|
|
|
|
* 6) your account is deleted
|
|
|
|
|
* 7) you are not a maintainer anymore
|
|
|
|
|
*
|
|
|
|
|
* The rules are the following:
|
|
|
|
|
* if(1 AND 2) then 4
|
|
|
|
|
* if(1 AND 3) then 4
|
|
|
|
|
* if(5 AND 2) then 6
|
|
|
|
|
* if(5 AND 3) then 7
|
|
|
|
|
*/
|
|
|
|
|
|
2005-09-15 00:22:22 +00:00
|
|
|
notifyAdminsOfCleanupExecution();
|
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);
|
|
|
|
|
while($oRow = mysql_fetch_object($hUsersToWarn))
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($oRow->userid);
|
2005-09-28 00:32:48 +00:00
|
|
|
$oUser->warnForInactivity();
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
2005-09-28 00:32:48 +00:00
|
|
|
/* warned >= 1 month ago */
|
|
|
|
|
$hUsersToDelete = warnedSince(1);
|
|
|
|
|
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);
|
|
|
|
|
if($oUser->isMaintainer())
|
2005-01-19 05:03:07 +00:00
|
|
|
deleteMaintainer($oRow->userid);
|
2005-09-28 00:32:48 +00:00
|
|
|
elseif(!$oUser->hasDataAssociated())
|
2005-01-19 05:03:07 +00:00
|
|
|
deleteUser($oRow->userid);
|
|
|
|
|
}
|
|
|
|
|
|
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-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2005-01-30 23:12:48 +00:00
|
|
|
function deleteMaintainer($iUserId)
|
2005-01-19 05:03:07 +00:00
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($iUserId);
|
2005-01-19 05:03:07 +00:00
|
|
|
$sQuery = "DELETE FROM appMaintainers WHERE userId = $iUserId";
|
|
|
|
|
$hResult = query_appdb($sQuery);
|
2005-09-28 00:32:48 +00:00
|
|
|
warnMaintainerDeleted($oUser->sEmail);
|
2005-01-30 23:12:48 +00:00
|
|
|
echo "user ".$oUser->sEmail." is not a maintainer anymore.\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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function warnMaintainerDeleted($sEmail)
|
|
|
|
|
{
|
2005-01-30 00:57:34 +00:00
|
|
|
$sSubject = "Warning: maintainer rights revoked\r\n";
|
|
|
|
|
$sMsg = "You didn't log in in the past seven month to the AppDB.\r\n";
|
|
|
|
|
$sMsg .= "As a result, you are not a maintainer anymore.\r\n";
|
|
|
|
|
$sMsg .= "Please feel free to enroll again as a maintainer anytime.\r\n";
|
|
|
|
|
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
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 */
|
|
|
|
|
function notifyAdminsOfCleanupExecution()
|
|
|
|
|
{
|
|
|
|
|
$sSubject = "Cleanup script running\r\n";
|
|
|
|
|
$sMsg = "Appdb cleanup cron script is executing.\r\n";
|
|
|
|
|
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
|
|
|
|
|
if($sEmail)
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
|
|
|
|
}
|
2005-01-19 05:03:07 +00:00
|
|
|
?>
|