From 6ae3aa98fd2ecaf029ecf837b85209cbb374338c Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Thu, 30 Jun 2005 01:59:32 +0000 Subject: [PATCH] When deleting a version or application the first thing deleted was the version or application. Then each of the sub-objects like comments, notes etc were deleted. This order is bad because it makes the database inconsistent, we never want a comment/note/etc for a version that doesn't exist. Delete the sub objects first and then the parent object. --- include/application.php | 39 +++++++++++++------------ include/version.php | 63 ++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/include/application.php b/include/application.php index 36c68c8..19770d3 100644 --- a/include/application.php +++ b/include/application.php @@ -222,29 +222,32 @@ class Application { */ function delete($bSilent=false) { + foreach($this->aVersionsIds as $iVersionId) + { + $oVersion = new Version($iVersionId); + $oVersion->delete($bSilent); + } + foreach($this->aUrlsIds as $iUrlId) + { + $oUrl = new Url($iUrlId); + $oUrl->delete($bSilent); + } + + // remove any supermaintainers for this application so we don't orphan them + $sQuery = "DELETE from appMaintainers WHERE appId='".$this->iAppId."';"; + if(!($hResult = query_appdb($sQuery))) + { + addmsg("Error removing app maintainers for the deleted application!", "red"); + } + $sQuery = "DELETE FROM appFamily WHERE appId = ".$this->iAppId." LIMIT 1"; - if($hResult = query_appdb($sQuery)) + if(!($hResult = query_appdb($sQuery))) { - foreach($this->aVersionsIds as $iVersionId) - { - $oVersion = new Version($iVersionId); - $oVersion->delete($bSilent); - } - foreach($this->aUrlsIds as $iUrlId) - { - $oUrl = new Url($iUrlId); - $oUrl->delete($bSilent); - } - - // remove any supermaintainers for this application so we don't orphan them - $sQuery = "DELETE from appMaintainers WHERE appId='".$this->iAppId."';"; - if(!($hResult = query_appdb($sQuery))) - { - addmsg("Error removing app maintainers for the deleted application!", "red"); - } + addmsg("Error deleting application!", "red"); } + if(!$bSilent) $this->mailSupermaintainers("delete"); } diff --git a/include/version.php b/include/version.php index 05bebb2..2aa552f 100644 --- a/include/version.php +++ b/include/version.php @@ -230,39 +230,44 @@ class Version { */ function delete($bSilent=false) { + /* remove all of the items this version contains */ + foreach($this->aNotesIds as $iNoteId) + { + $oNote = new Note($iNoteId); + $oNote->delete($bSilent); + } + foreach($this->aCommentsIds as $iCommentId) + { + $oComment = new Comment($iCommentId); + $oComment->delete($bSilent); + } + foreach($this->aScreenshotsIds as $iScreenshotId) + { + $oScreenshot = new Screenshot($iScreenshotId); + $oScreenshot->delete($bSilent); + } + foreach($this->aUrlsIds as $iUrlId) + { + $oUrl = new Url($iUrlId); + $oUrl->delete($bSilent); + } + + // remove any maintainers for this version so we don't orphan them + $sQuery = "DELETE from appMaintainers WHERE versionId='".$this->iVersionId."';"; + if(!($hResult = query_appdb($sQuery))) + { + addmsg("Error removing version maintainers for the deleted version!", "red"); + } + + /* now delete the version */ $sQuery = "DELETE FROM appVersion WHERE versionId = ".$this->iVersionId." LIMIT 1"; - if($hResult = query_appdb($sQuery)) + if(!($hResult = query_appdb($sQuery))) { - foreach($this->aNotesIds as $iNoteId) - { - $oNote = new Note($iNoteId); - $oNote->delete($bSilent); - } - foreach($this->aCommentsIds as $iCommentId) - { - $oComment = new Comment($iCommentId); - $oComment->delete($bSilent); - } - foreach($this->aScreenshotsIds as $iScreenshotId) - { - $oScreenshot = new Screenshot($iScreenshotId); - $oScreenshot->delete($bSilent); - } - foreach($this->aUrlsIds as $iUrlId) - { - $oUrl = new Url($iUrlId); - $oUrl->delete($bSilent); - } - - // remove any maintainers for this version so we don't orphan them - $sQuery = "DELETE from appMaintainers WHERE versionId='".$this->iVersionId."';"; - if(!($hResult = query_appdb($sQuery))) - { - addmsg("Error removing version maintainers for the deleted version!", "red"); - } + addmsg("Error removing the deleted version!", "red"); } + if(!$bSilent) $this->mailMaintainers("delete"); @@ -348,7 +353,7 @@ class Version { addmsg("Version modified.", "green"); break; case "delete": - $sSubject = "Version '".$this->sName." of ".$oApp->sName."' has been deleted by ".$_SESSION['current']->sRealname; + $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' has been deleted by ".$_SESSION['current']->sRealname; /* if replyText is set we should report the reason the application was deleted */ if($_REQUEST['replyText'])