Improve cleanup script to give users 1 month after warning before removing their account. Move user related logic into the user class. Add columns to the user_list table to track whether the user was warned about inactivity and the datetime of the warning.
This commit is contained in:
@@ -28,61 +28,47 @@ include(BASE."include/mail.php");
|
|||||||
|
|
||||||
notifyAdminsOfCleanupExecution();
|
notifyAdminsOfCleanupExecution();
|
||||||
|
|
||||||
/*
|
/* users inactive for 6 months that haven't been warned already */
|
||||||
$hSixMonth = inactiveSince(6);
|
$hUsersToWarn = unwarnedAndInactiveSince(6);
|
||||||
while($oRow = mysql_fetch_object($hSixMonth))
|
while($oRow = mysql_fetch_object($hUsersToWarn))
|
||||||
{
|
{
|
||||||
$oUser = new User($oRow->userid);
|
$oUser = new User($oRow->userid);
|
||||||
if($oUser->isMaintainer())
|
$oUser->warnForInactivity();
|
||||||
warnMaintainer($oUser->sEmail);
|
|
||||||
elseif(!hasDataAssociated($oRow->userid))
|
|
||||||
warnUser($oUser->sEmail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$hSevenMonth = inactiveSince(7);
|
/* warned >= 1 month ago */
|
||||||
while($oRow = mysql_fetch_object($hSevenMonth))
|
$hUsersToDelete = warnedSince(1);
|
||||||
|
while($oRow = mysql_fetch_object($hUsersToDelete))
|
||||||
{
|
{
|
||||||
$oUser = new User($oRow->userid);
|
$oUser = new User($oRow->userid);
|
||||||
if($oUser->isMaintainer())
|
if($oUser->isMaintainer())
|
||||||
deleteMaintainer($oRow->userid);
|
deleteMaintainer($oRow->userid);
|
||||||
elseif(!hasDataAssociated($oRow->userid))
|
elseif(!$oUser->hasDataAssociated())
|
||||||
deleteUser($oRow->userid);
|
deleteUser($oRow->userid);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
function inactiveSince($iMonths)
|
|
||||||
|
/* Users that are unwarned and inactive since $iMonths */
|
||||||
|
function unwarnedAndInactiveSince($iMonths)
|
||||||
{
|
{
|
||||||
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= stamp";
|
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= stamp AND inactivity_warned='false'";
|
||||||
$hResult = query_appdb($sQuery);
|
$hResult = query_appdb($sQuery);
|
||||||
return $hResult;
|
return $hResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasDataAssociated($iUserId)
|
/* users that were warned at least $iMonths ago */
|
||||||
|
function warnedSince($iMonths)
|
||||||
{
|
{
|
||||||
$sQuery = "SELECT count(userId) as c FROM appComments WHERE userId = $iUserId";
|
$sQuery = "SELECT userid FROM user_list WHERE DATE_SUB(CURDATE(),INTERVAL $iMonths MONTH) >= inactivity_warn_stamp ";
|
||||||
|
$sQuery .= "AND inactivity_warned='true'";
|
||||||
$hResult = query_appdb($sQuery);
|
$hResult = query_appdb($sQuery);
|
||||||
$ob = mysql_fetch_object($hResult);
|
return $hResult;
|
||||||
if($ob->c != 0) return true;
|
|
||||||
|
|
||||||
$sQuery = "SELECT count(userId) as c FROM appMaintainers WHERE userId = $iUserId";
|
|
||||||
$hResult = query_appdb($sQuery);
|
|
||||||
$ob = mysql_fetch_object($hResult);
|
|
||||||
if($ob->c != 0) return true;
|
|
||||||
|
|
||||||
$sQuery = "SELECT count(userId) as c FROM appVotes WHERE userId = $iUserId";
|
|
||||||
$hResult = query_appdb($sQuery);
|
|
||||||
$ob = mysql_fetch_object($hResult);
|
|
||||||
if($ob->c != 0) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function deleteUser($iUserId)
|
function deleteUser($iUserId)
|
||||||
{
|
{
|
||||||
$oUser = new User($iUserId);
|
$oUser = new User($iUserId);
|
||||||
# TO BE UNCOMMENTED WHEN THERE WILL BE LESS INACTIVE USERS IN THE DATABASE
|
warnUserDeleted($oUser->sEmail);
|
||||||
# warnUserDeleted($oUser->sEmail);
|
|
||||||
$oUser->delete();
|
$oUser->delete();
|
||||||
echo "user ".$oUser->sEmail." deleted.\n";
|
echo "user ".$oUser->sEmail." deleted.\n";
|
||||||
}
|
}
|
||||||
@@ -92,30 +78,10 @@ function deleteMaintainer($iUserId)
|
|||||||
$oUser = new User($iUserId);
|
$oUser = new User($iUserId);
|
||||||
$sQuery = "DELETE FROM appMaintainers WHERE userId = $iUserId";
|
$sQuery = "DELETE FROM appMaintainers WHERE userId = $iUserId";
|
||||||
$hResult = query_appdb($sQuery);
|
$hResult = query_appdb($sQuery);
|
||||||
# TO BE UNCOMMENTED WHEN THERE WILL BE LESS INACTIVE USERS IN THE DATABASE
|
warnMaintainerDeleted($oUser->sEmail);
|
||||||
# warnMaintainerDeleted($oUser->sEmail);
|
|
||||||
echo "user ".$oUser->sEmail." is not a maintainer anymore.\n";
|
echo "user ".$oUser->sEmail." is not a maintainer anymore.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function warnUser($sEmail)
|
|
||||||
{
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function warnMaintainer($sEmail)
|
|
||||||
{
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function warnUserDeleted($sEmail)
|
function warnUserDeleted($sEmail)
|
||||||
{
|
{
|
||||||
$sSubject = "Warning: account removed";
|
$sSubject = "Warning: account removed";
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class User {
|
|||||||
var $sStamp;
|
var $sStamp;
|
||||||
var $sDateCreated;
|
var $sDateCreated;
|
||||||
var $sWineRelease;
|
var $sWineRelease;
|
||||||
|
var $bInactivityWarned;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -36,6 +37,7 @@ class User {
|
|||||||
$this->sStamp = $oRow->stamp;
|
$this->sStamp = $oRow->stamp;
|
||||||
$this->sDateCreated = $oRow->created;
|
$this->sDateCreated = $oRow->created;
|
||||||
$this->sWineRelease = $oRow->CVSrelease;
|
$this->sWineRelease = $oRow->CVSrelease;
|
||||||
|
$this->bInactivityWarned = $oRow->inactivity_warned;
|
||||||
}
|
}
|
||||||
return $this->isLoggedIn();
|
return $this->isLoggedIn();
|
||||||
}
|
}
|
||||||
@@ -60,8 +62,8 @@ class User {
|
|||||||
$this->sWineRelease = $oRow->CVSrelease;
|
$this->sWineRelease = $oRow->CVSrelease;
|
||||||
if($this->isLoggedIn())
|
if($this->isLoggedIn())
|
||||||
{
|
{
|
||||||
// Update timestamp
|
// Update timestamp and clear the inactivity flag if it was set
|
||||||
query_appdb("UPDATE user_list SET stamp=null WHERE userid=".$this->iUserId);
|
query_appdb("UPDATE user_list SET stamp=NOW(), inactivity_warned='false' WHERE userid=".$this->iUserId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -632,6 +634,7 @@ class User {
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isVersionSubmitter($iVersionId)
|
function isVersionSubmitter($iVersionId)
|
||||||
{
|
{
|
||||||
$sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily
|
$sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily
|
||||||
@@ -644,6 +647,57 @@ class User {
|
|||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if this user has data associated with them we will return true */
|
||||||
|
/* otherwise we return false */
|
||||||
|
function hasDataAssociated()
|
||||||
|
{
|
||||||
|
$sQuery = "SELECT count(userId) as c FROM appComments WHERE userId = $this->iUserId";
|
||||||
|
$hResult = query_appdb($sQuery);
|
||||||
|
$ob = mysql_fetch_object($hResult);
|
||||||
|
if($ob->c != 0) return true;
|
||||||
|
|
||||||
|
$sQuery = "SELECT count(userId) as c FROM appMaintainers WHERE userId = $this->iUserId";
|
||||||
|
$hResult = query_appdb($sQuery);
|
||||||
|
$ob = mysql_fetch_object($hResult);
|
||||||
|
if($ob->c != 0) return true;
|
||||||
|
|
||||||
|
$sQuery = "SELECT count(userId) as c FROM appVotes WHERE userId = $this->iUserId";
|
||||||
|
$hResult = query_appdb($sQuery);
|
||||||
|
$ob = mysql_fetch_object($hResult);
|
||||||
|
if($ob->c != 0) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* warn the user that their account has been marked as inactive */
|
||||||
|
function warnForInactivity()
|
||||||
|
{
|
||||||
|
/* we don't want to warn users that have data associated with them */
|
||||||
|
if(hasDataAssociated())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->isMaintainer())
|
||||||
|
{
|
||||||
|
$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";
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$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($this->sEmail, $sSubject, $sMsg);
|
||||||
|
|
||||||
|
/* mark this user as being inactive and set the appropriate timestamp */
|
||||||
|
$sQuery = "update user_list set inactivity_warned='true', inactivity_warn_stamp=NOW() where userid=".$this->iUserId;
|
||||||
|
query_appdb($sQuery);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ create table user_list (
|
|||||||
realname text not null,
|
realname text not null,
|
||||||
email varchar(255) not null,
|
email varchar(255) not null,
|
||||||
created datetime not null,
|
created datetime not null,
|
||||||
|
inactivity_warn_stamp timestamp not null, /* the time we warned the user */
|
||||||
|
inactivity_warned enum('true','false') NOT NULL default 'false', /* if true, we warned the user */
|
||||||
CVSrelease text,
|
CVSrelease text,
|
||||||
unique key(userid),
|
unique key(userid),
|
||||||
unique(email)
|
unique(email)
|
||||||
|
|||||||
Reference in New Issue
Block a user