diff --git a/admin/adminMaintainerQueue.php b/admin/adminMaintainerQueue.php index 1ff1006..3b196b4 100644 --- a/admin/adminMaintainerQueue.php +++ b/admin/adminMaintainerQueue.php @@ -14,7 +14,7 @@ require_once(BASE."include/mail.php"); $aClean = array(); //array of filtered user input $aClean['sSub'] = makeSafe( $_REQUEST['sSub'] ); -$aClean['iQueueId'] = makeSafe( $_REQUEST['iQueueId'] ); +$aClean['iMaintainerId'] = makeSafe( $_REQUEST['iMaintainerId'] ); $aClean['sAdd'] = makeSafe( $_REQUEST['sAdd'] ); $aClean['sReject'] = makeSafe( $_REQUEST['sReject'] ); $aClean['sReplyText'] = makeSafe( $_REQUEST['sReplyText'] ); @@ -25,14 +25,14 @@ if(!$_SESSION['current']->hasPriv("admin")) if ($aClean['sSub']) { - if ($aClean['iQueueId']) + if ($aClean['iMaintainerId']) { //get data - $sQuery = "SELECT queueId, appId, versionId,". + $sQuery = "SELECT maintainerId, appId, versionId,". "userId, maintainReason, superMaintainer,". "UNIX_TIMESTAMP(submitTime) as submitTime ". - "FROM appMaintainerQueue WHERE queueId = '?'"; - $hResult = query_parameters($sQuery, $aClean['iQueueId']); + "FROM appMaintainers WHERE maintainerId = '?' AND queued = 'true'"; + $hResult = query_parameters($sQuery, $aClean['iMaintainerId']); $oRow = mysql_fetch_object($hResult); $oUser = new User($oRow->userId); mysql_free_result($hResult); @@ -44,7 +44,7 @@ if ($aClean['sSub']) } //process according to which request was submitted and optionally the sub flag - if (!$aClean['sAdd'] && !$aClean['sReject'] && $aClean['iQueueId']) + if (!$aClean['sAdd'] && !$aClean['sReject'] && $aClean['iMaintainerId']) { apidb_header("Admin Maintainer Queue"); echo '
',"\n"; @@ -171,7 +171,7 @@ if ($aClean['sSub']) echo '',"\n"; echo '',"\n"; - echo '',"\n"; + echo '',"\n"; echo html_frame_end(" "); echo html_back_link(1,'adminMaintainerQueue.php'); @@ -180,7 +180,7 @@ if ($aClean['sSub']) exit; } - else if ($aClean['sAdd'] && $aClean['iQueueId']) + else if ($aClean['sAdd'] && $aClean['iMaintainerId']) { /* create a new user object for the maintainer */ $oMaintainerUser = new User($oRow->userId); @@ -188,11 +188,11 @@ if ($aClean['sSub']) /* add the user as a maintainer and return the statusMessage */ $sStatusMessage = $oMaintainerUser->addAsMaintainer($oRow->appId, $oRow->versionId, $oRow->superMaintainer, - $aClean['iQueueId']); + $aClean['iMaintainerId']); //done addmsg("

$sStatusMessage

