diff --git a/include/application.php b/include/application.php index 61ad687..44c7b16 100644 --- a/include/application.php +++ b/include/application.php @@ -17,6 +17,8 @@ define("SILVER_RATING", "Silver"); define("BRONZE_RATING", "Bronze"); define("GARBAGE_RATING", "Garbage"); +define("MAINTAINER_REQUEST", 1); +define("SUPERMAINTAINER_REQUEST", 2); /** * Application class for handling applications. @@ -34,8 +36,8 @@ class Application { var $sSubmitTime; var $iSubmitterId; var $aVersionsIds; // an array that contains the versionId of every version linked to this app. - var $bSuperMaintainerRequest; // Temporary variable used in application submission. - // If the user wants to become a super maintainer for the application + var $iMaintainerRequest; /* Temporary variable for tracking maintainer + requests on app submission. Value denotes type of request */ /** * constructor, fetches the data. @@ -133,7 +135,7 @@ class Application { $this->SendNotificationMail(); // Only administrators will be mailed as no supermaintainers exist for this app. /* Submit super maintainer request if asked to */ - if($this->bSuperMaintainerRequest) + if($this->iMaintainerRequest == SUPERMAINTAINER_REQUEST) { $oMaintainer = new Maintainer(); $oMaintainer->iAppId = $this->iAppId; @@ -309,7 +311,7 @@ class Application { /* Unqueue matching super maintainer request */ $hResultMaint = query_parameters("SELECT maintainerId FROM appMaintainers WHERE userId = '?' AND appId = '?'", $this->iSubmitterId, $this->iAppId); - if($hResultMaint) + if($hResultMaint && mysql_num_rows($hResultMaint)) { $oMaintainerRow = mysql_fetch_object($hResultMaint); $oMaintainer = new Maintainer($oMaintainerRow->maintainerId); @@ -541,10 +543,25 @@ class Application { // Allow user to apply as super maintainer if this is a new app if(!$this->iAppId) { - if($this->bSuperMaintainerRequest) - $sRequestSuperMaintainerChecked = 'checked="checked"'; - echo 'Become super maintainer?',"\n"; - echo ' Check this to request being a super maintainer for the application',"\n"; + $sMaintainerOptions = + "". + "I would not like to become a maintainer
\n". + "". + "I would like to be a maintainer of the new version only
\n". + "". + "I would like to be a maintainer of the entire application
\n"; + + $sMaintainerOptionsSelected = str_replace( + "value=\"$this->iMaintainerRequest\"", + "value=\"$this->iMaintainerRequest\" checked=\"checked\"", + $sMaintainerOptions); + + echo html_tr(array( + array("Maintainer options", "class=\"color0\""), + $sMaintainerOptionsSelected), + "", "valign=\"top\""); } echo "\n"; @@ -586,7 +603,7 @@ class Application { $this->iVendorId = $aValues['iAppVendorId']; $this->sWebpage = $aValues['sAppWebpage']; $this->sKeywords = $aValues['sAppKeywords']; - $this->bSuperMaintainerRequest = $aValues['bSuperMaintainerRequest']; + $this->iMaintainerRequest = $aValues['iMaintainerRequest']; } /* display this application */ diff --git a/include/maintainer.php b/include/maintainer.php index 74a1c88..4d70c63 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -191,19 +191,31 @@ class maintainer function ObjectGetEntries($bQueued) { - /* Excluding requests for queued apps, as these will be handled automatically */ + /* Excluding requests for queued apps and versions, as these will be + handled automatically */ if($bQueued) - $sQuery = "SELECT maintainerId FROM appMaintainers, user_list, appFamily WHERE appMaintainers.userid = user_list.userid ". - "AND appMaintainers.queued = '?' AND appMaintainers.appId = ". - "appFamily.appId AND appFamily.queued = 'false' ORDER by ". "appMaintainers.submitTime"; + $sQuery = "SELECT appMaintainers.submitTime, maintainerId FROM + appMaintainers, user_list, appFamily + WHERE appMaintainers.userid = user_list.userid AND + appMaintainers.queued = '?' AND appMaintainers.appId = + appFamily.appId AND appMaintainers.versionId = '' AND + appFamily.queued = 'false' UNION SELECT + appMaintainers.submitTime, maintainerId FROM + appMaintainers, user_list, appVersion WHERE + user_list.userid = appMaintainers.userid AND + appMaintainers.versionId = appVersion.versionId AND + appVersion.queued = 'false' AND appMaintainers.queued = '?' + ORDER by submitTime"; else - $sQuery = "SELECT maintainerId FROM appMaintainers, user_list WHERE appMaintainers.userid = user_list.userid ". + $sQuery = "SELECT maintainerId FROM appMaintainers, user_list + WHERE appMaintainers.userid = user_list.userid ". "AND queued = '?' ORDER by realname"; if($bQueued) { if($_SESSION['current']->hasPriv("admin")) - return query_parameters($sQuery, $bQueued ? "true" : "false"); + return query_parameters($sQuery, $bQueued ? "true" : "false", + $bQueued ? "true" : "false"); else return NULL; } else @@ -256,10 +268,21 @@ class maintainer function getQueuedMaintainerCount() { - /* Excluding requests for queued apps, as these are handled automatically */ - $sQuery = "SELECT COUNT(*) as queued_maintainers FROM appMaintainers, appFamily WHERE appMaintainers.queued='true' AND appFamily.appId = appMaintainers.appId AND appFamily.queued = 'false'"; - $hResult = query_parameters($sQuery); + /* Excluding requests for queued apps and versions, as these are handled + automatically. One SELECT for super maintainers, one for maintainers. */ + $sQuery = "SELECT COUNT(DISTINCT maintainerId) as queued_maintainers FROM + appMaintainers, appFamily, appVersion + WHERE appMaintainers.queued='true' AND ((appFamily.appId = + appMaintainers.appId AND appFamily.queued = 'false' AND + appMaintainers.versionId = '') OR ( + appVersion.versionId = appMaintainers.versionId + AND appVersion.queued = 'false'))"; + + if(!($hResult = query_parameters($sQuery))) + return FALSE; + $oRow = mysql_fetch_object($hResult); + return $oRow->queued_maintainers; } diff --git a/include/version.php b/include/version.php index 1152710..8ab8219 100644 --- a/include/version.php +++ b/include/version.php @@ -26,6 +26,10 @@ class Version { var $iSubmitterId; var $sDate; var $sQueued; + var $iMaintainerRequest; /* Temporary variable for version submisson. + Indicates whether the user wants to become a + maintainer of the version being submitted. + Value denotes type of request. */ /** * constructor, fetches the data. @@ -90,6 +94,19 @@ class Version { $this->iVersionId = mysql_insert_id(); $this->Version($this->iVersionId); $this->SendNotificationMail(); + + /* Submit maintainer request if asked to */ + if($this->iMaintainerRequest == MAINTAINER_REQUEST) + { + $oMaintainer = new Maintainer(); + $oMaintainer->iAppId = $this->iAppId; + $oMaintainer->iVersionId = $this->iVersionId; + $oMaintainer->iUserId = $_SESSION['current']->iUserId; + $oMaintainer->sMaintainReason = "This user submitted the version;". + "auto-queued."; + $oMaintainer->bSuperMaintainer = 0; + $oMaintainer->create(); + } return true; } else @@ -348,6 +365,18 @@ class Version { // we send an e-mail to interested people $this->mailSubmitter("unQueue"); $this->SendNotificationMail(); + + /* Unqueue matching maintainer request */ + $hResultMaint = query_parameters("SELECT maintainerId FROM + appMaintainers WHERE userId = '?' AND versionId = '?'", + $this->iSubmitterId, $this->iVersionId); + + if($hResultMaint && mysql_num_rows($hResultMaint)) + { + $oMaintainerRow = mysql_fetch_object($hResultMaint); + $oMaintainer = new Maintainer($oMaintainerRow->maintainerId); + $oMaintainer->unQueue("OK"); + } } } @@ -562,6 +591,21 @@ class Version { echo $this->sDescription.'

',"\n"; + /* Allow the user to apply as maintainer if this is a new version. + If it is a new application as well, radio boxes will be displayed + by the application class instead. */ + if(!$this->iVersionId && $_REQUEST['iAppId']) + { + if($this->iMaintainerRequest == MAINTAINER_REQUEST) + $sRequestMaintainerChecked = 'checked="checked"'; + echo html_tr(array( + array("Become maintainer?", "class=\"color0\""), + " ". + "Check this box to request being a maintainer for this version"), + "","valign=\"top\""); + } + echo '',"\n"; echo html_frame_end(); @@ -608,6 +652,7 @@ class Version { $this->sDescription = $aValues['shVersionDescription']; $this->sTestedRating = $aValues['sMaintainerRating']; $this->sTestedRelease = $aValues['sMaintainerRelease']; + $this->iMaintainerRequest = $aValues['iMaintainerRequest']; } function display($iTestingId) diff --git a/unit_test/test_maintainer.php b/unit_test/test_maintainer.php index 316d7dc..27e9c6d 100644 --- a/unit_test/test_maintainer.php +++ b/unit_test/test_maintainer.php @@ -278,7 +278,7 @@ function test_superMaintainerOnAppSubmit() $oApp = new Application($iAppId); /* The user wants to be a super maintainer */ - $oApp->bSuperMaintainerRequest = 1; + $oApp->iMaintainerRequest = SUPERMAINTAINER_REQUEST; /* Make sure the user is not an admin, so the app will be queued */ $oUser->delPriv("admin");