From 5a4cbf49a3304a4ddca320548634c362b803078b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes?= Date: Sat, 8 Sep 2007 22:38:20 +0000 Subject: [PATCH] Add and use objectGetChildren() method. Add support for initializing comment class from SQL result. --- include/application.php | 105 +++++++++------ include/comment.php | 11 +- include/distribution.php | 52 ++++++-- include/version.php | 275 ++++++++++++++++++++------------------- 4 files changed, 252 insertions(+), 191 deletions(-) diff --git a/include/application.php b/include/application.php index 6cf19bf..adbbac9 100644 --- a/include/application.php +++ b/include/application.php @@ -240,59 +240,26 @@ class Application { if(!$_SESSION['current']->canDeleteApplication($this)) return false; - /* we have to retrieve the versions again here because */ - /* 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)) + foreach($this->objectGetChildren() as $oChild) { - $iVersionId = $oRow->versionId; - $oVersion = new Version($iVersionId); - 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"); + if(!$oChild->delete()) + $bSuccess = FALSE; } $sQuery = "DELETE FROM appFamily WHERE appId = '?' LIMIT 1"; if(!($hResult = query_parameters($sQuery, $this->iAppId))) - { - addmsg("Error deleting application!", "red"); - } + $bSuccess = false; if(!$bSilent) + { $this->SendNotificationMail("delete"); + if(!$bSuccess) + addmsg("Error deleting application", "red"); + } + return $bSuccess; } @@ -1019,6 +986,60 @@ class Application { 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) { /* Keep track of how many children we have moved */ diff --git a/include/comment.php b/include/comment.php index aa473c3..cd3d896 100644 --- a/include/comment.php +++ b/include/comment.php @@ -27,9 +27,12 @@ class Comment { * Constructor. * 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 FROM appComments, appVersion @@ -37,6 +40,10 @@ class Comment { AND commentId = '?'"; $hResult = query_parameters($sQuery, $iCommentId); $oRow = query_fetch_object($hResult); + } + + if($oRow) + { $this->iCommentId = $oRow->commentId; $this->iParentId = $oRow->parentId; $this->iAppId = $oRow->appId; diff --git a/include/distribution.php b/include/distribution.php index ab0d25d..e1b22ab 100644 --- a/include/distribution.php +++ b/include/distribution.php @@ -19,6 +19,7 @@ class distribution { // constructor, fetches the data. function distribution($iDistributionId = null, $oRow = null) { + $this->aTestingIds = array(); // we are working on an existing distribution. if(!$iDistributionId && !$oRow) return; @@ -156,14 +157,12 @@ class distribution { if(sizeof($this->aTestingIds) && !$_SESSION['current']->hasPriv("admin")) return FALSE; - // delete any test results this distribution has - if($this->aTestingIds) + $bSuccess = TRUE; + + foreach($this->objectGetChildren() as $oChild) { - foreach($this->aTestingIds as $iTestId) - { - $oTestData = new TestData($iTestId); - $oTestData->delete(); - } + if(!$oChild->delete()) + $bSuccess = FALSE; } // now delete the Distribution @@ -171,17 +170,19 @@ class distribution { WHERE distributionId = '?' LIMIT 1"; if(!($hResult = query_parameters($sQuery, $this->iDistributionId))) - { - addmsg("Error removing the Distribution!", "red"); - return false; - } + $bSuccess = FALSE; if(!$bSilent) + { $this->SendNotificationMail("delete"); + if(!$bSuccess) + addmsg("Error deleting distribution", "delete"); + } + $this->mailSubmitter("delete"); - return true; + return $bSuccess; } @@ -226,6 +227,31 @@ class distribution { 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() { // is the current user allowed to requeue this data @@ -282,7 +308,7 @@ class distribution { break; } $sMsg .= "We appreciate your help in making the Application Database better for all users."; - + mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg); } } diff --git a/include/version.php b/include/version.php index 681e64a..d97a9c9 100644 --- a/include/version.php +++ b/include/version.php @@ -220,134 +220,12 @@ class version { if(!$_SESSION['current']->canDeleteVersion($this)) return false; - /* fetch notesIds */ - $aNotesIds = array(); - $sQuery = "SELECT noteId - FROM appNotes - WHERE versionId = '?'"; - if($hResult = query_parameters($sQuery, $this->iVersionId)) + $bSuccess = TRUE; + + foreach($this->objectGetChildren() as $oChild) { - while($oRow = query_fetch_object($hResult)) - { - $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"); + if(!$oChild->delete()) + $bSuccess = FALSE; } /* now delete the version */ @@ -355,16 +233,18 @@ class version { WHERE versionId = '?' LIMIT 1", $this->iVersionId); if(!$hResult) - { - addmsg("Error removing the deleted version!", "red"); - } - - if(!$bSilent) - $this->SendNotificationMail("delete"); + $bSuccess = FALSE; $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.

\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) { /* Keep track of how many items we have updated */