", 'green'); } - else if (($aClean['sReject'] || ($aClean['sSub'] == 'sReject')) && $aClean['iQueueId']) + else if (($aClean['sReject'] || ($aClean['sSub'] == 'sReject')) && $aClean['iMaintainerId']) { $sEmail = $oUser->sEmail; if ($sEmail) @@ -209,8 +209,8 @@ if ($aClean['sSub']) } //delete main item - $sQuery = "DELETE from appMaintainerQueue where queueId = '?'"; - $hResult = query_parameters($sQuery, $aClean['iQueueId']); + $sQuery = "DELETE from appMaintainers where maintainerId = '?'"; + $hResult = query_parameters($sQuery, $aClean['iMaintainerId']); if(!$hResult) addmsg("unable to delete selected maintainer application", "red"); echo html_frame_start("Delete maintainer application",400,"",0); if($hResult) @@ -233,11 +233,11 @@ if ($aClean['sSub']) echo '',"\n"; //get available maintainers - $sQuery = "SELECT queueId, appId, versionId,". + $sQuery = "SELECT maintainerId, appId, versionId,". "userId, maintainReason,". "superMaintainer,". "submitTime as submitTime ". - "from appMaintainerQueue;"; + "FROM appMaintainers WHERE queued='true';"; $hResult = query_parameters($sQuery); if(!$hResult || !mysql_num_rows($hResult)) @@ -291,7 +291,7 @@ if ($aClean['sSub']) } echo " sEmail."\">".$oUser->sRealname."\n"; - echo " [queueId\">answer]\n"; + echo " [maintainerId\">answer]\n"; echo "\n\n"; $iRowCount++; } diff --git a/admin/adminMaintainers.php b/admin/adminMaintainers.php index 3a3fe22..ddb4dc4 100644 --- a/admin/adminMaintainers.php +++ b/admin/adminMaintainers.php @@ -40,7 +40,7 @@ if ($aClean['sSub']) { // get available maintainers $sQuery = "SELECT * FROM appMaintainers, user_list where appMaintainers.userId = user_list.userid"; - $sQuery.= " ORDER BY realname;"; + $sQuery.= " AND queued='false' ORDER BY realname;"; $hResult = query_parameters($sQuery); if(!$hResult || !mysql_num_rows($hResult)) diff --git a/include/maintainer.php b/include/maintainer.php index 7e6e97b..efca3b5 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -6,12 +6,12 @@ /* * get the userIds of super maintainers for this appId */ -function getSuperMaintainersUserIdsFromAppId($appId) +function getSuperMaintainersUserIdsFromAppId($iAppId) { $sQuery = "SELECT userId FROM ". "appMaintainers WHERE appId = '?' " . - "AND superMaintainer = '1';"; - $hResult = query_parameters($sQuery, $appId); + "AND superMaintainer = '1' AND queued='?';"; + $hResult = query_parameters($sQuery, $iAppId, "false"); $retval = array(); $c = 0; while($oRow = mysql_fetch_object($hResult)) diff --git a/include/user.php b/include/user.php index ba11337..6d8e41f 100644 --- a/include/user.php +++ b/include/user.php @@ -261,12 +261,12 @@ class User { /* otherwise check if we maintain this specific version */ if($iVersionId) { - $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND versionId = '?'"; - $hResult = query_parameters($sQuery, $this->iUserId, $iVersionId); + $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND versionId = '?' AND queued = '?'"; + $hResult = query_parameters($sQuery, $this->iUserId, $iVersionId, "false"); } else // are we maintaining any version ? { - $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?'"; - $hResult = query_parameters($sQuery, $this->iUserId); + $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND queued = '?'"; + $hResult = query_parameters($sQuery, $this->iUserId, "false"); } if(!$hResult) return false; @@ -284,12 +284,12 @@ class User { if($iAppId) { - $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND appId = '?' AND superMaintainer = '1'"; - $hResult = query_parameters($sQuery, $this->iUserId, $iAppId); + $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND appId = '?' AND superMaintainer = '1' AND queued = '?'"; + $hResult = query_parameters($sQuery, $this->iUserId, $iAppId, "false"); } else /* are we super maintainer of any applications? */ { - $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND superMaintainer = '1'"; - $hResult = query_parameters($sQuery, $this->iUserId); + $sQuery = "SELECT * FROM appMaintainers WHERE userid = '?' AND superMaintainer = '1' AND queued = '?'"; + $hResult = query_parameters($sQuery, $this->iUserId, "false"); } if(!$hResult) return false; @@ -304,7 +304,8 @@ class User { /* 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 = '?' ORDER BY appName", $this->iUserId); + "AND userId = '?' AND appMaintainers.queued = '?' ORDER BY appName", + $this->iUserId, "false"); if(!$hResult || mysql_num_rows($hResult) == 0) return NULL; @@ -323,8 +324,9 @@ class User { { if(!$this->isLoggedIn()) return 0; - $sQuery = "SELECT count(*) as cnt from appMaintainers WHERE userid = '?' AND superMaintainer = '?'"; - $hResult = query_parameters($sQuery, $this->iUserId, $bSuperMaintainer); + $sQuery = "SELECT count(*) as cnt from appMaintainers WHERE userid = '?' AND superMaintainer = '?'". + " AND queued ='?'"; + $hResult = query_parameters($sQuery, $this->iUserId, $bSuperMaintainer ? "1" : "0", "false"); if(!$hResult) return 0; $oRow = mysql_fetch_object($hResult); @@ -335,8 +337,10 @@ class User { /** * Add the user as a maintainer */ - function addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iQueueId) - { + //FIXME: we really don't need any parameter except $iMaintainerId here + // we'll clean this up when we clean up maintainers + function addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iMaintainerId) + { $aClean = array(); $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); @@ -347,18 +351,14 @@ class User { if(!$this->isSuperMaintainer($iAppId) && ((!$bSuperMaintainer && !$this->isMaintainer($iVersionId)) | $bSuperMaintainer)) { - // insert the new entry into the maintainers list - $hResult = query_parameters("INSERT INTO appMaintainers (maintainerId, appId,". - "versionId, userId, superMaintainer, submitTime) ". - "VALUES (?, '?', '?', '?', '?', ?)", - "null", $iAppId, $iVersionId, $this->iUserId, - $bSuperMaintainer, "NOW()"); + /* unqueue the maintainer entry */ + $hResult = query_parameters("UPDATE appMaintainers SET queued='false' WHERE userId = '?' AND maintainerId = '?'", + $this->iUserId, $iMaintainerId); + if($hResult) { $statusMessage = "

The maintainer was successfully added into the database

\n"; - //delete the item from the queue - query_parameters("DELETE from appMaintainerQueue where queueId = '?'", $iQueueId); $oApp = new Application($iAppId); $oVersion = new Version($iVersionId); //Send Status Email @@ -376,7 +376,8 @@ class User { } else { //delete the item from the queue - query_parameters("DELETE from appMaintainerQueue where queueId = '?'", $iQueueId); + query_parameters("DELETE from appMaintainers WHERE userId = '?' AND maintainerId = '?'", + $this->iUserId, $iMaintainerId); if($this->isSuperMaintainer($iAppId) && !$bSuperMaintainer) $statusMessage = "

User is already a super maintainer of this application

\n"; @@ -437,7 +438,7 @@ class User { { /* find all queued versions of applications that the user is a super maintainer of */ $hResult = query_parameters("SELECT count(*) as queued_versions FROM appVersion, appMaintainers - WHERE queued='true' AND appMaintainers.superMaintainer ='1' + WHERE Appversion.queued='true' AND appMaintainers.superMaintainer ='1' AND appVersion.appId = appMaintainers.appId AND appMaintainers.userId ='?'", $this->iUserId); } @@ -606,7 +607,7 @@ class User { if($queryAppFamily) { $sQuery = "SELECT appFamily.appId FROM appFamily, appMaintainers - WHERE queued = 'true' + WHERE appFamily.queued = 'true' AND appFamily.appId = appMaintainers.appId AND appMaintainers.superMaintainer = '1' AND appMaintainers.userId = '".mysql_real_escape_string($this->iUserId)."';"; @@ -848,7 +849,7 @@ class User { $hResult = query_parameters("SELECT appMaintainers.userId FROM appMaintainers, appVersion WHERE appVersion.appId = appMaintainers.appId - AND appVersion.versionId = '?'", + AND appVersion.versionId = '?' AND appMaintainers.queued = 'false'", $iVersionId); } /* @@ -858,7 +859,7 @@ class User { { $hResult = query_parameters("SELECT userId FROM appMaintainers - WHERE appId = '?'", + WHERE appId = '?' AND queued = 'false'", $iAppId); } diff --git a/include/util.php b/include/util.php index d9397f3..2782f56 100644 --- a/include/util.php +++ b/include/util.php @@ -187,7 +187,7 @@ function make_maintainer_rating_list($varname, $cvalue) /* get the number of queued maintainers */ function getQueuedMaintainerCount() { - $sQuery = "SELECT count(*) as queued_maintainers FROM appMaintainerQueue"; + $sQuery = "SELECT count(*) as queued_maintainers FROM appMaintainers where queued='true'"; $hResult = query_parameters($sQuery); $oRow = mysql_fetch_object($hResult); return $oRow->queued_maintainers; @@ -196,7 +196,7 @@ function getQueuedMaintainerCount() /* get the total number of maintainers and applications in the appMaintainers table */ function getMaintainerCount() { - $sQuery = "SELECT count(*) as maintainers FROM appMaintainers"; + $sQuery = "SELECT count(*) as maintainers FROM appMaintainers where queued='false'"; $hResult = query_parameters($sQuery); $oRow = mysql_fetch_object($hResult); return $oRow->maintainers; @@ -230,7 +230,7 @@ function getNumberOfVersions() /* Get the number of maintainers in the database */ function getNumberOfMaintainers() { - $hResult = query_parameters("SELECT DISTINCT userId FROM appMaintainers;"); + $hResult = query_parameters("SELECT DISTINCT userId FROM appMaintainers WHERE queued='false';"); return mysql_num_rows($hResult); } diff --git a/maintainersubmit.php b/maintainersubmit.php index 09f6043..5a5b531 100644 --- a/maintainersubmit.php +++ b/maintainersubmit.php @@ -85,17 +85,20 @@ if( $aClean['sMaintainReason'] ) apidb_header("Submit Maintainer Request"); // add to queue - $hResult = query_parameters("INSERT INTO appMaintainerQueue (queueId, appId, versionId, ". - "userId, maintainReason, superMaintainer, submitTime) ". - "VALUES (?, '?', '?', '?', '?', '?', ?)", - "null", $aClean['iAppId'], $aClean['iVersionId'], + $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". + "userId, maintainReason, superMaintainer, submitTime, queued) ". + "VALUES ('?', '?', '?', '?', '?', ?, '?')", + $aClean['iAppId'], $aClean['iVersionId'], $_SESSION['current']->iUserId, $aClean['sMaintainReason'], - $aClean['iSuperMaintainer'], "NOW()"); + $aClean['iSuperMaintainer'], "NOW()", 'true'); if ($hResult) { echo "

Your maintainer request has been submitted for review. You should hear back\n"; echo "soon about the status of your submission

\n"; + } else + { + addmsg("Error submitting maintainer request. Please contact the appdb admins at appdb@winehq.org", "red"); } } else { diff --git a/tables/maintainers.sql b/tables/maintainers.sql index 5b7abf6..5fb1aa7 100644 --- a/tables/maintainers.sql +++ b/tables/maintainers.sql @@ -7,28 +7,18 @@ drop table if exists appMaintainers; * List of the application maintainers. These users have the rights * to delete comments, edit the application description and otherwise * care for an application. + * + * We also store the reason they asked to be a maintainer since we use this table + * for both queued and unqueued maintainers */ create table appMaintainers ( maintainerId int not null auto_increment, appId int, versionId int, userId int, - superMaintainer bool, - submitTime datetime, - key(maintainerId) -); - -/* - * Queue where users names will go if they request to become an application - * maintainer. This includes the reason they want to become a maintainer. - */ -create table appMaintainerQueue ( - queueId int not null auto_increment, - appId int, - versionId int, - userId int, maintainReason text, superMaintainer bool, - submitTime datetime, - key(queueId) + submitTime datetime, + queued enum('true','false','rejected') NOT NULL default 'false'; + key(maintainerId) ); diff --git a/unit_test/test_user.php b/unit_test/test_user.php index 0d7b576..5f9e51f 100644 --- a/unit_test/test_user.php +++ b/unit_test/test_user.php @@ -297,9 +297,21 @@ function test_user_getMaintainerCount() */ $iAppId = 655000; $iVersionId = 655200; - $iQueueId = 655300; - $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, TRUE, $iQueueId); + //FIXME: when we clean up maintainers we'll want to clean this code up as well + /* queue up the maintainership */ + // add to queue + $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". + "userId, maintainReason, superMaintainer, submitTime, queued) ". + "VALUES ('?', '?', '?', '?', '?', ?, '?')", + $iAppId, $iVersionId, + $_SESSION['current']->iUserId, "Some crazy reason", + TRUE ? "1" : "0", "NOW()", 'true'); + + $iMaintainerId = mysql_insert_id(); + + $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, TRUE, $iMaintainerId); + /* see that the user is a super maintainer of the one application we added them to be */ $iExpected = 1; /* we expect 1 super maintainer for this user */ $iSuperMaintainerCount = $oUser->getMaintainerCount(TRUE); @@ -327,7 +339,19 @@ function test_user_getMaintainerCount() /** * make the user a maintainer */ - $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, FALSE, $iQueueId); + //FIXME: when we clean up maintainers we'll want to clean this code up as well + /* queue up the maintainership */ + // add to queue + $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". + "userId, maintainReason, superMaintainer, submitTime, queued) ". + "VALUES ('?', '?', '?', '?', '?', ?, '?')", + $iAppId, $iVersionId, + $_SESSION['current']->iUserId, "Some crazy reason", + FALSE ? "1" : "0", "NOW()", 'true'); + + $iMaintainerId = mysql_insert_id(); + + $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, FALSE, $iMaintainerId); /* see that the user is a super maintainer of no applications */ $iExpected = 0; /* we expect 1 super maintainer for this user */ @@ -388,9 +412,21 @@ function test_user_getAppsMaintained() */ $iAppId = $oApp->iAppId; /* use the iAppId of the application we just created */ $iVersionId = 655200; - $iQueueId = 655300; $bSuperMaintainer = TRUE; - $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iQueueId); + + //FIXME: when we clean up maintainers we'll want to clean this code up as well + /* queue up the maintainership */ + // add to queue + $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". + "userId, maintainReason, superMaintainer, submitTime, queued) ". + "VALUES ('?', '?', '?', '?', '?', ?, '?')", + $iAppId, $iVersionId, + $_SESSION['current']->iUserId, "Some crazy reason", + $bSuperMaintainer ? "1" : "0", "NOW()", 'true'); + + $iMaintainerId = mysql_insert_id(); + + $statusMessage = $oUser->addAsMaintainer($iAppId, $iVersionId, $bSuperMaintainer, $iMaintainerId); /* get an array of the apps maintained */ $aAppsMaintained = $oUser->getAppsMaintained();