oMaintainer = $oMaintainer; $this->aVersionIds = array(); $this->aScreenshotIds = array(); $this->aTestDataIds = array(); } // returns true if none of the arrays have any entries in them function isEmpty() { if((count($this->aVersionIds) == 0) && (count($this->aScreenshotIds) == 0) && (count($this->aTestDataIds) == 0)) { return true; } return false; } function retrieveQueuedEntries() { $bDebugOutputEnabled = false; if($bDebugOutputEnabled) echo "retrieveQueuedEntries() starting\n"; //////////////////////////////////// // retrieve a list of versions to check for queued data $aVersionsToCheck = array(); if($this->oMaintainer->bSuperMaintainer) { if($bDebugOutputEnabled) echo "maintainer is super maintainer\n"; $oApp = new Application($this->oMaintainer->iAppId); //TODO: would like to rely on the constructor but we might be a user with 'admin' // privileges and that would mean we would end up retrieved queued versions for // this application or unqueued versions depending on which user we were $aVersions = $oApp->getVersions(); foreach($aVersions as $oVersion) { if($bDebugOutputEnabled) { echo "Processing version: "; print_r($oVersion); } if($oVersion->objectGetState() == 'queued') { $this->aVersions[] = $oVersion->objectGetId(); } else if($oVersion->objectGetState() == 'accepted') // version isn't queued { // add the unqueued version to the list of versions to check for queued data $aVersionsToCheck[] = $oVersion->iVersionId; } } } else // just a normal maintainer { $aVersionsToCheck[] = $this->oMaintainer->iVersionId; if($bDebugOutputEnabled) echo "Normal maintainer of version ".$this->oMaintainer->iVersionId."\n"; } // go through all of the verions to see what queued data they have foreach($aVersionsToCheck as $iVersionId) { if($bDebugOutputEnabled) echo "Processing iVersionId of ".$iVersionId."\n"; ////////////////// // queued testdata // retrieve queued testdata for this version $sQuery = "select * from testResults where versionId = '?' and state = '?'"; $hResult = query_parameters($sQuery, $iVersionId, 'queued'); // go through the test results looking for the oldest queued data while($oTestingRow = query_fetch_object($hResult)) { if($bDebugOutputEnabled) echo "\tQueued TestData found\n"; $oTestData = new TestData(null, $oTestingRow); $this->aTestDataIds[] = $oTestData->objectGetId(); } // queued testdata ////////////////// //////////////////// // queued screenshots $sQuery = "select * from appData where type = 'screenshot' and versionId = '?' and state = '?'"; $hResult = query_parameters($sQuery, $iVersionId, 'queued'); while($oScreenshotRow = query_fetch_object($hResult)) { $oScreenshot = new Screenshot(null, $oScreenshotRow); $this->aScreenshotIds[] = $oScreenshot->objectGetId(); } // queued screenshots ////////////////////// } } } // contains the results of a notification update so other logic // can act on these results class notificationUpdate { var $sEmail; var $sSubject; var $sMsg; // contents of the email we will send to the maintainer var $iTargetLevel; // the target notification level based upon the // maintiners queued entries function notificationUpdate($sEmail, $sSubject, $sMsg, $iTargetLevel) { $this->sEmail = $sEmail; $this->sSubject = $sSubject; $this->sMsg = $sMsg; $this->iTargetLevel = $iTargetLevel; } } class maintainer { var $iMaintainerId; var $iAppId; var $iVersionId; var $iUserId; var $sMaintainReason; var $bSuperMaintainer; var $aSubmitTime; //FIXME: should be 'sSubmitTime' var $sState; var $sReplyText; // parameters used in the queued data notification system // that lets maintainers know that their applications/versions have // queued data for them to process var $iNotificationLevel; // the current warning level of this maintainer var $sNotificationTime; // the time when we last warned this maintainer function maintainer($iMaintainerId = null, $oRow = null) { // set a default notification level of 0 $this->iNotificationLevel = 0; if(!$iMaintainerId && !$oRow) return; if(!$oRow) { $sQuery = "SELECT * FROM appMaintainers WHERE maintainerId = '?'"; $hResult = query_parameters($sQuery, $iMaintainerId); if($hResult) $oRow = query_fetch_object($hResult); } if($oRow) { $this->iMaintainerId = $oRow->maintainerId; $this->iAppId = $oRow->appId; $this->iVersionId = $oRow->versionId; $this->iUserId = $oRow->userId; $this->sMaintainReason = $oRow->maintainReason; $this->bSuperMaintainer = $oRow->superMaintainer; $this->aSubmitTime = $oRow->submitTime; $this->sState = $oRow->state; $this->iNotificationLevel = $oRow->notificationLevel; $this->sNotificationTime = $oRow->notificationTime; } } function create() { /* user id, appid, and maintain reason must be valid to continue */ if(!$this->iAppId || !$this->sMaintainReason) { return NULL; } if(!$this->iUserId) $this->iUserId = $_SESSION['current']->iUserId; $oApp = new application($this->iAppId); if(!$this->bSuperMaintainer) $oVersion = new version($this->iVersionId); if($oApp->objectGetState() != 'accepted' || (!$this->bSuperMaintainer && $oVersion->objectGetState() != 'accepted')) $this->sState = "pending"; else $this->sState = $this->mustBeQueued() ? 'queued' : 'accepted'; $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". "userId, maintainReason, superMaintainer, submitTime, state) ". "VALUES ('?', '?', '?', '?', '?', ?, '?')", $this->iAppId, $this->iVersionId, $this->iUserId, $this->sMaintainReason, $this->bSuperMaintainer, "NOW()", $this->sState); /* this objects id is the insert id returned by the database */ $this->iMaintainerId = query_appdb_insert_id(); if(!$this->mustBeQueued()) $this->updateMaintainerState(); /* If this is a non-queued maintainer submission, remove the user's non- super maintainer entries for the application's versions. This check is also done in unQueue() */ if(!$this->mustBeQueued() && $this->bSuperMaintainer) $this->removeUserFromAppVersions(); return $hResult; } function unQueue() { /* if the user isn't already a supermaintainer of the application and */ /* if they are trying to become a maintainer and aren't already a maintainer of */ /* the version, then continue processing the request */ $oUser = new User($this->iUserId); if(!$oUser->isSuperMaintainer($this->iAppId) && ((!$this->bSuperMaintainer && !$oUser->isMaintainer($this->iVersionId)) || $this->bSuperMaintainer)) { /* unqueue the maintainer entry */ $hResult = query_parameters("UPDATE appMaintainers SET state='accepted' WHERE userId = '?' AND maintainerId = '?'", $this->iUserId, $this->iMaintainerId); if($hResult) { $sStatusMessage = "
The maintainer was successfully added into the database
\n"; $this->updateMaintainerState(); //Send Status Email $sEmail = $oUser->sEmail; if ($sEmail) { if($this->iVersionId) { $oVersion = new Version($this->iVersionId); $sURL = $oVersion->objectMakeUrl(); $sName = version::fullName($this->iVersionId); } else { $oApp = new Application($this->iAppId); $sURL = $oApp->objectMakeUrl(); $sName = $oApp->sName; } $sSubject = "Application Maintainer Request Report"; $sMsg = "Your application to be the maintainer of $sName has been accepted.\n"; $sMsg .= "$sURL\n"; $sMsg .= "$this->sReplyText\n"; $sMsg .= "We appreciate your help in making the Application Database better for all users.\n\n"; mail_appdb($sEmail, $sSubject ,$sMsg); } $this->sState = 'accepted'; } } else { /* Delete entry, but only if queued */ query_parameters("DELETE from appMaintainers WHERE userId = '?' AND maintainerId = '?' AND state = 'queued'", $this->iUserId, $this->iMaintainerId); if($oUser->isSuperMaintainer($this->iAppId) && !$this->bSuperMaintainer) $sStatusMessage = "User is already a super maintainer of this application
\n"; else $sStatusMessage = "User is already a maintainer/super maintainer of this application/version
\n"; } /* Delete any maintainer entries the user had for the application's versions, if this is a super maintainer request */ if($this->bSuperMaintainer) $this->removeUserFromAppVersions(); return $sStatusMessage; } function reject() { $oUser = new User($this->iUserId); $sEmail = $oUser->sEmail; if ($sEmail) { $oApp = new Application($oRow->appId); $oVersion = new Version($oRow->versionId); $sSubject = "Application Maintainer Request Report"; $sMsg = "Your application to be the maintainer of ".$oApp->sName." ".$oVersion->sName." was rejected. "; $sMsg .= $this->sReplyText; $sMsg .= ""; $sMsg .= "-The AppDB admins\n"; mail_appdb($sEmail, $sSubject ,$sMsg); } //delete main item $sQuery = "DELETE from appMaintainers where maintainerId = '?'"; $hResult = query_parameters($sQuery, $this->iMaintainerId); return $hResult; } function mustBeQueued() { /* In place for future fine-grained permisson system, only allow admins for now */ if($_SESSION['current']->hasPriv("admin")) return FALSE; else return TRUE; } function purge() { return $this->delete(); } function delete() { $sQuery = "DELETE from appMaintainers where maintainerId = '?'"; $hResult = query_parameters($sQuery, $this->iMaintainerId); if(!$hResult) return FALSE; $this->updateMaintainerState(); return TRUE; } public function findAppMaintainer($iUserId, $iAppId) { $hResult = query_parameters("SELECT * FROM appMaintainers WHERE userId = '?' AND appId = '?' AND superMaintainer = '1'", $iUserId, $iAppId); if(!$hResult) return null; $oRow = mysql_fetch_object($hResult); return new maintainer(null, $oRow); } public function findVersionMaintainer($iUserId, $iVersionId) { $hResult = query_parameters("SELECT * FROM appMaintainers WHERE userId = '?' AND versionId = '?'", $iUserId, $iVersionId); if(!$hResult) return null; $oRow = mysql_fetch_object($hResult); return new maintainer(null, $oRow); } function deleteMaintainer($oUser, $iAppId = null, $iVersionId = null) { /* remove supermaintainer */ if($iAppId && ($iVersionId == null)) { $superMaintainer = 1; $hResult = query_parameters("DELETE FROM appMaintainers WHERE userId = '?' AND appId = '?' AND superMaintainer = '?'", $oUser->iUserId, $iAppId, $superMaintainer); } else if($iAppId && $iVersionId) /* remove a normal maintainer */ { $superMaintainer = 0; $hResult = query_parameters("DELETE FROM appMaintainers WHERE userId = '?' AND appId = '?' AND versionId = '?' AND superMaintainer = '?'", $oUser->iUserId, $iAppId, $iVersionId, $superMaintainer); } else if(($iAppId == null) && ($iVersionId == null)) /* remove all maintainership by this user */ { $hResult = query_parameters("DELETE FROM appMaintainers WHERE userId = '?'", $oUser->iUserId); } if($hResult) return true; return false; } function deleteMaintainersForVersion($oVersion) { if(!$oVersion->iVersionId) return FALSE; $hResult = query_parameters("DELETE from appMaintainers WHERE versionId='?'", $oVersion->iVersionId); return $hResult; } function deleteMaintainersForApplication($oApp) { $sQuery = "DELETE from appMaintainers WHERE appId='?'"; $hResult = query_parameters($sQuery, $oApp->iAppId); return $hResult; } public function updateMaintainerState() { if($this->bSuperMaintainer) { $this->updateAppMaintainerState($this->iAppId); $oApp = new application($this->iAppId); $aVersions = $oApp->objectGetChildrenClassSpecific('version'); foreach($aVersions as $oVersion) $this->updateVersionMaintainerState($oVersion->objectGetId()); } else { $this->updateVersionMaintainerState($this->iVersionId); } } public function updateAppMaintainerState($iAppId) { $oApp = new application($iAppId); $oApp->updateMaintainerState(); } public function updateVersionMaintainerState($iVersionId) { $oVersion = new version($iVersionId); $oVersion->updateMaintainerState(); } function getSubmitterEmails() { $sRecipients = ''; $sQuery = "SELECT DISTINCT(user_list.email) FROM appMaintainers, user_list WHERE appMaintainers.userId = user_list.userId AND appMaintainers.state = 'accepted'"; $hResult = query_parameters($sQuery); if(!$hResult) return FALSE; for($i = 0; $oRow = query_fetch_object($hResult); $i++) { if($i) $sRecipients .= ' '; $sRecipients .= $oRow->email; } return $sRecipients; } function ObjectGetEntries($sState, $iRows = 0, $iStart = 0, $sOrderBy = '', $bAscending = true) { /* Not implemented */ if($sState == 'rejected') return FALSE; $sLimit = ""; /* Should we add a limit clause to the query? */ if($iRows || $iStart) { $sLimit = " LIMIT ?,?"; /* Selecting 0 rows makes no sense, so we assume the user wants to select all of them after an offset given by iStart */ if(!$iRows) $iRows = maintainer::objectGetEntriesCount($sState); } /* Excluding requests for queued apps and versions, as these will be handled automatically */ $sQuery = "SELECT * FROM appMaintainers WHERE appMaintainers.state = '?'$sLimit"; if($sState != 'accepted') { if($_SESSION['current']->hasPriv("admin")) { if($sLimit) { return query_parameters($sQuery, $sState, $iStart, $iRows); } else { return query_parameters($sQuery, $sState); } } else { return NULL; } } else { if($sLimit) { return query_parameters($sQuery, $sState, $iStart, $iRows); } else { return query_parameters($sQuery, $sState); } } } /* retrieve a maintainer object from a row returned by */ /* ObjectGetEntries() */ function ObjectGetObjectFromObjectGetEntriesRow($oRow) { return new maintainer($oRow->maintainerId); } // returns the number of applications/versions a particular user maintains function getMaintainerCountForUserId($iUserId, $bSuperMaintainer) { $sQuery = "SELECT count(*) as cnt from appMaintainers WHERE userid = '?' AND superMaintainer = '?'". " AND state ='?'"; $hResult = query_parameters($sQuery, $iUserId, $bSuperMaintainer ? "1" : "0", 'accepted'); if(!$hResult) return 0; $oRow = query_fetch_object($hResult); return $oRow->cnt; } // returns the number of applications/versions a particular user maintains function getMaintainerCountForUser($oUser, $bSuperMaintainer) { return self::getMaintainerCountForUserId($oUser->iUserId, $bSuperMaintainer); } /** * get the applications and versions that this user maintains */ function getAppsMaintained($oUser) { /* retrieve the list of application and order them by application name */ $hResult = query_parameters("SELECT appMaintainers.appId, versionId, superMaintainer, appName FROM ". "appFamily, appMaintainers WHERE appFamily.appId = appMaintainers.appId ". "AND userId = '?' AND appMaintainers.state = '?' ORDER BY appName", $oUser->iUserId, 'accepted'); if(!$hResult || query_num_rows($hResult) == 0) return NULL; $aAppsMaintained = array(); $c = 0; while($oRow = query_fetch_object($hResult)) { $aAppsMaintained[$c] = array($oRow->appId, $oRow->versionId, $oRow->superMaintainer); $c++; } return $aAppsMaintained; } function objectGetEntriesCount($sState) { /* Not implemented */ if($sState == 'rejected') return FALSE; /* Excluding requests for queued apps and versions, as these are handled automatically. One SELECT for super maintainers, one for maintainers. */ $sQuery = "SELECT COUNT(maintainerId) as count FROM appMaintainers WHERE appMaintainers.state = '?'"; if(!($hResult = query_parameters($sQuery, $sState))) return FALSE; if($oRow = query_fetch_object($hResult)) $iCount = $oRow->count; else $iCount = 0; return $iCount; } /* see how many unique maintainers we actually have */ function getNumberOfMaintainers() { $hResult = query_parameters("SELECT DISTINCT userId FROM appMaintainers WHERE state='accepted';"); return query_num_rows($hResult); } function isUserMaintainer($oUser, $iVersionId = null) { /* if we are a super maintainer, we are a maintainer of this version as well */ $oVersion = new Version($iVersionId); if($oUser->isSuperMaintainer($oVersion->iAppId)) return true; /* otherwise check if we maintain this specific version */ if($iVersionId) { $sQuery = "SELECT * FROM appMaintainers WHERE userId = '?' AND versionId = '?' AND state = '?'"; $hResult = query_parameters($sQuery, $oUser->iUserId, $iVersionId, 'accepted'); } else // are we maintaining any version ? { $sQuery = "SELECT * FROM appMaintainers WHERE userId = '?' AND state = '?'"; $hResult = query_parameters($sQuery, $oUser->iUserId, 'accepted'); } if(!$hResult) return false; return query_num_rows($hResult); } function isUserSuperMaintainer($oUser, $iAppId = null) { if($iAppId) { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND appId = '?' AND superMaintainer = '1' AND state = '?'"; $hResult = query_parameters($sQuery, $oUser->iUserId, $iAppId, 'accepted'); } else /* are we super maintainer of any applications? */ { $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND superMaintainer = '1' AND state = '?'"; $hResult = query_parameters($sQuery, $oUser->iUserId, 'accepted'); } if(!$hResult) return false; return query_num_rows($hResult); } /* Returns true if the given app has a maintainer, false otherwise */ public function appHasMaintainer($iAppId) { $hResult = query_parameters("SELECT COUNT(maintainerId) as count FROM appMaintainers WHERE appId = '?' AND superMaintainer = '1' AND state = 'accepted'", $iAppId); if(!$hResult) return false; $oRow = mysql_fetch_object($hResult); return $oRow->count > 0; } /* Returns true if the given version has a maintainer, false otherwise */ public function versionHasMaintainer($iVersionId) { $oVersion = new version($iVersionId); $hResult = query_parameters("SELECT COUNT(maintainerId) as count FROM appMaintainers WHERE (appId = '?' AND superMaintainer = '1') OR (versionId = '?') AND state = 'accepted'", $oVersion->iAppId, $iVersionId); if(!$hResult) return false; $oRow = mysql_fetch_object($hResult); return $oRow->count > 0; } /* if given an appid or a version id return a handle for a query that has */ /* the user ids that are maintainers for this particular appid or version id */ function getMaintainersForAppIdVersionId($iAppId = null, $iVersionId = null) { $hResult = null; if($iVersionId) { $hResult = query_parameters("SELECT userId from appMaintainers, appVersion WHERE appMaintainers.state = 'accepted' AND appVersion.versionId = '?' AND ( appMaintainers.versionId = appVersion.versionId OR ( appMaintainers.appId = appVersion.appId AND superMaintainer = '1' ) )", $iVersionId); } /* * If versionId was not supplied we fetch supermaintainers of application and maintainer of all versions. */ elseif($iAppId) { $hResult = query_parameters("SELECT userId FROM appMaintainers WHERE appId = '?' AND state = 'accepted'", $iAppId); } return $hResult; } /* * get the userIds of super maintainers for this appId */ function getSuperMaintainersUserIdsFromAppId($iAppId) { $sQuery = "SELECT userId FROM ". "appMaintainers WHERE appId = '?' " . "AND superMaintainer = '1' AND state='?';"; $hResult = query_parameters($sQuery, $iAppId, 'accepted'); $aUserIds = array(); $c = 0; while($oRow = query_fetch_object($hResult)) { $aUserIds[$c] = $oRow->userId; $c++; } return $aUserIds; } function ObjectGetHeader() { $oTableRow = new TableRow(); $oTableRow->AddTextCell("Submission Date"); $oTableRow->AddTextCell("Application Name"); $oTableRow->AddTextCell("Version"); $oTableRow->AddTextCell("Super maintainer?"); $oTableRow->AddTextCell("Submitter"); return $oTableRow; } function ObjectGetTableRow() { $oUser = new User($this->iUserId); $oApp = new Application($this->iAppId); $oVersion = new Version($this->iVersionId); $oTableRow = new TableRow(); $oTableRow->AddTextCell(print_date(mysqldatetime_to_unixtimestamp($this->aSubmitTime))); $oTableRow->AddTextCell($oApp->objectMakeLink()); $oTableRow->AddTextCell(($this->bSuperMaintainer) ? "N/A" : $oVersion->objectMakeLink()); $oTableRow->AddTextCell(($this->bSuperMaintainer) ? "Yes" : "No"); $oTableRow->AddTextCell($oUser->objectMakeLink()); $oOMTableRow = new OMTableRow($oTableRow); return $oOMTableRow; } function objectDisplayAddItemHelp($aClean) { echo "This page is for submitting a request to become an application maintainer.\n"; echo "An application maintainer is someone who runs the application \n"; echo "regularly and who is willing to be active in reporting regressions with newer \n"; echo "versions of DXGL and to help other users run this application under DXGL.
"; echo "Being an application maintainer comes with new rights and new responsibilities; please be sure to read the maintainer's guidelines before to proceed.
"; echo "We ask that all maintainers explain why they want to be an application maintainer,\n"; echo "why they think they will do a good job and a little about their experience\n"; echo "with DXGL. This is both to give you time to\n"; echo "think about whether you really want to be an application maintainer and also for the\n"; echo "appdb admins to identify people that are best suited for the job. Your request\n"; echo "may be denied if there are already a handful of maintainers for this application or if you\n"; echo "don't have the experience with DXGL that is necessary to help other users out.
\n"; if(!$aClean['iVersionId']) { echo "Super maintainers are just like normal maintainers but they can modify EVERY version of\n"; echo "this application (and the application itself). We don't expect you to run every version but at least to help keep\n"; echo "the forums clean of stale and out-of-date information.
\n"; } } function ObjectDisplayQueueProcessingHelp() { echo "\n\n"; echo "Please enter an accurate and personalized reply anytime a maintainer request is rejected.\n"; echo "Its not polite to reject someones attempt at trying to help out without explaining why.\n"; echo " |
"; echo 'Application | '.$oApp->sName; echo ' |
"; echo 'Version | '.$oVersion->sName; echo ' |
Why you want to and should be an application super maintainer | |
Why you want to and should be an application maintainer |
Other maintainers'; /* Fetch maintainers and super maintainers */ $oVersion = new Version($this->iVersionId); $aOtherMaintainers = $oVersion->getMaintainersUserIds(); $aOtherSuperMaintainers = Maintainer::getSuperMaintainersUserIdsFromAppId($this->iAppId); if($aOtherMaintainers || $aOtherSuperMaintainers) $bFoundMaintainers = true; else $bFoundMaintainers = false; echo " | \n";
/* display maintainers for the version */
if($aOtherMaintainers)
{
while(list($index, $iUserId) = each($aOtherMaintainers))
{
$oUser = new User($iUserId);
// because Version::getMaintainersUserIds() includes super maintainers
// we need to exclude these from the list of maintainers that we are
// building
if(!maintainer::isUserSuperMaintainer($oUser, $oVersion->iAppId))
echo "$oUser->sRealname \n"; } } /* display super maintainers for the given app */ if($aOtherSuperMaintainers) { while(list($index, $iUserId) = each($aOtherSuperMaintainers)) { $oUser = new User($iUserId); echo "$oUser->sRealname* \n"; } } if(!$bFoundMaintainers) { echo "No other maintainers"; } echo " |
This user also maintains these apps:';
echo " iUserId}&sTitle=Maintained+Apps\">Detailed view"; echo ' | ',"\n";
$oUser = new User($this->iUserId);
$aOtherApps = Maintainer::getAppsMaintained($oUser);
if($aOtherApps)
{
while(list($index, list($iAppIdOther, $iVersionIdOther, $bSuperMaintainerOther)) = each($aOtherApps))
{
$oApp = new Application($iAppIdOther);
if($bSuperMaintainerOther)
echo $oApp->objectMakeLink()."* \n"; else echo $oVersion->fullNameLink($iVersionIdOther)." \n"; } } else { echo "User maintains no other applications"; } echo " |
App Name: | ',"\n"; echo "".$oApp->objectMakeLink()." |
App Version: | ',"\n"; echo "".$oVersion->objectMakeLink()." |
Maintainer request reason: | ',"\n"; echo '