bug: Move duplicate detection to a separate function

This commit is contained in:
Alexander Nicolaysen Sørnes
2009-07-30 16:52:42 +02:00
parent a083c9eb0e
commit 8e9122b6f5

View File

@@ -106,22 +106,12 @@ class Bug
return false; return false;
} }
/* Check for Duplicates */ /* Check for duplicates */
if($this->isDuplicate())
$sQuery = "SELECT *
FROM buglinks
WHERE versionId = '?'";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{
while($oRow = query_fetch_object($hResult))
{
if($oRow->bug_id == $this->iBug_id)
{ {
addmsg("The Bug link has already been submitted.", "red"); addmsg("The Bug link has already been submitted.", "red");
return false; return false;
} }
}
}
/* passed the checks so lets insert the puppy! */ /* passed the checks so lets insert the puppy! */
$hResult = query_parameters("INSERT INTO buglinks (versionId, bug_id, ". $hResult = query_parameters("INSERT INTO buglinks (versionId, bug_id, ".
@@ -204,6 +194,23 @@ class Bug
return true; return true;
} }
/* Checks whether the version already has a link for this bug */
public function isDuplicate()
{
$sQuery = "SELECT COUNT(linkId) as count
FROM buglinks
WHERE versionId = '?'
AND bug_id = '?'";
if($hResult = query_parameters($sQuery, $this->iVersionId, $this->iBug_id))
{
if(($oRow = query_fetch_object($hResult)))
{
return $oRow->count > 0;
}
}
return false;
}
function mailSubmitter($bRejected=false) function mailSubmitter($bRejected=false)
{ {
global $aClean; global $aClean;