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.
This commit is contained in:
Chris Morgan
2007-08-27 03:48:44 +00:00
committed by WineHQ
parent 82d02d655f
commit 43a7ea8f1d
8 changed files with 260 additions and 234 deletions

View File

@@ -1,170 +0,0 @@
<?php
/***************************************************/
/* code to view and maintain the list of bug links */
/***************************************************/
/*
* application environment
*/
require("path.php");
require(BASE."include/incl.php");
require_once(BASE."include/bugs.php");
// deny access if not logged in
if(!$_SESSION['current']->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 '<form method="get" name="sMessage" action="'.$_SERVER['PHP_SELF'].'">',"\n";
echo '<center>',"\n";
echo '<b>Page '.$currentPage.' of '.$totalPages.'</b><br />',"\n";
display_page_range($currentPage, $pageRange, $totalPages, $_SERVER['PHP_SELF']."?iItemsPerPage=".$ItemsPerPage."&sQueuedOnly=".$QueuedOnly);
echo '<br />',"\n";
echo '<br />',"\n";
/* display the option to choose how many comments per-page to display */
echo '<input type="hidden" name="iPage" value="'.$currentPage.'" />';
echo '<b>Number of Bug Links per page: </b>';
echo '<select name="iItemsPerPage">';
$ItemsPerPageArray = array(2 ,10, 20, 50, 100);
foreach($ItemsPerPageArray as $i => $value)
{
if($ItemsPerPageArray[$i] == $ItemsPerPage)
echo '<option value="'.$ItemsPerPageArray[$i].'" selected="selected">'.$ItemsPerPageArray[$i],"\n";
else
echo '<option value="'.$ItemsPerPageArray[$i].'">'.$ItemsPerPageArray[$i],"\n";
}
echo '</select>',"\n";
echo '<br />',"\n";
echo '<b>View queued links only: </b><input type=checkbox name="sQueuedOnly" '.($QueuedOnly == "on"?" CHECKED":"").'>',"\n";
echo '<br />',"\n";
echo '<input type=submit value="Refresh">',"\n";
echo '</center>',"\n";
echo '</form>',"\n";
echo '<table width=100% border=0 cellpadding=3 cellspacing=1>',"\n";
echo '<tr class=color4>',"\n";
echo ' <td align=center width="40">Bug #</td>',"\n";
echo ' <td align=center width="60">Status</td>',"\n";
echo ' <td>Bug Description</td>',"\n";
echo ' <td width=80>Application Name</td>',"\n";
echo ' <td>Aplication Description</td>',"\n";
echo ' <td width=40>version</td>',"\n";
echo ' <td align=center width="40">delete</td>',"\n";
echo ' <td align=center width="40">checked</td>',"\n";
echo '</tr>',"\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 '<tr class='.$bgcolor.'>',"\n";
echo ' <td align=center>',"\n";
echo ' <a href="'.BUGZILLA_ROOT.'show_bug.cgi?id='.$oRow->bug_id.'">'.$oRow->bug_id.'</a>',"\n";
echo ' </td>',"\n";
echo ' <td align=center>'.$oRow->bug_status.'</td>',"\n";
echo ' <td>'.$oRow->short_desc.'</td>',"\n";
echo ' <td>',"\n";
echo $oApp->objectMakeLink()."\n";
echo ' </td>',"\n";
echo ' <td>'.$oRow->appDescription.'</td>',"\n";
echo ' <td>',"\n";
echo $oVersion->objectMakeLink()."\n";
echo ' </td>',"\n";
echo ' <td align=center>[<a href="adminBugs.php?sSub=delete',"\n";
echo '&iBuglinkId='.$oRow->linkId,"\n";
echo '&sQueuedOnly='.$QueuedOnly,"\n";
echo '&iItemsPerPage='.$ItemsPerPage,"\n";
echo '&iPage='.$currentPage,"\n";
echo '">delete</a>]</td>',"\n";
$bQueued = ($oRow->queued=="true")?true:false;
if ($bQueued)
{
echo '<td align=center>[<a href="adminBugs.php?sSub=unqueue',"\n";
echo '&iBuglinkId='.$oRow->linkId,"\n";
echo '&sQueuedOnly='.$QueuedOnly,"\n";
echo '&iItemsPerPage='.$ItemsPerPage,"\n";
echo '&iPage='.$currentPage,"\n";
echo '">OK</a>]</td>',"\n";
} else
{
echo '<td align=center>Yes</td>',"\n";
}
echo '</tr>',"\n";
$c++;
}
}
echo "</table>","\n";
echo "<center>","\n";
display_page_range($currentPage, $pageRange, $totalPages, $_SERVER['PHP_SELF']."?iItemsPerPage=".$ItemsPerPage."&sQueuedOnly=".$QueuedOnly);
echo "</center>","\n";
apidb_footer();
}
?>

View File

@@ -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 = "<a href=\"".$this->objectMakeUrl()."\">".
$this->sShort_desc."</a>";
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 '<input type="hidden" name="iBugLinkId" value="'.$this->iLinkId.'" >';
}
function getOutputEditorValues($aClean)
{
$this->iTestingId = $aValues['iBugLinkId'];
}
}

View File

@@ -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) ".

View File

@@ -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("&nbsp;");
$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");

View File

@@ -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)
{

View File

@@ -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");

View File

@@ -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']))

View File

@@ -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",