From d9bf5bc5282d3c5882b509e723700c109bf268be Mon Sep 17 00:00:00 2001 From: Jonathan Ernst Date: Fri, 11 Feb 2005 01:34:16 +0000 Subject: [PATCH] Improved version and applicaton class, deletes all linked elements --- TODO | 2 -- include/application.php | 26 +++++++++++++++++++++++++- include/version.php | 18 ++++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index 9b2047b..d29092c 100644 --- a/TODO +++ b/TODO @@ -8,8 +8,6 @@ WineHQ Application Database TODO List # check for existing email when user is creating a new account -# when deleting an application or version we should delete linked entries (screenshots, comments, etc.) - # add a system that will allow users to monitor an app without becoming a maintainer. # add wineversion, distro, source/package fields to the user_list table. diff --git a/include/application.php b/include/application.php index c6fdfa2..a7e89a3 100644 --- a/include/application.php +++ b/include/application.php @@ -5,6 +5,7 @@ require_once(BASE."include/version.php"); require_once(BASE."include/vendor.php"); +require_once(BASE."include/url.php"); /** * Application class for handling applications. @@ -22,6 +23,7 @@ class Application { var $sSubmitTime; var $iSubmitterId; var $aVersionsIds; // an array that contains the versionId of every version linked to this app. + var $aUrlsIds; // an array that contains the screenshotId of every url linked to this version /** * constructor, fetches the data. @@ -37,7 +39,7 @@ class Application { $sQuery = "SELECT appFamily.*, appVersion.versionId AS versionId FROM appFamily, appVersion WHERE appFamily.appId = appVersion.appId - AND appFamily.appId = ".$iAppId; + AND appFamily.appId = ".$iAppId." ORDER BY versionName"; if($hResult = query_appdb($sQuery)) { $this->aVersionsIds = array(); @@ -85,6 +87,23 @@ class Application { $this->bQueued = $oRow->queued; } } + + /* + * We fetch urlsIds. + */ + $this->aUrlsIds = array(); + $sQuery = "SELECT id + FROM appData + WHERE type = 'url' + AND appId = ".$iAppId; + + if($hResult = query_appdb($sQuery)) + { + while($oRow = mysql_fetch_object($hResult)) + { + $this->aUrlsIds[] = $oRow->id; + } + } } } @@ -211,6 +230,11 @@ class Application { $oVersion = new Version($iVersionId); $oVersion->delete($bSilent); } + foreach($this->aUrlsIds as $iUrlId) + { + $oUrl = new Url($iUrlId); + $oUrl->delete($bSilent); + } } if(!$bSilent) $this->mailSupermaintainers(true); diff --git a/include/version.php b/include/version.php index 57f0b2a..5d89561 100644 --- a/include/version.php +++ b/include/version.php @@ -5,6 +5,7 @@ require_once(BASE."include/note.php"); require_once(BASE."include/comment.php"); +require_once(BASE."include/url.php"); /** * Version class for handling versions. @@ -77,6 +78,7 @@ class Version { /* * We fetch commentsIds. */ + $this->aCommentsIds = array(); $sQuery = "SELECT commentId FROM appComments WHERE versionId = ".$iVersionId; @@ -193,7 +195,7 @@ class Version { if ($iAppId && $iAppId!=$this->iAppId) { $sUpdate = compile_update_string(array('appId' => $iAppId)); - if (!query_appdb("UPDATE appVersion SET ".$sUpdate." WHERE appId = ".$this->iAppId)) + if (!query_appdb("UPDATE appVersion SET ".$sUpdate." WHERE versionId = ".$this->iVersionId)) return false; $oAppBefore = new Application($this->iAppId); $oAppAfter = new Application($iAppId); @@ -217,25 +219,25 @@ class Version { LIMIT 1"; if($hResult = query_appdb($sQuery)) { - foreach($aNotesIds as $iNoteId) + foreach($this->aNotesIds as $iNoteId) { $oNote = new Note($iNoteId); $oNote->delete($bSilent); } - foreach($aCommentsIds as $iCommentId) + foreach($this->aCommentsIds as $iCommentId) { - $oComment = new Note($iCommentId); + $oComment = new Comment($iCommentId); $oComment->delete($bSilent); } - foreach($aScreenshotsIds as $iScreenshotId) + foreach($this->aScreenshotsIds as $iScreenshotId) { $oScreenshot = new Screenshot($iScreenshotId); $oScreenshot->delete($bSilent); } - foreach($aUrlsIds as $iUrlId) + foreach($this->aUrlsIds as $iUrlId) { - #FIXME: NOT IMPLEMENTED $oUrl = new Note($iUrlId); - #FIXME: NOT IMPLEMENTED $oUrl->delete($bSilent); + $oUrl = new Url($iUrlId); + $oUrl->delete($bSilent); } } if(!$bSilent)