From 2827e0654e43ebec2b1f3fa2e972f0f6795a92b8 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Fri, 14 Sep 2007 23:02:12 -0400 Subject: [PATCH] =?UTF-8?q?Alexander=20Nicolaysen=20S=C3=B8rnes=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let objectManager handle deletion and delete notification. --- admin/adminMaintainers.php | 15 +- include/application.php | 68 ++++---- include/application_queue.php | 20 +++ include/browse_newest_apps.php | 24 +++ include/bugs.php | 34 ++-- include/comment.php | 147 +++++++++++------ include/distribution.php | 54 ++++-- include/downloadurl.php | 16 ++ include/maintainer.php | 71 ++++++++ include/monitor.php | 65 +++++++- include/note.php | 25 ++- include/objectManager.php | 291 ++++++++++++++++++++++++++++++++- include/screenshot.php | 67 +++++++- include/testData.php | 84 +++++++--- include/testData_queue.php | 20 +++ include/url.php | 39 +++-- include/vendor.php | 30 +++- include/version.php | 64 +++++--- include/version_queue.php | 20 +++ objectManager.php | 12 +- unit_test/test_om_objects.php | 4 + 21 files changed, 958 insertions(+), 212 deletions(-) diff --git a/admin/adminMaintainers.php b/admin/adminMaintainers.php index 041a888..4c32c59 100644 --- a/admin/adminMaintainers.php +++ b/admin/adminMaintainers.php @@ -18,19 +18,6 @@ echo '
Maintainer was successfully deleted

