From 9dee67618d5e5cdb0a09b4983fdc8b5b5d9fb19f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 25 Sep 2014 13:42:38 -0700 Subject: [PATCH] Allow pastes to be destroyed Summary: Fixes T6186. Test Plan: - Used `bin/remove destroy Pxxx` to destroy a paste. - Verified file, transactions, etc., were destroyed. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6186 Differential Revision: https://secure.phabricator.com/D10563 --- src/__phutil_library_map__.php | 2 + .../paste/storage/PhabricatorPaste.php | 40 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ff0d0bb903..9b5f3ad6ef 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4855,6 +4855,8 @@ phutil_register_library_map(array( 'PhabricatorMentionableInterface', 'PhabricatorPolicyInterface', 'PhabricatorProjectInterface', + 'PhabricatorDestructibleInterface', + 'PhabricatorApplicationTransactionInterface', ), 'PhabricatorPasteApplication' => 'PhabricatorApplication', 'PhabricatorPasteCommentController' => 'PhabricatorPasteController', diff --git a/src/applications/paste/storage/PhabricatorPaste.php b/src/applications/paste/storage/PhabricatorPaste.php index 0b725c7a90..9191f316a2 100644 --- a/src/applications/paste/storage/PhabricatorPaste.php +++ b/src/applications/paste/storage/PhabricatorPaste.php @@ -7,7 +7,9 @@ final class PhabricatorPaste extends PhabricatorPasteDAO PhabricatorFlaggableInterface, PhabricatorMentionableInterface, PhabricatorPolicyInterface, - PhabricatorProjectInterface { + PhabricatorProjectInterface, + PhabricatorDestructibleInterface, + PhabricatorApplicationTransactionInterface { protected $title; protected $authorPHID; @@ -152,4 +154,40 @@ final class PhabricatorPaste extends PhabricatorPasteDAO return pht('The author of a paste can always view and edit it.'); } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + if ($this->filePHID) { + $file = id(new PhabricatorFileQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withPHIDs(array($this->filePHID)) + ->executeOne(); + if ($file) { + $engine->destroyObject($file); + } + } + + $this->delete(); + } + + +/* -( PhabricatorApplicationTransactionInterface )------------------------- */ + + + public function getApplicationTransactionEditor() { + return new PhabricatorPasteEditor(); + } + + public function getApplicationTransactionObject() { + return $this; + } + + public function getApplicationTransactionTemplate() { + return new PhabricatorPasteTransaction(); + } + }