Add and use objectGetChildren() method. Add support for initializing comment class from SQL

result.
This commit is contained in:
Alexander Nicolaysen Sørnes
2007-09-08 22:38:20 +00:00
committed by WineHQ
parent faf7d9bb19
commit 5a4cbf49a3
4 changed files with 252 additions and 191 deletions

View File

@@ -240,59 +240,26 @@ class Application {
if(!$_SESSION['current']->canDeleteApplication($this)) if(!$_SESSION['current']->canDeleteApplication($this))
return false; return false;
/* we have to retrieve the versions again here because */ foreach($this->objectGetChildren() as $oChild)
/* new ones could have been added since this application */
/* object was created */
//FIXME: how to deal with concurrency issues such as
// if a new version was added during this deletion?
$hResult = $this->_internal_retrieve_all_versions();
while($oRow = query_fetch_object($hResult))
{ {
$iVersionId = $oRow->versionId; if(!$oChild->delete())
$oVersion = new Version($iVersionId); $bSuccess = FALSE;
if(!$oVersion->delete($bSilent))
$bSuccess = false; // return false, deleting the version failed
}
/* fetch urlsIds */
$aUrlsIds = array();
$sQuery = "SELECT id
FROM appData
WHERE type = 'url'
AND appId = '?'";
if($hResult = query_parameters($sQuery, $this->iAppId))
{
while($oRow = query_fetch_object($hResult))
{
$aUrlsIds[] = $oRow->id;
}
}
foreach($aUrlsIds as $iUrlId)
{
$oUrl = new Url($iUrlId);
$oUrl->delete($bSilent);
}
// remove any supermaintainers for this application so we don't orphan them
$hResult = Maintainer::deleteMaintainersForApplication($this);
if(!$hResult)
{
addmsg("Error removing app maintainers for the deleted application!", "red");
} }
$sQuery = "DELETE FROM appFamily $sQuery = "DELETE FROM appFamily
WHERE appId = '?' WHERE appId = '?'
LIMIT 1"; LIMIT 1";
if(!($hResult = query_parameters($sQuery, $this->iAppId))) if(!($hResult = query_parameters($sQuery, $this->iAppId)))
{ $bSuccess = false;
addmsg("Error deleting application!", "red");
}
if(!$bSilent) if(!$bSilent)
{
$this->SendNotificationMail("delete"); $this->SendNotificationMail("delete");
if(!$bSuccess)
addmsg("Error deleting application", "red");
}
return $bSuccess; return $bSuccess;
} }
@@ -1019,6 +986,60 @@ class Application {
return $oRow->count; return $oRow->count;
} }
function getVersions()
{
$aVersions = array();
$hResult = $this->_internal_retrieve_all_versions();
while($oRow = mysql_fetch_object($hResult))
$aVersions[] = new version($oRow->versionId);
return $aVersions;
}
function objectGetChildren()
{
$aChildren = array();
/* Get versions */
foreach($this->getVersions() as $oVersion)
{
$aChildren += $oVersion->objectGetChildren();
$aChildren[] = $oVersion;
}
/* Get urls */
$sQuery = "SELECT * FROM appData WHERE type = '?' AND appId = '?'";
$hResult = query_parameters($sQuery, "url", $this->iAppId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oUrl = new url(0, $oRow);
$aChildren += $oUrl->objectGetChildren();
$aChildren[] = $oUrl;
}
/* Get maintainers */
$sQuery = "SELECT * FROM appMaintainers WHERE appId = '?' AND superMaintainer = '?'";
$hResult = query_parameters($sQuery, $this->iAppId, '1');
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oMaintainer = new maintainer(0, $oRow);
$aChildren += $oMaintainer->objectGetChildren();
$aChildren[] = $oMaintainer;
}
return $aChildren;
}
function objectMoveChildren($iNewId) function objectMoveChildren($iNewId)
{ {
/* Keep track of how many children we have moved */ /* Keep track of how many children we have moved */

View File

@@ -27,9 +27,12 @@ class Comment {
* Constructor. * Constructor.
* If $iCommentId is provided, fetches comment. * If $iCommentId is provided, fetches comment.
*/ */
function Comment($iCommentId="") function Comment($iCommentId = null, $oRow = null)
{ {
if(is_numeric($iCommentId)) if(!$iCommentId && !$oRow)
return;
if(!$oRow)
{ {
$sQuery = "SELECT appComments.*, appVersion.appId AS appId $sQuery = "SELECT appComments.*, appVersion.appId AS appId
FROM appComments, appVersion FROM appComments, appVersion
@@ -37,6 +40,10 @@ class Comment {
AND commentId = '?'"; AND commentId = '?'";
$hResult = query_parameters($sQuery, $iCommentId); $hResult = query_parameters($sQuery, $iCommentId);
$oRow = query_fetch_object($hResult); $oRow = query_fetch_object($hResult);
}
if($oRow)
{
$this->iCommentId = $oRow->commentId; $this->iCommentId = $oRow->commentId;
$this->iParentId = $oRow->parentId; $this->iParentId = $oRow->parentId;
$this->iAppId = $oRow->appId; $this->iAppId = $oRow->appId;

View File

@@ -19,6 +19,7 @@ class distribution {
// constructor, fetches the data. // constructor, fetches the data.
function distribution($iDistributionId = null, $oRow = null) function distribution($iDistributionId = null, $oRow = null)
{ {
$this->aTestingIds = array();
// we are working on an existing distribution. // we are working on an existing distribution.
if(!$iDistributionId && !$oRow) if(!$iDistributionId && !$oRow)
return; return;
@@ -156,14 +157,12 @@ class distribution {
if(sizeof($this->aTestingIds) && !$_SESSION['current']->hasPriv("admin")) if(sizeof($this->aTestingIds) && !$_SESSION['current']->hasPriv("admin"))
return FALSE; return FALSE;
// delete any test results this distribution has $bSuccess = TRUE;
if($this->aTestingIds)
foreach($this->objectGetChildren() as $oChild)
{ {
foreach($this->aTestingIds as $iTestId) if(!$oChild->delete())
{ $bSuccess = FALSE;
$oTestData = new TestData($iTestId);
$oTestData->delete();
}
} }
// now delete the Distribution // now delete the Distribution
@@ -171,17 +170,19 @@ class distribution {
WHERE distributionId = '?' WHERE distributionId = '?'
LIMIT 1"; LIMIT 1";
if(!($hResult = query_parameters($sQuery, $this->iDistributionId))) if(!($hResult = query_parameters($sQuery, $this->iDistributionId)))
{ $bSuccess = FALSE;
addmsg("Error removing the Distribution!", "red");
return false;
}
if(!$bSilent) if(!$bSilent)
{
$this->SendNotificationMail("delete"); $this->SendNotificationMail("delete");
if(!$bSuccess)
addmsg("Error deleting distribution", "delete");
}
$this->mailSubmitter("delete"); $this->mailSubmitter("delete");
return true; return $bSuccess;
} }
@@ -226,6 +227,31 @@ class distribution {
return $this->delete(); return $this->delete();
} }
function getTestResults()
{
$aTests = array();
$sQuery = "SELECT * FROM testResults WHERE distributionId = '?'";
$hResult = query_parameters($sQuery, $this->iDistributionId);
while($oRow = mysql_fetch_object($hResult))
$aTests += new testData(null, $oRow);
return $aTests;
}
function objectGetChildren()
{
$aChildren = array();
foreach($this->getTestResults() as $oTest)
{
$aChildren += $oTest->objectGetChildren();
$aChildren[] = $oTest;
}
return $aChildren;
}
function ReQueue() function ReQueue()
{ {
// is the current user allowed to requeue this data // is the current user allowed to requeue this data

View File

@@ -220,134 +220,12 @@ class version {
if(!$_SESSION['current']->canDeleteVersion($this)) if(!$_SESSION['current']->canDeleteVersion($this))
return false; return false;
/* fetch notesIds */ $bSuccess = TRUE;
$aNotesIds = array();
$sQuery = "SELECT noteId foreach($this->objectGetChildren() as $oChild)
FROM appNotes
WHERE versionId = '?'";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{ {
while($oRow = query_fetch_object($hResult)) if(!$oChild->delete())
{ $bSuccess = FALSE;
$aNotesIds[] = $oRow->noteId;
}
}
/* remove all of the items this version contains */
foreach($aNotesIds as $iNoteId)
{
$oNote = new Note($iNoteId);
$oNote->delete($bSilent);
}
/* We fetch commentsIds. */
$aCommentsIds = array();
$sQuery = "SELECT commentId
FROM appComments
WHERE versionId = '?'";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{
while($oRow = query_fetch_object($hResult))
{
$aCommentsIds[] = $oRow->commentId;
}
}
foreach($aCommentsIds as $iCommentId)
{
$oComment = new Comment($iCommentId);
// delete the comment silently, we don't want to send out
// any notifications since the version is being deleted
$oComment->delete(true);
}
/* fetch screenshotsIds and urlsIds */
$aScreenshotsIds = array();
$aUrlsIds = array();
$sQuery = "SELECT id, type
FROM appData
WHERE versionId = '?'";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{
while($oRow = query_fetch_object($hResult))
{
if($oRow->type="image")
$aScreenshotsIds[] = $oRow->id;
else
$aUrlsIds[] = $oRow->id;
}
}
foreach($aScreenshotsIds as $iScreenshotId)
{
$oScreenshot = new Screenshot($iScreenshotId);
$oScreenshot->delete($bSilent);
}
foreach($aUrlsIds as $iUrlId)
{
$oUrl = new Url($iUrlId);
$oUrl->delete($bSilent);
}
$aBuglinkIds = $this->get_buglink_ids();
foreach($aBuglinkIds as $iBug_id)
{
$oBug = new Bug($iBug_id);
$oBug->delete($bSilent);
}
/* fetch Test Results Ids */
$aTestingIds = array();
$sQuery = "SELECT *
FROM testResults
WHERE versionId = '?'
ORDER BY testingId";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{
while($oRow = query_fetch_object($hResult))
{
$aTestingIds[] = $oRow->testingId;
}
}
foreach($aTestingIds as $iTestId)
{
$oTest = new testData($iTestId);
$oTest->delete($bSilent);
}
/* fetch monitor Ids */
$aMonitorIds = array();
$sQuery = "SELECT *
FROM appMonitors
WHERE versionId = '?'
ORDER BY monitorId";
if($hResult = query_parameters($sQuery, $this->iVersionId))
{
while($oRow = query_fetch_object($hResult))
{
$aMonitorIds[] = $oRow->monitorId;
}
}
foreach($aMonitorIds as $iMonitorId)
{
$oMonitor = new Monitor($iMonitorId);
$oMonitor->delete($bSilent);
}
// remove any maintainers for this version so we don't orphan them
$result = Maintainer::deleteMaintainersForVersion($this);
if(!$result)
{
addmsg("Error removing version maintainers for the deleted version!", "red");
} }
/* now delete the version */ /* now delete the version */
@@ -355,16 +233,18 @@ class version {
WHERE versionId = '?' WHERE versionId = '?'
LIMIT 1", $this->iVersionId); LIMIT 1", $this->iVersionId);
if(!$hResult) if(!$hResult)
{ $bSuccess = FALSE;
addmsg("Error removing the deleted version!", "red");
}
if(!$bSilent)
$this->SendNotificationMail("delete");
$this->mailSubmitter("delete"); $this->mailSubmitter("delete");
return true; if(!$bSilent)
{
if(!$bSuccess)
addmsg("Error removing version", "red");
$this->SendNotificationMail("delete");
}
return $bSuccess;
} }
@@ -1538,6 +1418,133 @@ class version {
"From that page you can edit, delete or approve it into the AppDB.</p>\n"; "From that page you can edit, delete or approve it into the AppDB.</p>\n";
} }
function objectGetChildren()
{
$aChildren = array();
/* Find test results */
$sQuery = "SELECT * FROM testResults WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oTest = new testData(0, $oRow);
$aChildren += $oTest->objectGetChildren();
$aChildren[] = $oTest;
}
/* Find maintainers */
$sQuery = "SELECT * FROM appMaintainers WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oMaintainer = new maintainer(0, $oRow);
$aChildren += $oMaintainer->objectGetChildren();
$aChildren[] = $oMaintainer;
}
/* Find monitors */
$sQuery = "SELECT * FROM appMonitors WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oMonitor = new monitor(0, $oRow);
$aChildren += $oMonitor->objectGetChildren();
$aChildren[] = $oMonitor;
}
/* Find notes */
$sQuery = "SELECT * FROM appNotes WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oNote = new note(0, $oRow);
$aChildren += $oNote->objectGetChildren();
$aChildren[] = $oNote;
}
/* Find screenshots */
$sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
$hResult = query_parameters($sQuery, "screenshot", $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oScreenshot = new screenshot(0, $oRow);
$aChildren += $oScreenshot->objectGetChildren();
$aChildren[] = $oScreenshot;
}
/* Get bug links */
foreach($this->get_buglink_ids() as $iBugId)
{
$oBug = new bug($iBugId);
$aChildren += $oBug->objectGetChildren();
$aChildren[] = $oBug;
}
/* Get comments */
$sQuery = "SELECT * FROM appComments WHERE versionId = '?'";
$hResult = query_parameters($sQuery, $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oComment = new comment(0, $oRow);
$aChildren += $oComment->objectGetChildren();
$aChildren[] = $oComment;
}
/* Get urls */
$sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
$hResult = query_parameters($sQuery, "url", $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oUrl = new url(0, $oRow);
$aChildren += $oUrl->objectGetChildren();
$aChildren[] = $oUrl;
}
/* Get downloadurls */
$sQuery = "SELECT * FROM appData WHERE type = '?' AND versionId = '?'";
$hResult = query_parameters($sQuery, "downloadurl", $this->iVersionId);
if(!$hResult)
return FALSE;
while($oRow = mysql_fetch_object($hResult))
{
$oDownload = new downloadurl(0, $oRow);
$aChildren += $oDownload->objectGetChildren();
$aChildren[] = $oDownload;
}
return $aChildren;
}
function objectMoveChildren($iNewId) function objectMoveChildren($iNewId)
{ {
/* Keep track of how many items we have updated */ /* Keep track of how many items we have updated */