diff --git a/cron/cleanup.php b/cron/cleanup.php index ac4e3c7..a3e1af2 100644 --- a/cron/cleanup.php +++ b/cron/cleanup.php @@ -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); diff --git a/include/user.php b/include/user.php index e336e75..8d79c63 100644 --- a/include/user.php +++ b/include/user.php @@ -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() { diff --git a/maintainerdelete.php b/maintainerdelete.php index 2c819fd..f43ff29 100644 --- a/maintainerdelete.php +++ b/maintainerdelete.php @@ -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;