From 43a7ea8f1d4ad1f2246b44533dc1c802215d6cc4 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Mon, 27 Aug 2007 03:48:44 +0000 Subject: [PATCH] Add object manager support to the bug class. Add menu entries for displaying the bug queue and list of bugs and remove the existing link to admin/adminBugs.php. Remove now unused admin/adminBugs.php. Remove now unused getNumberOfQueuedBugLinks() and getNumberOfBugLinks() from util.php. Add object manager unit test support for the bug class. --- admin/adminBugs.php | 170 ---------------------- include/bugs.php | 259 +++++++++++++++++++++++++++++----- include/maintainer.php | 2 + include/sidebar_admin.php | 8 +- include/util.php | 24 ---- include/version.php | 1 + objectManager.php | 1 + unit_test/test_om_objects.php | 29 +++- 8 files changed, 260 insertions(+), 234 deletions(-) delete mode 100644 admin/adminBugs.php diff --git a/admin/adminBugs.php b/admin/adminBugs.php deleted file mode 100644 index 4a9cf28..0000000 --- a/admin/adminBugs.php +++ /dev/null @@ -1,170 +0,0 @@ -hasPriv("admin")) - util_show_error_page_and_exit("Insufficient privileges."); - -if (isset($aClean['sSub'])) -{ - if(($aClean['sSub'] == 'delete' ) && ($aClean['iBuglinkId'])) - { - $oBuglink = new Bug($aClean['iBuglinkId']); - $oBuglink->delete(); - } - if(($aClean['sSub'] == 'unqueue' ) && ($aClean['iBuglinkId'])) - { - $oBuglink = new Bug($aClean['iBuglinkId']); - $oBuglink->unqueue(); - } - util_redirect_and_exit($_SERVER['PHP_SELF']."?iItemsPerPage=".$aClean['iItemsPerPage']."&sQueuedOnly=".$aClean['sQueuedOnly']."&iPage=".$aClean['iPage']); - -} - -{ - apidb_header("Administer Bugs"); - - $pageRange = 10; - - $QueuedOnly = empty($aClean['sQueuedOnly'])? NULL: $aClean['sQueuedOnly']; - $BugLinks = ($QueuedOnly == 'on')?getNumberOfQueuedBugLinks():getNumberOfBugLinks(); - - $ItemsPerPage = isset($aClean['iItemsPerPage']) ? $aClean['iItemsPerPage'] : 10; - $currentPage = isset($aClean['iPage']) ? $aClean['iPage'] : 1; - - $ItemsPerPage = min($ItemsPerPage,100); - $totalPages = max(ceil($BugLinks/$ItemsPerPage),1); - $currentPage = min($currentPage,$totalPages); - $offset = (($currentPage-1) * $ItemsPerPage); - - /* display page selection links */ - echo '
',"\n"; - echo '
',"\n"; - echo 'Page '.$currentPage.' of '.$totalPages.'
',"\n"; - display_page_range($currentPage, $pageRange, $totalPages, $_SERVER['PHP_SELF']."?iItemsPerPage=".$ItemsPerPage."&sQueuedOnly=".$QueuedOnly); - echo '
',"\n"; - echo '
',"\n"; - - /* display the option to choose how many comments per-page to display */ - echo ''; - - echo 'Number of Bug Links per page: '; - echo '',"\n"; - - echo '
',"\n"; - echo 'View queued links only: ',"\n"; - echo '
',"\n"; - echo '',"\n"; - - echo '
',"\n"; - echo '
',"\n"; - - echo '',"\n"; - echo '',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo '',"\n"; - if ($QueuedOnly == 'on') - { - $sWhere = "WHERE appFamily.appId = appVersion.appId - AND buglinks.versionId = appVersion.versionId - AND buglinks.bug_id = ".BUGZILLA_DB.".bugs.bug_id - AND buglinks.queued = 'true'"; - } else - { - $sWhere = "WHERE appFamily.appId = appVersion.appId - AND buglinks.versionId = appVersion.versionId - AND buglinks.bug_id = ".BUGZILLA_DB.".bugs.bug_id"; - } - $sQuery = "SELECT appFamily.description as appDescription, - appFamily.appName as appName, appVersion.*, - buglinks.versionId as versionId, - buglinks.bug_id as bug_id, - buglinks.linkId as linkId, - buglinks.queued as queued, - bugs.* - FROM appFamily, appVersion, buglinks, bugs.bugs - ".$sWhere." - ORDER BY buglinks.bug_id, appName, versionName - LIMIT ".query_escape_string($offset).", ".query_escape_string($ItemsPerPage).";"; - - $c = 0; - - if($hResult = query_parameters($sQuery)) - { - while($oRow = query_fetch_object($hResult)) - { - $oApp = new application($oRow->appId); - $oVersion = new version($oRow->versionId); - // set row color - $bgcolor = ($c % 2 == 0) ? "color0" : "color1"; - echo '',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - echo ' ',"\n"; - $bQueued = ($oRow->queued=="true")?true:false; - if ($bQueued) - { - echo '',"\n"; - } else - { - echo '',"\n"; - } - echo '',"\n"; - $c++; - } - } - - echo "
Bug #StatusBug DescriptionApplication NameAplication Descriptionversiondeletechecked
',"\n"; - echo ' '.$oRow->bug_id.'',"\n"; - echo ' '.$oRow->bug_status.''.$oRow->short_desc.'',"\n"; - echo $oApp->objectMakeLink()."\n"; - echo ' '.$oRow->appDescription.'',"\n"; - echo $oVersion->objectMakeLink()."\n"; - echo ' [delete][OK]Yes
","\n"; - echo "
","\n"; - display_page_range($currentPage, $pageRange, $totalPages, $_SERVER['PHP_SELF']."?iItemsPerPage=".$ItemsPerPage."&sQueuedOnly=".$QueuedOnly); - echo "
","\n"; - - apidb_footer(); -} -?> diff --git a/include/bugs.php b/include/bugs.php index eea8a78..b02dbef 100644 --- a/include/bugs.php +++ b/include/bugs.php @@ -9,7 +9,8 @@ require_once(BASE."include/application.php"); /** * Bug Link class for handling Bug Links and thumbnails */ -class Bug { +class Bug +{ var $iLinkId; // parameters necessary to create a new Bug with Bug::create() @@ -20,7 +21,6 @@ class Bug { var $sShort_desc; var $sBug_status; var $sResolution; - var $iAppId; var $sSubmitTime; var $iSubmitterId; var $bQueued; @@ -28,34 +28,40 @@ class Bug { /** * Constructor, fetches the data and bug objects if $ilinkId is given. */ - function bug($iLinkId = null) + function bug($iLinkId = null, $oRow = null) { - // we are working on an existing Bug - if(is_numeric($iLinkId)) + if(!$iLinkId && !$oRow) + return; + + if(!$oRow) { - $sQuery = "SELECT buglinks.*, appVersion.appId AS appId - FROM buglinks, appVersion - WHERE buglinks.versionId = appVersion.versionId - AND linkid = '?'"; + $sQuery = "SELECT * FROM buglinks + WHERE linkid = '?'"; if($hResult = query_parameters($sQuery, $iLinkId)) { $oRow = query_fetch_object($hResult); - $this->iLinkId = $iLinkId; - $this->iAppId = $oRow->appId; - $this->iBug_id = $oRow->bug_id; - $this->iVersionId = $oRow->versionId; - $this->bQueued = ($oRow->queued=="true")?true:false; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - /* lets fill in some blanks */ - if ($this->iBug_id) - { - $sQuery = "SELECT * + } + } + + if($oRow) + { + $this->iLinkId = $oRow->linkId; + $this->iBug_id = $oRow->bug_id; + $this->iVersionId = $oRow->versionId; + $this->bQueued = ($oRow->queued=="true") ? true : false; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; + /* lets fill in some blanks */ + if ($this->iBug_id) + { + $sQuery = "SELECT * FROM bugs WHERE bug_id = ".$this->iBug_id; - if($hResult = query_bugzilladb($sQuery)) + if($hResult = query_bugzilladb($sQuery)) + { + $oRow = query_fetch_object($hResult); + if($oRow) { - $oRow = query_fetch_object($hResult); $this->sShort_desc = $oRow->short_desc; $this->sBug_status = $oRow->bug_status; $this->sResolution = $oRow->resolution; @@ -72,18 +78,18 @@ class Bug { function create() { $oVersion = new Version($this->iVersionId); - // Security, if we are not an administrator or a maintainer, the Bug must be queued. - if(!($_SESSION['current']->hasPriv("admin") || - $_SESSION['current']->isMaintainer($oVersion->iVersionId) || - $_SESSION['current']->isSuperMaintainer($oVersion->iAppId))) + + // Security, if we are not an administrator or a maintainer, + // the Bug must be queued. + if($this->mustBeQueued()) { $this->bQueued = true; } else { $this->bQueued = false; } - /* lets check for a valid bug id */ + /* lets check for a valid bug id */ if(!is_numeric($this->iBug_id)) { addmsg($this->iBug_id." is not a valid bug number.", "red"); @@ -91,7 +97,6 @@ class Bug { } /* check that bug # exists in bugzilla*/ - $sQuery = "SELECT * FROM bugs WHERE bug_id = ".$this->iBug_id; @@ -119,7 +124,6 @@ class Bug { } /* passed the checks so lets insert the puppy! */ - $hResult = query_parameters("INSERT INTO buglinks (versionId, bug_id, ". "submitTime, submitterId, queued) ". "VALUES('?', '?', ?, '?', '?')", @@ -129,7 +133,7 @@ class Bug { $this->bQueued ? "true":"false"); if($hResult) { - $this->iLinkId = query_bugzilla_insert_id(); + $this->iLinkId = query_appdb_insert_id(); $this->SendNotificationMail(); @@ -141,10 +145,11 @@ class Bug { } } - /** * Deletes the Bug from the database. * and request its deletion from the filesystem (including the thumbnail). + * + * Return true if successful, false if an error occurs */ function delete($bSilent=false) { @@ -154,16 +159,20 @@ class Bug { { if(!$bSilent) $this->SendNotificationMail(true); + } else + { + return false; } + if($this->iSubmitterId && ($this->iSubmitterId != $_SESSION['current']->iUserId)) { $this->mailSubmitter(true); } + return true; } - /** * Move Bug out of the queue. */ @@ -185,17 +194,23 @@ class Bug { } } + //TODO: figure out what we might want to do here but lie and + // return true until then + function update() + { + return true; + } function mailSubmitter($bRejected=false) { global $aClean; if(!isset($aClean['sReplyText'])) $aClean['sReplyText'] = ""; - + if($this->iSubmitterId) { $oSubmitter = new User($this->iSubmitterId); - $sAppName = Application::lookup_name($this->iAppId)." ".Version::lookup_name($this->iVersionId); + $sAppName = Version::fullName($this->iVersionId); if(!$bRejected) { $sSubject = "Submitted Bug Link accepted"; @@ -294,6 +309,182 @@ class Bug { { return ($this->sBug_status != 'RESOLVED' && $this->sBug_status != 'CLOSED'); } + + function allowAnonymousSubmissions() + { + return false; + } + + function mustBeQueued() + { + if($_SESSION['current']->hasPriv("admin") || + $_SESSION['current']->isMaintainer($oVersion->iVersionId) || + $_SESSION['current']->isSuperMaintainer($oVersion->iAppId)) + { + return false; + } + + return true; + } + + function objectGetId() + { + return $this->iLinkId; + } + + function objectGetEntries($bQueued, $bRejected, $iRows = 0, $iStart = 0) + { + $sLimit = ""; + + /* 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 = bug::objectGetEntriesCount($bQueued, $bRejected); + + $sQueued = objectManager::getQueueString($bQueued, $bRejected); + $sQuery = "select * from buglinks where queued = '?' LIMIT ?, ?"; + $hResult = query_parameters($sQuery, $sQueued, $iStart, $iRows); + return $hResult; + } + + function objectGetEntriesCount($bQueued, $bRejected) + { + $sQueued = objectManager::getQueueString($bQueued, $bRejected); + $sQuery = "select count(*) as cnt from buglinks where queued = '?'"; + $hResult = query_parameters($sQuery, $sQueued); + $oRow = mysql_fetch_object($hResult); + return $oRow->cnt; + } + + function objectGetHeader() + { + $oTableRow = new TableRow(); + + $oTableRow->AddTextCell("Bug #"); + + $oTableCell = new TableCell("Status"); + $oTableCell->SetAlign("center"); + $oTableRow->AddCell($oTableCell); + + $oTableRow->AddTextCell("Bug Description"); + + $oTableCell = new TableCell("Application Name"); + $oTableCell->SetAlign("center"); + $oTableRow->AddCell($oTableCell); + + $oTableCell = new TableCell("Application Description"); + $oTableCell->SetAlign("center"); + $oTableRow->AddCell($oTableCell); + + $oTableCell = new TableCell("Version"); + $oTableCell->SetAlign("center"); + $oTableRow->AddCell($oTableCell); + + return $oTableRow; + } + + // returns a table row + function objectGetTableRow() + { + $oTableRow = new TableRow(); + + $oVersion = new version($this->iVersionId); + $oApp = new application($oVersion->iAppId); + + $oTableCell = new TableCell($this->iBug_id); + $oTableCell->SetAlign("center"); + $oTableCell->SetCellLink(BUGZILLA_ROOT.'show_bug.cgi?id='.$oRow->bug_id); + $oTableRow->AddCell($oTableCell); + + $oTableCell = new TableCell($this->sBug_status); + $oTableCell->SetAlign("center"); + $oTableRow->AddCell($oTableCell); + + $oTableRow->AddTextCell($this->sShort_desc); + + $oTableRow->AddTextCell($oApp->objectMakeLink()); + + $oTableRow->AddTextCell(util_trim_description($oApp->sDescription)); + + $oTableRow->AddTextCell($oVersion->objectMakeLink()); + + $oOMTableRow = new OMTableRow($oTableRow); + + // enable the deletion link, the objectManager will check + // for appropriate permissions before adding the link + $oOMTableRow->SetRowHasDeleteLink(true); + + return $oOMTableRow; + } + + function objectMakeUrl() + { + $oManager = new objectManager("bug", "View Bug"); + return $oManager->makeUrl("view", $this->objectGetId()); + } + + function objectMakeLink() + { + $sLink = "objectMakeUrl()."\">". + $this->sShort_desc.""; + return $sLink; + } + + function canEdit() + { + if($_SESSION['current']->hasPriv("admin")) + { + return true; + } else if($this->iVersionId) + { + if(maintainer::isUserMaintainer($_SESSION['current'], + $this->iVersionId)) + { + return true; + } + } + + return false; + } + + function objectGetItemsPerPage($bQueued = false) + { + $aItemsPerPage = array(25, 50, 100, 200); + $iDefaultPerPage = 25; + return array($aItemsPerPage, $iDefaultPerPage); + } + + function display() + { + $oTable = new Table(); + $oTable->SetAlign("center"); + $oTable->SetClass("color0"); + $oTable->SetCellPadding(2); + + $oHeaderRow = $this->objectGetHeader(); + $oHeaderRow->SetClass("color4"); + $oTable->AddRow($oHeaderRow); + + $oDataRow = $this->objectGetTableRow(); + $oDataRow->oTableRow->SetClass("color0"); + $oTable->AddRow($oDataRow); + + echo $oTable->GetString(); + } + + // NOTE: we don't have any editing support for this entry at this time + // so output the entry and a field to identify the bug id + function outputEditor() + { + $this->display(); + echo ''; + } + + function getOutputEditorValues($aClean) + { + $this->iTestingId = $aValues['iBugLinkId']; + } } diff --git a/include/maintainer.php b/include/maintainer.php index 6950282..462c384 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -210,7 +210,9 @@ class maintainer { /* user id, appid, and maintain reason must be valid to continue */ if(!$this->iUserId || !$this->iAppId || !$this->sMaintainReason) + { return NULL; + } $hResult = query_parameters("INSERT INTO appMaintainers (appId, versionId, ". "userId, maintainReason, superMaintainer, submitTime, queued) ". diff --git a/include/sidebar_admin.php b/include/sidebar_admin.php index c110983..4447157 100644 --- a/include/sidebar_admin.php +++ b/include/sidebar_admin.php @@ -25,13 +25,17 @@ function global_admin_menu() { $g->add("Test Results Queue (".testData::objectGetEntriesCount(true, false).")", BASE."objectManager.php?sClass=testData_queue&bIsQueue=true&sTitle=". "Test%20Results%20Queue"); + $g->add("Bug Link Queue (".bug::objectGetEntriesCount(true, false).")", + BASE."objectManager.php?sClass=bug&bIsQueue=true&sTitle=". + "Bug%20Link%20Queue"); $g->addmisc(" "); $g->add("Maintainer Entries (".Maintainer::getMaintainerCount().")", BASE."admin/adminMaintainers.php"); - $g->add("Bug Links (".getNumberOfQueuedBugLinks()."/".getNumberOfBugLinks().")", - BASE."admin/adminBugs.php"); + $g->add("Bug Links (".bug::objectGetEntriesCount(false, false).")", + BASE."objectManager.php?sClass=bug&bIsQueue=false&sTitle=". + "Bug%20Links"); $g->add("Test Results (".testData::objectGetEntriesCount(false, false).")", BASE."objectManager.php?sClass=testData&bIsQueue=false&sTitle=". "View%20Test%20Results"); diff --git a/include/util.php b/include/util.php index b88ae40..9ac0b32 100644 --- a/include/util.php +++ b/include/util.php @@ -226,30 +226,6 @@ function getNumberOfComments() return $oRow->num_comments; } -/* Get the number of queued bug links in the database */ -function getNumberOfQueuedBugLinks() -{ - $hResult = query_parameters("SELECT count(*) as num_buglinks FROM buglinks WHERE queued='true';"); - if($hResult) - { - $oRow = query_fetch_object($hResult); - return $oRow->num_buglinks; - } - return 0; -} - -/* Get the number of bug links in the database */ -function getNumberOfBugLinks() -{ - $hResult = query_parameters("SELECT count(*) as num_buglinks FROM buglinks;"); - if($hResult) - { - $oRow = query_fetch_object($hResult); - return $oRow->num_buglinks; - } - return 0; -} - /* used by outputTopXRowAppsFromRating() to reduce duplicated code */ function outputTopXRow($oRow) { diff --git a/include/version.php b/include/version.php index 4d8c1b3..47f68d8 100644 --- a/include/version.php +++ b/include/version.php @@ -11,6 +11,7 @@ require_once(BASE."include/bugs.php"); require_once(BASE."include/util.php"); require_once(BASE."include/testData.php"); require_once(BASE."include/downloadurl.php"); +require_once(BASE."include/monitor.php"); define("LICENSE_OPENSOURCE", "Open Source"); define("LICENSE_FREEWARE", "Freeware"); diff --git a/objectManager.php b/objectManager.php index afbef83..0434688 100644 --- a/objectManager.php +++ b/objectManager.php @@ -23,6 +23,7 @@ require_once(BASE.'include/application_queue.php'); require_once(BASE.'include/version_queue.php'); require_once(BASE.'include/testData_queue.php'); require_once(BASE.'include/browse_newest_apps.php'); +require_once(BASE.'include/bugs.php'); /* if we have no valid class name we should abort */ if(!isset($aClean['sClass'])) diff --git a/unit_test/test_om_objects.php b/unit_test/test_om_objects.php index 06ad4b2..798e412 100644 --- a/unit_test/test_om_objects.php +++ b/unit_test/test_om_objects.php @@ -12,6 +12,8 @@ require_once(BASE.'include/version_queue.php'); require_once(BASE.'include/application_queue.php'); require_once(BASE.'include/browse_newest_apps.php'); require_once(BASE.'include/monitor.php'); +require_once(BASE.'include/bugs.php'); + /* internal function */ function test_class($sClassName, $aTestMethods) @@ -139,6 +141,11 @@ function cleanup($oObject) { switch(get_class($oObject)) { + case "bug": + // remove the bug row we created for the bug in create_object() + $sQuery = "delete from bugs where bug_id = '?'"; + $hResult = query_bugzilladb($sQuery, $oObject->iBug_id); + break; case "downloadurl": case "maintainer": case "screenshot": @@ -166,6 +173,18 @@ function create_object($sClassName, $oUser) /* Set up one test entry, depending on class */ switch($sClassName) { + case "bug": + // create a bug in the bugzilla database, we need a valid + // bug id to create a bug entry + $sQuery = "insert into bugs (short_desc, bug_status, resolution)". + " values ('?', '?', '?')"; + $hResult = query_bugzilladb($sQuery, "test_om_objects", "VERIFIED", + ''); + + // retrieve the bug id and assign that to our + // bug class + $oTestObject->iBug_id = query_bugzilla_insert_id(); + break; case "distribution": $oTestObject->sName = "Silly test distribution"; $oTestObject->sUrl = "http://appdb.winehq.org/"; @@ -173,10 +192,11 @@ function create_object($sClassName, $oUser) case "downloadurl": $oTestObject->sUrl = "http://appdb.winehq.org/"; $oTestObject->sDescription = "DANGER"; - $oTestObject->iVersionId = create_version_and_parent_app(); + $oTestObject->iVersionId = create_version_and_parent_app("create_object_downloadurl"); break; case "maintainer": - $oVersion = new version(create_version_and_parent_app()); + $iVersionId = create_version_and_parent_app("create_object_maintainer"); + $oVersion = new version($iVersionId); $oTestObject->iUserId = $oUser->iUserId; $oTestObject->iAppId = $oVersion->iAppId; $oTestObject->iVersionId = $oVersion->iVersionId; @@ -184,10 +204,10 @@ function create_object($sClassName, $oUser) break; case "screenshot": case "testData": - $oTestObject->iVersionId = create_version_and_parent_app(); + $oTestObject->iVersionId = create_version_and_parent_app("create_object_testData"); break; case "testData_queue": - $oTestObject->oTestData->iVersionId = create_version_and_parent_app(); + $oTestObject->oTestData->iVersionId = create_version_and_parent_app("create_object_testData_queue"); break; case "version": $oApp = new application(); @@ -250,6 +270,7 @@ function test_object_methods() $aTestClasses = array("application", "application_queue", "browse_newest_apps", + "bug", "distribution", "downloadurl", "maintainer",