Move deletion of maintainer logic into the user class. If the cleanup script wants to delete a user and can't, if they are a maintainer we should remove their maintainer status even if we don't delete their account. Send email at the start of the cleanup script to aid in debug

This commit is contained in:
Chris Morgan
2005-09-30 01:37:57 +00:00
committed by WineHQ
parent b067e62789
commit a66ae25f38
3 changed files with 56 additions and 12 deletions

View File

@@ -17,7 +17,9 @@ include(BASE."include/mail.php");
$usersWarned = 0;
$usersDeleted = 0;
$usersToBeDeletedButHaveData = 0;
$usersWithData = 0; /* users marked for deletion that have data */
notifyAdminsOfCleanupStart();
/* users inactive for 6 months that haven't been warned already */
$hUsersToWarn = unwarnedAndInactiveSince(6);
@@ -39,11 +41,17 @@ while($oRow = mysql_fetch_object($hUsersToDelete))
deleteUser($oRow->userid);
} else
{
$usersToBeDeletedButHaveData++;
/* is the user a maintainer? if so remove their maintainer privilages */
if($oUser->isMaintainer())
{
$oUser->deleteMaintainer();
}
$usersWithData++;
}
}
notifyAdminsOfCleanupExecution($usersWarned, $usersDeleted, $usersToBeDeletedButHaveData);
notifyAdminsOfCleanupExecution($usersWarned, $usersDeleted, $usersWithData);
/* Users that are unwarned and inactive since $iMonths */
@@ -81,16 +89,25 @@ function warnUserDeleted($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);
}
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);
}
/* 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($usersWarned, $usersDeleted, $usersToBeDeletedButHaveData)
function notifyAdminsOfCleanupExecution($usersWarned, $usersDeleted, $usersWithData)
{
$sSubject = "Cleanup script running\r\n";
$sSubject = "Cleanup script summary\r\n";
$sMsg = "Appdb cleanup cron script executed.\r\n";
$sMsg .= "Status:\r\n";
$sMsg .= "Users warned:".$usersWarned." Users deleted:".$usersDeleted."\r\n";
$sMsg .= "Users pending deletion but have appdb data:".$usersToBeDeletedButHaveData."\r\n";
$sMsg .= "Users pending deletion but have appdb data:".$usersWithData."\r\n";
$sEmail = get_notify_email_address_list(null, null); /* get list admins */
if($sEmail)
mail_appdb($sEmail, $sSubject, $sMsg);

View File

@@ -315,6 +315,35 @@ class User {
return $statusMessage;
}
/* remove maintainership */
/* if $iAppId and $iVersionId are null, delete all maintainership for this user */
function deleteMaintainer($iAppId = null, $iVersionId = null)
{
/* remove supermaintainer */
if($iAppId && ($iVersionId == null))
{
$superMaintainer = 1;
$sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId.
" AND appId = ".$iAppId." AND superMaintainer = ".$superMaintainer.";";
} else if($iAppId && $iVersionId) /* remove a normal maintainer */
{
$superMaintainer = 0;
$sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId.
" AND appId = ".$iAppId." AND versionId = ".$iVersionId." AND superMaintainer = ".$superMaintainer.";";
} else if(($iAppId == null) && ($iVersionId == null)) /* remove all maintainership by this user */
{
$sQuery = "DELETE FROM appMaintainers WHERE userId = ".$this->iUserId.";";
}
if($sQuery)
{
if($result = query_appdb($sQuery))
return true;
}
return false;
}
/* get the number of queued applications */
function getQueuedAppCount()
{

View File

@@ -24,22 +24,20 @@ $superMaintainer = strip_tags($_POST['superMaintainer']);
if($confirmed)
{
$oApp = new Application($appId);
$oApp = new Application($appId);
if($superMaintainer)
{
apidb_header("You have resigned as supermaintainer of ".$oApp->sName);
$query = "DELETE FROM appMaintainers WHERE userId = ".$_SESSION['current']->iUserId.
" AND appId = ".$oApp->iAppId." AND superMaintainer = ".$superMaintainer.";";
$result = $_SESSION['current']->deleteMaintainer($oApp->iAppId, null);
} else
{
$oVersion = new Version($versionId);
apidb_header("You have resigned as maintainer of ".$oApp->sName." ".$oVersion->sName);
$query = "DELETE FROM appMaintainers WHERE userId = ".$_SESSION['current']->iUserId.
" AND appId = ".$oApp->iAppId." AND versionId = ".$oVersion->iVersionId." AND superMaintainer = ".$superMaintainer.";";
$result = $_SESSION['current']->deleteMaintainer($oApp->iAppId, $oVersion->iVersionId);
}
/* echo html_frame_start("Removing",400,"",0);
*/
if($result = query_appdb($query))
if($result)
{
if($superMaintainer)
echo "You were removed as a supermaintainer of ".$oApp->sName;