diff --git a/cron/cleanup.php b/cron/cleanup.php index 95f3b8d..152cbdb 100644 --- a/cron/cleanup.php +++ b/cron/cleanup.php @@ -28,61 +28,47 @@ include(BASE."include/mail.php"); notifyAdminsOfCleanupExecution(); -/* -$hSixMonth = inactiveSince(6); -while($oRow = mysql_fetch_object($hSixMonth)) +/* users inactive for 6 months that haven't been warned already */ +$hUsersToWarn = unwarnedAndInactiveSince(6); +while($oRow = mysql_fetch_object($hUsersToWarn)) { $oUser = new User($oRow->userid); - if($oUser->isMaintainer()) - warnMaintainer($oUser->sEmail); - elseif(!hasDataAssociated($oRow->userid)) - warnUser($oUser->sEmail); + $oUser->warnForInactivity(); } -$hSevenMonth = inactiveSince(7); -while($oRow = mysql_fetch_object($hSevenMonth)) +/* warned >= 1 month ago */ +$hUsersToDelete = warnedSince(1); +while($oRow = mysql_fetch_object($hUsersToDelete)) { $oUser = new User($oRow->userid); if($oUser->isMaintainer()) deleteMaintainer($oRow->userid); - elseif(!hasDataAssociated($oRow->userid)) + elseif(!$oUser->hasDataAssociated()) 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); 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); - $ob = mysql_fetch_object($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; + return $hResult; } - function deleteUser($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(); echo "user ".$oUser->sEmail." deleted.\n"; } @@ -92,30 +78,10 @@ function deleteMaintainer($iUserId) $oUser = new User($iUserId); $sQuery = "DELETE FROM appMaintainers WHERE userId = $iUserId"; $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"; } -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) { $sSubject = "Warning: account removed"; diff --git a/include/user.php b/include/user.php index 85244f0..e336e75 100644 --- a/include/user.php +++ b/include/user.php @@ -15,6 +15,7 @@ class User { var $sStamp; var $sDateCreated; var $sWineRelease; + var $bInactivityWarned; /** * Constructor. @@ -36,6 +37,7 @@ class User { $this->sStamp = $oRow->stamp; $this->sDateCreated = $oRow->created; $this->sWineRelease = $oRow->CVSrelease; + $this->bInactivityWarned = $oRow->inactivity_warned; } return $this->isLoggedIn(); } @@ -60,8 +62,8 @@ class User { $this->sWineRelease = $oRow->CVSrelease; if($this->isLoggedIn()) { - // Update timestamp - query_appdb("UPDATE user_list SET stamp=null WHERE userid=".$this->iUserId); + // Update timestamp and clear the inactivity flag if it was set + query_appdb("UPDATE user_list SET stamp=NOW(), inactivity_warned='false' WHERE userid=".$this->iUserId); return true; } return false; @@ -631,7 +633,8 @@ class User { return true; else return false; - } + } + function isVersionSubmitter($iVersionId) { $sQuery = "SELECT appVersion.versionId FROM appVersion, appFamily @@ -644,6 +647,57 @@ class User { else 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); + } } diff --git a/tables/user_list.sql b/tables/user_list.sql index 1c390a0..cee56e0 100644 --- a/tables/user_list.sql +++ b/tables/user_list.sql @@ -3,13 +3,15 @@ use apidb; drop table if exists user_list; create table user_list ( - stamp timestamp not null, - userid int not null auto_increment, - password text not null, - realname text not null, - email varchar(255) not null, - created datetime not null, - CVSrelease text, + stamp timestamp not null, + userid int not null auto_increment, + password text not null, + realname text not null, + email varchar(255) 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, unique key(userid), unique(email) );