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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hSixMonth = inactiveSince(6);
|
|
|
|
|
while($oRow = mysql_fetch_object($hSixMonth))
|
|
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($oRow->userid);
|
|
|
|
|
if($oUser->isMaintainer())
|
|
|
|
|
warnMaintainer($oUser->sEmail);
|
2005-01-19 05:03:07 +00:00
|
|
|
elseif(!hasDataAssociated($oRow->userid))
|
2005-01-30 23:12:48 +00:00
|
|
|
warnUser($oUser->sEmail);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$hSevenMonth = inactiveSince(7);
|
|
|
|
|
while($oRow = mysql_fetch_object($hSevenMonth))
|
|
|
|
|
{
|
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);
|
|
|
|
|
elseif(!hasDataAssociated($oRow->userid))
|
|
|
|
|
deleteUser($oRow->userid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function inactiveSince($iMonths)
|
|
|
|
|
{
|
|
|
|
|
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= stamp";
|
|
|
|
|
$hResult = query_appdb($sQuery);
|
|
|
|
|
return $hResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasDataAssociated($iUserId)
|
|
|
|
|
{
|
2005-02-15 19:19:36 +00:00
|
|
|
$sQuery = "SELECT count(userId) as c FROM appComments WHERE userId = $iUserId";
|
2005-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2005-02-15 19:19:36 +00:00
|
|
|
$ob = mysql_fetch_object($hResult);
|
|
|
|
|
if($ob->c != 0) return true;
|
2005-01-19 05:03:07 +00:00
|
|
|
|
2005-02-15 19:19:36 +00:00
|
|
|
$sQuery = "SELECT count(userId) as c FROM appMaintainerQueue WHERE userId = $iUserId";
|
2005-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2005-02-15 19:19:36 +00:00
|
|
|
$ob = mysql_fetch_object($hResult);
|
|
|
|
|
if($ob->c != 0) return true;
|
2005-01-19 05:03:07 +00:00
|
|
|
|
2005-02-15 19:19:36 +00:00
|
|
|
$sQuery = "SELECT count(userId) as c FROM appVotes WHERE userId = $iUserId";
|
2005-01-19 05:03:07 +00:00
|
|
|
$hResult = query_appdb($sQuery);
|
2005-02-15 19:19:36 +00:00
|
|
|
$ob = mysql_fetch_object($hResult);
|
|
|
|
|
if($ob->c != 0) return true;
|
2005-01-19 05:03:07 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function deleteUser($iUserId)
|
|
|
|
|
{
|
2005-01-30 23:12:48 +00:00
|
|
|
$oUser = new User($iUserId);
|
2005-02-14 18:21:27 +00:00
|
|
|
# TO BE UNCOMMENTED WHEN THERE WILL BE LESS INACTIVE USERS IN THE DATABASE
|
|
|
|
|
# warnUserDeleted($oUser->sEmail);
|
|
|
|
|
$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-02-14 18:21:27 +00:00
|
|
|
# TO BE UNCOMMENTED WHEN THERE WILL BE LESS INACTIVE USERS IN THE DATABASE
|
|
|
|
|
# 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 warnUser($sEmail)
|
|
|
|
|
{
|
2005-01-30 00:57:34 +00:00
|
|
|
$sSubject = "Warning: inactivity detected";
|
|
|
|
|
$sMsg = "You didn't log in in the past six month to the AppDB.\r\n";
|
|
|
|
|
$sMsg .= "Please log in or your account will automatically be deleted in one month.\r\n";
|
|
|
|
|
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
2005-01-19 05:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function warnMaintainer($sEmail)
|
|
|
|
|
{
|
2005-01-30 00:57:34 +00:00
|
|
|
$sSubject = "Warning: inactivity detected";
|
|
|
|
|
$sMsg = "You didn't log in in the past six month to the AppDB.\r\n";
|
|
|
|
|
$sMsg .= "As a maintainer we would be pleased to see you once in a while.\r\n";
|
|
|
|
|
$sMsg .= "Please log in or you will lose your maintainer's abilities in one month.\r\n";
|
|
|
|
|
|
|
|
|
|
mail_appdb($sEmail, $sSubject, $sMsg);
|
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
|
|
|
}
|
|
|
|
|
?>
|