diff --git a/include/application.php b/include/application.php index fcefc39..d189192 100644 --- a/include/application.php +++ b/include/application.php @@ -9,6 +9,7 @@ require_once(BASE."include/category.php"); require_once(BASE."include/url.php"); require_once(BASE."include/util.php"); require_once(BASE."include/mail.php"); +require_once(BASE."include/maintainer.php"); define("PLATINUM_RATING", "Platinum"); define("GOLD_RATING", "Gold"); @@ -33,6 +34,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 /** * constructor, fetches the data. @@ -128,6 +131,18 @@ class Application { $this->iAppId = mysql_insert_id(); $this->application($this->iAppId); $this->SendNotificationMail(); // Only administrators will be mailed as no supermaintainers exist for this app. + + /* Submit super maintainer request if asked to */ + if($this->bSuperMaintainerRequest) + { + $oMaintainer = new Maintainer(); + $oMaintainer->iAppId = $this->iAppId; + $oMaintainer->iUserId = $_SESSION['current']->iUserId; + $oMaintainer->sMaintainReason = "This user submitted the application; auto-queued."; + $oMaintainer->bSuperMaintainer = 1; + $oMaintainer->create(); + } + return true; } else { @@ -291,6 +306,15 @@ class Application { // we send an e-mail to intersted people $this->mailSubmitter(); $this->SendNotificationMail(); + + /* Unqueue matching super maintainer request */ + $hResultMaint = query_parameters("SELECT maintainerId FROM appMaintainers WHERE userId = '?' AND appId = '?'", $this->iSubmitterId, $this->iAppId); + if($hResultMaint) + { + $oMaintainerRow = mysql_fetch_object($hResultMaint); + $oMaintainer = new Maintainer($oMaintainerRow->maintainerId); + $oMaintainer->unQueue("OK"); + } } } @@ -336,7 +360,10 @@ class Application { { $aClean = array(); //array of filtered user input - $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); + if(isset($_REQUEST['sReplyText'])) + $aClean['sReplyText'] = makeSafe($_REQUEST['sReplyText']); + else + $aClean['sReplyText'] = ""; if($this->iSubmitterId) { @@ -517,6 +544,15 @@ class Application { echo $this->sDescription.'

',"\n"; + // 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"; + } + echo "\n"; echo html_frame_end(); @@ -556,6 +592,7 @@ class Application { $this->iVendorId = $aValues['iAppVendorId']; $this->sWebpage = $aValues['sAppWebpage']; $this->sKeywords = $aValues['sAppKeywords']; + $this->bSuperMaintainerRequest = $aValues['bSuperMaintainerRequest']; } /* display this application */ diff --git a/include/maintainer.php b/include/maintainer.php index c4828f0..18ca1b6 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -185,9 +185,11 @@ class maintainer function ObjectGetEntries($bQueued) { + /* Excluding requests for queued apps, as these will be handled automatically */ if($bQueued) - $sQuery = "SELECT maintainerId FROM appMaintainers, user_list WHERE appMaintainers.userid = user_list.userid ". - "AND queued = '?' ORDER by submitTime"; + $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"; else $sQuery = "SELECT maintainerId FROM appMaintainers, user_list WHERE appMaintainers.userid = user_list.userid ". "AND queued = '?' ORDER by realname"; @@ -248,7 +250,8 @@ class maintainer function getQueuedMaintainerCount() { - $sQuery = "SELECT count(*) as queued_maintainers FROM appMaintainers where queued='true'"; + /* 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); $oRow = mysql_fetch_object($hResult); return $oRow->queued_maintainers; diff --git a/unit_test/test_maintainer.php b/unit_test/test_maintainer.php index f7b7e7e..316d7dc 100644 --- a/unit_test/test_maintainer.php +++ b/unit_test/test_maintainer.php @@ -257,6 +257,53 @@ function test_maintainer_unQueue() return true; } +/* Test whether a super maintainer request submitted along with an application is also accepted when the application is accepted */ +function test_superMaintainerOnAppSubmit() +{ + test_start(__FUNCTION__); + + global $test_email, $test_password; + + /* Log in */ + $oUser = new User(); + if($retval = $oUser->login($test_email, $test_password) != SUCCESS) + { + echo "Received '$retval' instead of SUCCESS('".SUCCESS."')."; + return FALSE; + } + + $iAppId = 655000; + $iVersionId = 655200; + + $oApp = new Application($iAppId); + + /* The user wants to be a super maintainer */ + $oApp->bSuperMaintainerRequest = 1; + + /* Make sure the user is not an admin, so the app will be queued */ + $oUser->delPriv("admin"); + + $oApp->create(); + + /* Make the user an admin so the app can be unqueued */ + $oUser->addPriv("admin"); + + $oApp->unQueue(); + + /* The user should now be a super maintainer */ + $iExpected = 1; + $iGot = Maintainer::getMaintainerCountForUser($oUser, TRUE); + + if($iGot != $iExpected) + { + echo "Got maintainer count of '$iGot' instead of '$iExpected'"; + return false; + } + + Maintainer::deleteMaintainer($oUser, $iAppId); + + return true; +} if(!test_maintainer_getMaintainerCountForUser()) echo "test_maintainer_getMaintainerCountForUser() failed!\n"; @@ -275,4 +322,9 @@ if(!test_maintainer_unQueue()) else echo "test_maintainer_unQueue() passed\n"; +if(!test_superMaintainerOnAppSubmit()) + echo "test_superMaintainerOnAppSubmit() failed!\n"; +else + echo "test_superMaintainerOnAppSubmit() passed\n"; + ?>