From 94926698e0f840cbac3fffe27923bb308332f75f Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 29 Jun 2014 07:50:53 -0700 Subject: [PATCH] Allow Legalpad documents to be destroyed with `bin/remove destroy` Summary: Ref T3116. Support permanent destruction of legal document objects. Test Plan: Ran `bin/remove destroy L1`, saw it clean up the document body, signatures, transactions and edges. Reviewers: btrahan, chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T3116 Differential Revision: https://secure.phabricator.com/D9775 --- src/__phutil_library_map__.php | 1 + .../legalpad/storage/LegalpadDocument.php | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7e3ab8e8f6..3fd46e6365 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3611,6 +3611,7 @@ phutil_register_library_map(array( 1 => 'PhabricatorPolicyInterface', 2 => 'PhabricatorSubscribableInterface', 3 => 'PhabricatorApplicationTransactionInterface', + 4 => 'PhabricatorDestructableInterface', ), 'LegalpadDocumentBody' => array( diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php index 4f8378f0a1..a29047c4e8 100644 --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -4,7 +4,8 @@ final class LegalpadDocument extends LegalpadDAO implements PhabricatorPolicyInterface, PhabricatorSubscribableInterface, - PhabricatorApplicationTransactionInterface { + PhabricatorApplicationTransactionInterface, + PhabricatorDestructableInterface { protected $title; protected $contributorCount; @@ -170,4 +171,31 @@ final class LegalpadDocument extends LegalpadDAO return new LegalpadTransaction(); } + +/* -( PhabricatorDestructableInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $this->openTransaction(); + $this->delete(); + + $bodies = id(new LegalpadDocumentBody())->loadAllWhere( + 'documentPHID = %s', + $this->getPHID()); + foreach ($bodies as $body) { + $body->delete(); + } + + $signatures = id(new LegalpadDocumentSignature())->loadAllWhere( + 'documentPHID = %s', + $this->getPHID()); + foreach ($signatures as $signature) { + $signature->delete(); + } + + $this->saveTransaction(); + } + } -- 2.51.2