\n"; - } - echo html_frame_end(" "); - echo html_back_link(1,'adminMaintainers.php'); - } } else { // get available maintainers @@ -115,7 +102,7 @@ if (isset($aClean['sSub'])) $oVersion = new version($oRow->versionId); echo " ".$oVersion->objectMakeLink()."\n"; } - echo " [delete]\n"; + echo " [delete]\n"; echo "\n\n"; $c++; } diff --git a/include/application.php b/include/application.php index 0a09cc1..cae6d52 100644 --- a/include/application.php +++ b/include/application.php @@ -236,7 +236,7 @@ class Application { * Deletes the application from the database. * and request the deletion of linked elements. */ - function delete($bSilent=false) + function delete() { $bSuccess = true; @@ -257,14 +257,6 @@ class Application { if(!($hResult = query_parameters($sQuery, $this->iAppId))) $bSuccess = false; - if(!$bSilent) - { - $this->SendNotificationMail("delete"); - - if(!$bSuccess) - addmsg("Error deleting application", "red"); - } - return $bSuccess; } @@ -342,6 +334,43 @@ class Application { } } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + $sSubject = "Submitted application deleted"; + $sMsg = "The application you submitted (".$this->sName. + ") has been deleted."; + break; + } + $aMailTo = null; + } else + { + switch($sAction) + { + case "delete": + $sSubject = $this->sName." deleted"; + $sMsg = "The application '".$this->sName."' has been deleted."; + break; + } + $aMailTo = User::get_notify_email_address_list($this->iAppId); + } + return array($sSubject, $sMsg, $aMailTo); + } + function mailSubmitter($sAction="add") { global $aClean; @@ -368,11 +397,6 @@ class Application { "Edit+Application\n"; $sMsg .= "Reason given:\n"; break; - case "delete": - $sSubject = "Submitted application deleted"; - $sMsg = "The application you submitted (".$this->sName.") has been deleted by ".$_SESSION['current']->sRealname."."; - $sMsg .= "Reason given:\n"; - break; } $sMsg .= $aClean['sReplyText']."\n"; @@ -455,18 +479,6 @@ class Application { $sMsg .= $this->objectMakeUrl()."\n"; addmsg("Application modified.", "green"); break; - case "delete": - $sSubject = $this->sName." has been deleted by ".$_SESSION['current']->sRealname; - - // if sReplyText is set we should report the reason the application was deleted - if($aClean['sReplyText']) - { - $sMsg .= "Reason given:\n"; - $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any - } - - addmsg("Application deleted.", "green"); - break; case "reject": $sSubject = $this->sName." has been rejected by ".$_SESSION['current']->sRealname; $sMsg .= APPDB_ROOT."objectManager.php?sClass=application_queue". @@ -698,8 +710,8 @@ class Application { } if($_SESSION['current']->hasPriv("admin")) { - $url = BASE."admin/deleteAny.php?sWhat=appFamily&iAppId=".$this->iAppId."&sConfirmed=yes"; - echo "
"; + $url = BASE."objectManager.php?sClass=application&bIsQueue=false&sAction=delete&sTitle=Delete%20".$this->sName."&iId=".$this->iAppId; + echo "
"; echo '
'; } } else diff --git a/include/application_queue.php b/include/application_queue.php index b99dbd2..95e0529 100644 --- a/include/application_queue.php +++ b/include/application_queue.php @@ -132,6 +132,26 @@ class application_queue return $bSuccess; } + function objectGetChildren() + { + return $this->oApp->objectGetChildren(); + } + + function objectGetSubmitterId() + { + return $this->oApp->objectGetSubmitterId(); + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oApp->objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oApp->objectGetMail($sAction, $bMailSubmitter, $bParentAction); + } + function outputEditor() { /* We ask the user for the application name first so as to avoid duplicate diff --git a/include/browse_newest_apps.php b/include/browse_newest_apps.php index 65ea853..b7b5ba8 100644 --- a/include/browse_newest_apps.php +++ b/include/browse_newest_apps.php @@ -98,6 +98,30 @@ class browse_newest_apps return array($aItemsPerPage, $iDefaultPerPage); } + function objectGetChildren() + { + $oApp = new application($this->iAppId); + return $oApp->objectGetChildren(); + } + + function objectGetSubmitterId() + { + $oApp = new application($this->iAppId); + return $oApp->objectGetSubmitterId(); + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + $oApp = new application($this->iAppId); + return $oApp->objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $oApp = new application($this->iAppId); + return $oApp->objectGetMail($sAction, $bMailSubmitter, $bParentAction); + } + function objectGetId() { return $this->iAppId; diff --git a/include/bugs.php b/include/bugs.php index ea05791..81ec1db 100644 --- a/include/bugs.php +++ b/include/bugs.php @@ -151,24 +151,12 @@ class Bug * * Return true if successful, false if an error occurs */ - function delete($bSilent=false) + function delete() { $sQuery = "DELETE FROM buglinks WHERE linkId = '?'"; - if($hResult = query_parameters($sQuery, $this->iLinkId)) - { - if(!$bSilent) - $this->SendNotificationMail(true); - } else - { - return false; - } - - if($this->iSubmitterId && - ($this->iSubmitterId != $_SESSION['current']->iUserId)) - { - $this->mailSubmitter(true); - } + if(!($hResult = query_parameters($sQuery, $this->iLinkId))) + return false; return true; } @@ -269,6 +257,22 @@ class Bug } } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + /* We don't do this at the moment */ + return array(null, null, null); + } + function objectGetChildren() { return array(); diff --git a/include/comment.php b/include/comment.php index cd3d896..bc6dec3 100644 --- a/include/comment.php +++ b/include/comment.php @@ -163,13 +163,18 @@ class Comment { return true; } + function getOutputEditorValues($aClean) + { + /* Stub */ + } + /** * Removes the current comment from the database. * Informs interested people about the deletion. * Returns true on success and false on failure. */ - function delete($bSilent = false) + function delete() { $hResult = query_parameters("DELETE FROM appComments WHERE commentId = '?'", $this->iCommentId); if ($hResult) @@ -178,57 +183,11 @@ class Comment { $hResult = query_parameters("UPDATE appComments set parentId = '?' WHERE parentId = '?'", $this->iParentId, $this->iCommentId); - if(!$bSilent) - { - $this->SendNotificationMail("delete"); - } - return true; } else { - addmsg("Error removing the deleted comment!", "red"); + return false; } - - return false; - } - - function SendNotificationMail($sAction="add", $sMsg = null) - { - global $aClean; - - // use 'sReplyText' if it is defined, otherwise define the value as an empty string - if(!isset($aClean['sReplyText'])) - $aClean['sReplyText'] = ""; - - $oApp = new Application($this->iAppId); - switch($sAction) - { - case "delete": - $sSubject = "Comment for '".version::fullName($this->iVersionId)."' deleted by ".$_SESSION['current']->sRealname; - $oVersion = new version($this->iVersionId); - $sMsg = $oVersion->objectMakeUrl()."\n"; - $sMsg .= "\n"; - $sMsg .= "This comment was made on ".substr($this->sDateCreated,0,10)." by ".$this->oOwner->sRealname."\n"; - $sMsg .= "\n"; - $sMsg .= "Subject: ".$this->sSubject."\r\n"; - $sMsg .= "\n"; - $sMsg .= $this->sBody."\r\n"; - $sMsg .= "\n"; - $sMsg .= "Because:\n"; - if($sReason) - $sMsg .= $sReason."\n"; - else - $sMsg .= "No reason given.\n"; - - addmsg("Comment deleted.", "green"); - - break; - } - - $sEmail = User::get_notify_email_address_list($this->iAppId, $this->iVersionId); - $sEmail .= $this->oOwner->sEmail; - if($sEmail) - mail_appdb($sEmail, $sSubject, $sMsg); } function get_comment_count_for_versionid($iVersionId) @@ -280,9 +239,15 @@ class Comment { || $_SESSION['current']->isMaintainer($oRow->versionId) || $_SESSION['current']->isSuperMaintainer($oRow->appId)) { + $oVersion = new version($oRow->versionId); echo ""; - echo "
\n"; - echo "commentId\" />"; + echo "\n"; + echo "commentId\" />"; + echo ""; + echo ""; + echo ""; + echo ""; + echo "objectMakeUrl()."\" />"; echo "
\n"; echo ""; } @@ -381,11 +346,91 @@ class Comment { echo "\n"; } } - + if (!$is_main) echo "\n"; } + function canEdit() + { + return $_SESSION['current']->hasPriv("admin"); + } + + function objectGetId() + { + return $this->iCommentId; + } + + function objectGetSubmitterId() + { + return $this->oOwner->iUserId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + $oOptions = new mailOptions(); + + if($sAction == "delete" && $bParentAction) + $oOptions->bMailOnce = TRUE; + + return $oOptions; + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $sSubject = ""; + $sMessage = ""; + $aRecipients = null; + + $oVersion = new version($this->iVersionId); + $sVerName = version::fullName($this->iVersionId); + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + if($bParentAction) + { + $sSubject = "Comments for $sVerName deleted"; + $sMessage = "Your comments for $sVerName were deleted because the"; + $sMessage .= "version was removed from the database"; + } else + { + $sSubject = "Comment for $sVerName deleted"; + $sMessage = $oVersion->objectMakeUrl()."\n"; + $sMessage .= "\n"; + $sMessage .= "This comment was made on ".substr($this->sDateCreated,0,10)."\n"; + $sMessage .= "\n"; + $sMessage .= "Subject: ".$this->sSubject."\r\n"; + $sMessage .= "\n"; + $sMessage .= $this->sBody."\r\n"; + } + break; + } + } else + { + switch($sAction) + { + case "delete": + if(!$bParentAction) + { + $sSubject = "Comment for $sVerName deleted"; + $sMessage = $oVersion->objectMakeUrl()."\n"; + $sMessage .= "\n"; + $sMessage .= "This comment was made on ".substr($this->sDateCreated,0,10)." by ".$this->oOwner->sRealname."\n"; + $sMessage .= "\n"; + $sMessage .= "Subject: ".$this->sSubject."\r\n"; + $sMessage .= "\n"; + $sMessage .= $this->sBody."\r\n"; + } + break; + } + $aRecipients = User::get_notify_email_address_list($this->iAppId, $this->iVersionId); + } + return array($sSubject, $sMessage, $aRecipients); + } + function objectGetChildren() { return array(); diff --git a/include/distribution.php b/include/distribution.php index 2503781..df89501 100644 --- a/include/distribution.php +++ b/include/distribution.php @@ -141,9 +141,9 @@ class distribution { return false; } } - + // Delete Distributution. - function delete($bSilent=false) + function delete() { /* Is the current user allowed to delete this distribution? We allow everyone to delete a queued, empty distribution, because it should be @@ -172,16 +172,6 @@ class distribution { if(!($hResult = query_parameters($sQuery, $this->iDistributionId))) $bSuccess = FALSE; - if(!$bSilent) - { - $this->SendNotificationMail("delete"); - - if(!$bSuccess) - addmsg("Error deleting distribution", "delete"); - } - - $this->mailSubmitter("delete"); - return $bSuccess; } @@ -283,6 +273,46 @@ class distribution { return false; } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $oSubmitter = new user($this->iSubmitterId); + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + $sSubject = "Submitted distribution deleted"; + $sMsg = "The distribution you submitted (".$this->sName.") has been ". + "deleted.\n"; + break; + } + $aMailTo = null; + } else + { + switch($sAction) + { + case "delete": + $sSubject = "Distribution ".$this->sName." deleted"; + $sMsg = ""; + break; + } + $aMailTo = User::get_notify_email_address_list(null, null); + } + + return array($sSubject, $sMsg, $aMailTo); + } + function mailSubmitter($sAction="add") { global $aClean; diff --git a/include/downloadurl.php b/include/downloadurl.php index b338adc..d44ad0d 100644 --- a/include/downloadurl.php +++ b/include/downloadurl.php @@ -136,6 +136,22 @@ class downloadurl return $sReturn; } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + /* We don't do this at the moment */ + return array(null, null, null); + } + /* Process data from a Download URL form */ function ProcessForm($aValues) { diff --git a/include/maintainer.php b/include/maintainer.php index 5ec6cd0..43d3ced 100644 --- a/include/maintainer.php +++ b/include/maintainer.php @@ -839,6 +839,77 @@ class maintainer return $sReplyTextHelp; } + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $oSubmitter = new user($this->iSubmitterId); + + $sVerb = $this->sQueued == "true" ? "rejected" : "removed"; + + if($this->bSuperMaintainer) + { + $oApp = new application($this->iAppId); + $sFor = $oApp->sName; + } else + { + $sFor = version::fullName($this->iVersionId); + } + + $sMsg = null; + $sSubject = null; + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + $sSubject = "Maintainership for $sFor $sVerb"; + if($this->sQueued == "true") + { + $sMsg = "Your request to be a maintainer of '$sFor'". + " has been denied."; + } else + { + $sMsg = "You have been removed as a maintainer of ". + "'$sFor'."; + } + break; + } + $aMailTo = null; + } else + { + switch($sAction) + { + case "delete": + if(!$bParentAction) + { + $sSubject = "Maintainership for $sFor $sVerb"; + if($this->bQueued == "false") + { + $sMsg = $oSubmitter->sRealName." has been removed as a ". + "maintainer of $sFor."; + } else + { + $sMsg = $oSubmitter->sRealName." request to be a maintainer ". + " of $sFor has been rejected."; + } + } + break; + } + $aMailTo = User::get_notify_email_address_list(null, null); + } + return array($sSubject, $sMsg, $aMailTo); + } + + function objectGetSubmitterId() + { + return $this->iUserId; + } + function objectHideDelete() { return TRUE; diff --git a/include/monitor.php b/include/monitor.php index 85b9c6f..7dc93b8 100644 --- a/include/monitor.php +++ b/include/monitor.php @@ -100,16 +100,75 @@ class Monitor { } } + function objectGetSubmitterId() + { + return $this->iUserId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $sSubject = null; + $sMsg = null; + + if($this->iVersionId) + { + $sWhat = "version"; + $sName = version::fullName($this->iVersionId); + $oVersion = new version($this->iVersionId); + $sUrl = $oVersion->objectMakeUrl(); + } else + { + $sWhat = "application"; + $oApp = new application($this->iAppId); + $sName = $oApp->sName; + $sUrl = $oApp->objectMakeUrl(); + } + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + if($bParentActino) + { + $sSubject = "Monitored $sWhat deleted"; + $sMsg = "The $sWhat $sName which you monitored has been ". + "deleted by ".$_SESSION['current']->iUserId."."; + } + break; + } + $aMailTo = null; + } else + { + $oUser = new user($this->iUserId); + $sUser = $oUser->sName; + switch($sAction) + { + case "delete": + if(!$bParentAction) + { + $sSubject = "Monitor for $sName removed: $sUser"; + $sMsg = $sUrl; + } + break; + } + User::get_notify_email_address_list(null, $this->iVersionId); + } + return array($sSubject, $sMsg, $aMailTo); + } /** * Removes the current Monitor from the database. * Informs interested people about the deletion. */ - function delete($bSilent=false) + function delete() { $hResult = query_parameters("DELETE FROM appMonitors WHERE monitorId = '?'", $this->iMonitorId); - if(!$bSilent) - $this->SendNotificationMail("delete"); if(!$hResult) return FALSE; diff --git a/include/note.php b/include/note.php index ab55882..c8d7246 100644 --- a/include/note.php +++ b/include/note.php @@ -126,13 +126,14 @@ class Note { * * Returns: true if successful, false if not */ - function delete($bSilent=false) + function delete() { $hResult = query_parameters("DELETE FROM appNotes WHERE noteId = '?'", $this->iNoteId); - if(!$bSilent) - $this->SendNotificationMail("delete"); - return true; + if(!$hResult) + return FALSE; + + return TRUE; } @@ -311,6 +312,22 @@ class Note { return $oManager->makeUrl("view", $this->objectGetId()); } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + /* We don't do this at the moment */ + return array(null, null, null); + } + function objectGetChildren() { return array(); diff --git a/include/objectManager.php b/include/objectManager.php index ea2906a..ad3d1a8 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -10,6 +10,7 @@ class ObjectManager var $sTitle; var $iId; var $bIsRejected; + var $sReturnTo; var $oMultiPage; var $oTableRow; @@ -335,20 +336,228 @@ class ObjectManager "ObjectDisplayQueueProcessingHelp")); } - /* Delete the object associated with the given id */ - function delete_entry() + /* Ask whether the user really wants to delete the entry and display a delete reason box */ + function delete_prompt() { $this->checkMethods(array("delete", "canEdit")); $oObject = new $this->sClass($this->iId); + /* Check permissions */ + if(!$oObject->canEdit()) + { + echo "You do not have permission to delete this entry.\n"; + return; + } + + /* Check whether the object exists */ + if(!$oObject->objectGetId()) + { + echo "There is no entry with that id in the database.\n"; + return; + } + + $oTable = new Table(); + $oTableRow = new TableRow(); + $oTable->setAlign("center"); + $oTable->addRow($oTableRow); + $oTableRow->addTextCell( + '
'. + '
'. + '
'. + "Confirm deletion". + "
". + '
'. + "Are you sure you wish to delete this entry?
". + "Please enter a reason why so that you don’t hurt the submitter’s". + " feelings.". + "
". + "
". + + '
'. + $this->makeUrlFormData(). + ''. + '

'. + ''. + "
". + "
"); + echo $oTable->getString(); + } + + function delete_child($sReplyText, $bMailSubmitter, $bMailCommon) + { + $this->checkMethods(array("delete", "canEdit")); + + $oObject = new $this->sClass($this->iId); + $oSubmitterMail = null; + $oCommonMail = null; + if(!$oObject->canEdit()) return FALSE; + if($bMailSubmitter) + $oSubmitterMail = $this->get_mail(TRUE, "delete", TRUE); + + if($bMailCommon) + $oCommonMail = $this->get_mail(FALSE, "delete", TRUE); + if($oObject->delete()) - util_redirect_and_exit($this->makeUrl("view", false)); - else - echo "Failure.\n"; + { + if($oCommonMail || $oSubmitterMail) + { + $sReplyText = "The parent entry was deleted. The reason given for ". + "that deletion was:\n$sReplyText"; + + if($oCommonMail) + $oCommonMail->send("delete", $sReplyText); + + if($oSubmitterMail) + $oSubmitterMail->send("delete", $sReplyText); + } + + return TRUE; + } else + { + return FALSE; + } + } + + /* Delete the object associated with the given id */ + function delete_entry($sReplyText) + { + $this->checkMethods(array("delete", "canEdit")); + + $oObject = new $this->sClass($this->iId); + + if(!$oObject->objectGetId()) + return FALSE; + + if(!$oObject->canEdit()) + return FALSE; + + $oSubmitterMail = $this->get_mail(TRUE, "delete"); + $oCommonMail = $this->get_mail(FALSE, "delete"); + + $iFailed = 0; + $iDeleted = 0; + + /* Delete children first, if there are any */ + if(method_exists($oObject, "objectGetChildren")) + { + $aChildren = $oObject->objectGetChildren(); + + if(!is_array($aChildren)) + { + addmsg("Failed to get child entries, aborting", "red"); + util_redirect_and_exit($this->makeUrl("view", false)); + } + + /* Keep track of whether we should send mails. This is used by the + 'mail once' option */ + $aSendMailSubmitter = array(); + $aSendMailCommon = array(); + + foreach($aChildren as $oChild) + { + if(!is_object($oChild)) + { + addmsg("Failed to get child entries, aborting", "red"); + util_redirect_and_exit($this->makeUrl("view", false)); + } + + $oM = $this->om_from_object($oChild); + + if(!isset($aSendMailSubmitter[$oM->sClass][$oChild->objectGetSubmitterId()])) + $aSendMailSubmitter[$oM->sClass][$oChild->objectGetSubmitterId()] = TRUE; + + if(!isset($aSendMailCommon[$oM->sClass])) + $aSendMailCommon[$oM->sClass] = TRUE; + + if($oM->delete_child($sReplyText, $aSendMailSubmitter[$oM->sClass][$oChild->objectGetSubmitterId()], $aSendMailCommon[$oM->sClass])) + { + $iDeleted++; + + if($oChild->objectGetMailOptions("delete", TRUE, TRUE)->bMailOnce) + $aSendMailSubmitter[$oM->sClass][$oChild->objectGetSubmitterId()] = FALSE; + + if($oChild->objectGetMailOptions("delete", FALSE, TRUE)->bMailOnce) + $aSendMailCommon[$oM->sClass] = FALSE; + } else + { + $iFailed++; + } + } + } + + if($oObject->delete()) + { + $oCommonMail->send("delete", $sReplyText); + + if($oSubmitterMail) + $oSubmitterMail->send("delete", $sReplyText); + + addmsg("Entry deleted", "green"); + + if($iDeleted) + addmsg("Deleted $iDeleted child entries", "green"); + + if($iFailed) + addmsg("Failed to delete $iFailed child entries", "red"); + + $this->return_to_url($this->makeUrl("view", false)); + } else + { + addmsg("Failed to delete entry", "red"); + } + } + + /* Return the user to the url specified in the objectManager object. Fall back to a + given value if the object member is not set */ + function return_to_url($sFallback) + { + $sUrl = $this->sReturnTo; + + if(!$sUrl) + $sUrl = $sFallback; + + util_redirect_and_exit($sUrl); + } + + function om_from_object($oObject) + { + return new objectManager(get_class($oObject), "", $oObject->objectGetId()); + } + + /* Creates a mail object using information from objectGetMail(). If bMailSubmitter + is true then we first check to see whether the submitter is the one deleting the + entry, in which case we don't send him a notification mail. + Thus it returns null if no mail is to be sent, or a Mail object otherwise. + bParentAction states whether the action was caused by a change to the parent + entry, for instance this will be true when deleting a version because we + delete its parent application. */ + function get_mail($bMailSubmitter, $sAction, $bParentAction = FALSE) + { + $oObject = new $this->sClass($this->iId); + + if($bMailSubmitter) + { + $iSubmitterId = $oObject->objectGetSubmitterId(); + + /* Should we mail the submitter? */ + if($iSubmitterId && $iSubmitterId != $_SESSION['current']->iUserId) + { + return new mail($oObject->objectGetMail($sAction, $bMailSubmitter, + $bParentAction), + $iSubmitterId); + } else + { + return null; + } + } else + { + return new mail($oObject->objectGetMail("delete", $bMailSubmitter, + $bParentAction)); + } } /* Move all the object's children to another object of the same type, and @@ -377,7 +586,8 @@ class ObjectManager return FALSE; } - $this->delete_entry(); + /* The argument is the reply text */ + $this->delete_entry("Duplicate entry"); } /* Display a page where the user can select which object the children of the current @@ -542,7 +752,8 @@ class ObjectManager $oObject->getOutputEditorValues($aClean); /* Check input, if necessary */ - if(method_exists(new $this->sClass, "checkOutputEditorInput")) + if($aClean['sSubmit'] != "Delete" && + method_exists(new $this->sClass, "checkOutputEditorInput")) { $sErrors = $oObject->checkOutputEditorInput($aClean); } @@ -589,7 +800,7 @@ class ObjectManager break; case "Delete": - $this->delete_entry(); + $this->delete_entry($aClean['sReplyText']); break; default: @@ -655,6 +866,7 @@ class ObjectManager $sReturn .= "\n"; $sReturn .= "sClass."\" />\n"; $sReturn .= "sTitle."\" />\n"; + $sReturn .= "sReturnTo."\" />\n"; if($this->oMultiPage->bEnabled) { @@ -839,4 +1051,67 @@ class MultiPage } } +class mailOptions +{ + var $bMailOnce; + + function mailOptions() + { + /* Set default options */ + $this->bMailOnce = FALSE; + } +} + +class mail +{ + var $sSubject; + var $sMessage; + var $aRecipients; + + function mail($aInput, $iRecipientId = null) + { + if(!$aInput) + return; + + /* $aInput is returned from objectGetMail(); an array with the following members + 0: Mail subject + 1: Mail text + 2: Array of recipients + If iRecipientId is set the third array member is ignored. */ + $this->sSubject = $aInput[0]; + $this->sMessage = $aInput[1]; + + if($iRecipientId) + { + $oRecipient = new user($iRecipientId); + $this->aRecipients = array($oRecipient->sEmail); + } else + { + $this->aRecipients = $aInput[2]; + } + } + + function send($sAction, $sReplyText) + { + /* We don't send empty mails */ + if(!$this->sSubject && !$this->sMessage) + return; + + $this->sMessage .= "\n"; + + $this->sMessage .= "The action was performed by ".$_SESSION['current']->sRealname."\n"; + + switch($sAction) + { + case "delete": + $this->sMessage .= "Reasons given\n"; + break; + } + + $this->sMessage .= $sReplyText; + + mail_appdb($this->aRecipients, $this->sSubject, $this->sMessage); + } +} + ?> diff --git a/include/screenshot.php b/include/screenshot.php index 36fafce..9f7da6e 100644 --- a/include/screenshot.php +++ b/include/screenshot.php @@ -132,7 +132,7 @@ class screenshot * * Returns: true if deletion was success, false if otherwise */ - function delete($bSilent=false) + function delete() { /* appData has a universal function for removing database entries */ $oAppData = new appData($this->iScreenshotId, null, $this); @@ -150,13 +150,6 @@ class screenshot $sOriginalFilename = appdb_fullpath("/data/screenshots/originals/".$this->iScreenshotId); if(is_file($sOriginalFilename)) unlink($sOriginalFilename); - - if(!$bSilent) - $this->mailMaintainers(true); - } - if($this->iSubmitterId && ($this->iSubmitterId != $_SESSION['current']->iUserId)) - { - $this->mailSubmitter(true); } return true; @@ -321,6 +314,64 @@ class screenshot return $this->oThumbnailImage->get_height(); } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + $oOptions = new mailOptions(); + + if($sAction == "delete" && $bParentAction) + $oOptions->bMailOnce = TRUE; + + return $oOptions; + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $sFor = version::fullName($this->iVersionId); + + $sMsg = null; + $sSubject = null; + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + if($bParentAction) + { + $sSubject = "Submitter screenshots deleted"; + $sMsg = "The screenshots you submitted for $sFor have been ". + "deleted because $sFor was deleted."; + } else + { + $sSubject = "Submitted screenshot deleted"; + $sMsg = "The screenshot with description '".$this->sDescription. + "' that you submitted for $sFor has been deleted."; + } + break; + } + $aMailTo = null; + } else + { + switch($sAction) + { + case "delete": + if(!$bParentAction) + { + $sSubject = "Screenshot for $sFor deleted"; + $sMsg = "The screenshot with description '".$this->sDescription. + "' for $sFor has been deleted."; + } + break; + } + $aMailTo = User::get_notify_email_address_list(null, $this->iVersionId); + } + return array($sSubject, $sMsg, $aMailTo); + } function mailSubmitter($bRejected=false) { diff --git a/include/testData.php b/include/testData.php index 187ec3a..e0dca48 100644 --- a/include/testData.php +++ b/include/testData.php @@ -209,7 +209,7 @@ class testData{ } // Delete test results. - function delete($bSilent=false) + function delete() { // is the current user allowed to delete this test result? $oVersion = new Version($this->iVersionId); @@ -230,12 +230,6 @@ class testData{ return false; } - if(!$bSilent) - $this->SendNotificationMail("delete"); - - if($this->iSubmitterId && ($this->iSubmitterId != $_SESSION['current']->iUserId)) - $this->mailSubmitter("delete"); - return true; } @@ -314,6 +308,60 @@ class testData{ } } + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + $oOptions = new mailOptions(); + + if($sAction == "delete" && $bParentAction) + $oOptions->bMailOnce = TRUE; + + return $oOptions; + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $oSubmitter = new User($this->iSubmitterId); + $sName = version::fullName($this->iVersionId); + + $sMsg = null; + $sSubject = null; + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + $sSubject = "Submitted test data deleted"; + if($bParentAction) + { + $sMsg = "All test data you submitted for '$sName' has ". + "been deleted because '$sName' was deleted."; + } else + { + $sMsg = "The test report you submitted for '$sName' has ". + "been deleted."; + } + break; + } + $aMailTo = nulL; + } else + { + switch($sAction) + { + case "delete": + if(!$bParentAction) + { + $sSubject = "Test Results deleted for $sName by ". + $_SESSION['current']->sRealname; + $sMsg = ""; + } + break; + } + $aMailTo = User::get_notify_email_address_list(null, $this->iVersionId); + } + return array($sSubject, $sMsg, $aMailTo); + } + function mailSubmitter($sAction="add") { global $aClean; @@ -343,12 +391,6 @@ class testData{ $sMsg .= $this->objectMakeUrl()."\n"; $sMsg .= "Reason given:\n"; break; - case "delete": - $sSubject = "Submitted testing data deleted"; - $sMsg = "The testing data you submitted for '$sName' has ". - "been deleted by ".$_SESSION['current']->sRealname."."; - $sMsg .= "Reason given:\n"; - break; } $sMsg .= $aClean['sReplyText']."\n"; $sMsg .= "We appreciate your help in making the Application ". @@ -400,17 +442,6 @@ class testData{ $sMsg .= $sBacklink; addmsg("test data modified.", "green"); break; - case "delete": - $sSubject = "Test Results deleted for version ".$oVersion->sName." of ".$oApp->sName." by ".$_SESSION['current']->sRealname; - // if replyText is set we should report the reason the data was deleted - if($aClean['sReplyText']) - { - $sMsg .= "Reason given:\n"; - $sMsg .= $aClean['sReplyText']."\n"; // append the reply text, if there is any - } - - addmsg("test data deleted.", "green"); - break; case "reject": $sSubject = "Test Results rejected for version ".$oVersion->sName." of ".$oApp->sName." by ".$_SESSION['current']->sRealname; $sMsg .= $sBacklink; @@ -1140,6 +1171,11 @@ class testData{ { return $this->iTestingId; } + + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } } ?> diff --git a/include/testData_queue.php b/include/testData_queue.php index c3729dd..f6c7d02 100644 --- a/include/testData_queue.php +++ b/include/testData_queue.php @@ -177,6 +177,26 @@ class testData_queue { return $this->oTestData->objectGetId(); } + + function objectGetSubmitterId() + { + return $this->oTestData->objectGetSubmitterId(); + } + + function objectGetChildren() + { + return $this->oTestData->objectGetChildren(); + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oTestData->objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oTestData->objectGetMail($sAction, $bMailSubmitter, $bParentAction); + } } ?> diff --git a/include/url.php b/include/url.php index c23d880..72c814d 100644 --- a/include/url.php +++ b/include/url.php @@ -91,7 +91,7 @@ class Url { * Deletes the url from the database. * and request its deletion from the filesystem (including the thumbnail). */ - function delete($bSilent=false) + function delete() { $sQuery = "DELETE FROM appData WHERE id = '?' @@ -100,15 +100,6 @@ class Url { if(!$hResult = query_parameters($sQuery, $this->iUrlId)) return false; - if(!$bSilent) - $this->SendNotificationMail(true); - - if($this->iSubmitterId && - $this->iSubmitterId != $_SESSION['current']->iUserId) - { - $this->mailSubmitter(true); - } - return true; } @@ -255,11 +246,6 @@ class Url { addmsg("The url you submitted will be added to the database ". "database after being reviewed.", "green"); } - } else // Url deleted. - { - $sSubject = "Url for $sAppName deleted by ".$_SESSION['current']->sRealname; - $sMsg = "$sUrl\n"; - addmsg("Url deleted.", "green"); } $sEmail = User::get_notify_email_address_list(null, $this->iVersionId); @@ -456,7 +442,7 @@ class Url { return TRUE; } - function canEdit($iVersionId, $iAppId = NULL) + function canEdit($iVersionId = NULL, $iAppId = NULL) { if($_SESSION['current']->hasPriv("admin")) return TRUE; @@ -499,6 +485,27 @@ class Url { return $sReturn; } + function objectGetId() + { + return $this->iUrlId; + } + + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + /* We don't do this at the moment */ + return array(null, null, null); + } + function objectGetChildren() { return array(); diff --git a/include/vendor.php b/include/vendor.php index eb847e7..9de276a 100644 --- a/include/vendor.php +++ b/include/vendor.php @@ -149,19 +149,18 @@ class Vendor { /** * Deletes the vendor from the database. */ - function delete($bSilent=false) + function delete() { if(sizeof($this->aApplicationsIds)>0) { - addmsg("The vendor has not been deleted because there are still applications linked to it.", "red"); - } else + return FALSE; + } else { $sQuery = "DELETE FROM vendor WHERE vendorId = '?' LIMIT 1"; if(query_parameters($sQuery, $this->iVendorId)) { - addmsg("The vendor has been deleted.", "green"); return TRUE; } @@ -292,6 +291,29 @@ class Vendor { return TRUE; } + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetChildren() + { + /* We don't have any */ + return array(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + /* We don't send notification mails */ + return array(null, null, null); + } + + function objectGetSubmitterId() + { + /* We don't record the submitter id */ + return NULL; + } + function getOutputEditorValues($aClean) { $this->sName = $aClean['sVendorName']; diff --git a/include/version.php b/include/version.php index aaafc4c..3488c43 100644 --- a/include/version.php +++ b/include/version.php @@ -231,7 +231,7 @@ class version { * Deletes the version from the database. * and request the deletion of linked elements. */ - function delete($bSilent=false) + function delete() { /* We need the versionId to continue */ if(!$this->iVersionId) @@ -256,19 +256,9 @@ class version { if(!$hResult) $bSuccess = FALSE; - $this->mailSubmitter("delete"); - - if(!$bSilent) - { - if(!$bSuccess) - addmsg("Error removing version", "red"); - - $this->SendNotificationMail("delete"); - } return $bSuccess; } - /** * Move version out of the queue. */ @@ -344,6 +334,46 @@ class version { } } + function objectGetSubmitterId() + { + return $this->iSubmitterId; + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return new mailOptions(); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + $oApp = new application($this->iAppId); + + if($bMailSubmitter) + { + switch($sAction) + { + case "delete": + $sSubject = "Submitted version deleted"; + $sMsg = "The version you submitted (".$oApp->sName." ".$this->sName. + ") has been deleted."; + break; + } + $aMailTo = null; + } else + { + switch($sAction) + { + case "delete": + $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' ". + "deleted"; + $sMsg = ""; + break; + } + $aMailTo = User::get_notify_email_address_list(null, $this->iVersionId); + } + return array($sSubject, $sMsg, $aMailTo); + } + function mailSubmitter($sAction="add") { global $aClean; //FIXME: we should pass the sReplyText value in @@ -372,11 +402,6 @@ class version { "&bIsQueue=true&bIsRejected=true&iId=".$this->iVersionId."&". "sTitle=Edit+Version\n"; break; - case "delete": - $sSubject = "Submitted version deleted"; - $sMsg = "The version you submitted (".$oApp->sName." ".$this->sName.") has been deleted by ".$_SESSION['current']->sRealname."."; - $sMsg .= "Reason given:\n"; - break; } $sMsg .= $aClean['sReplyText']."\n"; $sMsg .= "We appreciate your help in making the Version Database better for all users."; @@ -428,7 +453,6 @@ class version { addmsg("Version modified.", "green"); break; case "delete": - $sSubject = "Version '".$this->sName."' of '".$oApp->sName."' has been deleted by ".$_SESSION['current']->sRealname; // if sReplyText is set we should report the reason the application was deleted if($aClean['sReplyText']) @@ -851,8 +875,8 @@ class version { echo "\t".''."\n"; echo "\t".''."\n"; echo ''."\n"; - $url = BASE."admin/deleteAny.php?sWhat=appVersion&iAppId=".$oApp->iAppId."&iVersionId=".$this->iVersionId."&sConfirmed=yes"; - echo "
\n"; + $url = BASE."objectManager.php?sClass=version&sAction=delete&bQueued=false&sTitle=Delete%20".version::fullName($this->iVersionId)."&iId=".$this->iVersionId; + echo "\n"; echo "\t".''."\n"; echo '
'."\n"; echo '
'."\n"; @@ -975,7 +999,7 @@ class version { $oNote = new Note($oRow->noteId); $oNote->display(); } - + // Comments Section Comment::view_app_comments($this->iVersionId); } diff --git a/include/version_queue.php b/include/version_queue.php index 6f625e1..03fa3f1 100644 --- a/include/version_queue.php +++ b/include/version_queue.php @@ -97,6 +97,26 @@ class version_queue $this->oDownloadUrl->unQueue(); } + function objectGetSubmitterId() + { + return $this->oVersion->objectGetSubmitterId(); + } + + function objectGetChildren() + { + return $this->oVersion->objectGetChildren(); + } + + function objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oVersion->objectGetMailOptions($sAction, $bMailSubmitter, $bParentAction); + } + + function objectGetMail($sAction, $bMailSubmitter, $bParentAction) + { + return $this->oVersion->objectGetMail($sAction, $bMailSubmitter, $bParentAction); + } + function outputEditor() { global $aClean; diff --git a/objectManager.php b/objectManager.php index 2d9d48d..1bfc96e 100644 --- a/objectManager.php +++ b/objectManager.php @@ -48,6 +48,9 @@ if(isset($aClean['bIsQueue']) && $aClean['bIsQueue'] == 'true') else $oObject->bIsQueue = false; +if(isset($aClean['sReturnTo'])) + $oObject->sReturnTo = $aClean['sReturnTo']; + $aClean['bIsRejected'] = isset($aClean['bIsRejected']) ? $aClean['bIsRejected'] : false; /* If it is rejected it is defined as queued */ if($aClean['bIsRejected'] == 'true') @@ -68,11 +71,6 @@ $oOtherObject = new $oObject->sClass($oObject->iId); on failure */ $sErrors = $oObject->processForm($aClean); -if($oObject->iId && $aClean['sAction'] == "delete") -{ - $oObject->delete_entry(); -} - if(isset($aClean['sAction']) && $aClean['sAction'] == "add") $oObject->handle_anonymous_submission(); @@ -100,6 +98,10 @@ if($oObject->iId) $oObject->display_move_children(); break; + case "delete": + $oObject->delete_prompt(); + break; + default: $oObject->view($_SERVER['REQUEST_URI']); break; diff --git a/unit_test/test_om_objects.php b/unit_test/test_om_objects.php index e4d7e9b..d8a7fc4 100644 --- a/unit_test/test_om_objects.php +++ b/unit_test/test_om_objects.php @@ -260,9 +260,13 @@ function test_object_methods() "canEdit", "display", "getOutputEditorValues", + "objectGetChildren", "objectGetEntries", "objectGetHeader", "objectGetId", + "objectGetMail", + "objectGetMailOptions", + "objectGetSubmitterId", "objectGetTableRow", "objectMakeLink", "objectMakeUrl",