From 7f9a9bc800f76c10b2f8571f41815e15dfc0653f Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 29 Mar 2018 11:20:38 -0700 Subject: [PATCH] Make Harbormaster objects destructible Summary: Ref T13114. See PHI511. Ref T13072. This makes Buildables, Builds, Targets and Artifacts destructible with `bin/remove destroy`. This might not be totally exhaustive. In particular: - File artifacts won't destroy the file. This is sort of okay because file artifacts are currently just a file reference, but probably shouldn't be how things work in the long term. - `BuildCommand` doesn't get cleaned up, but `BuildMessage` does on `Build`. See T13072 for more. Test Plan: Used `bin/remove destroy` to nuke a bunch of builds, buildables, etc. Loaded stuff in the web UI and it all looked like it got nuked properly. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13114, T13072 Differential Revision: https://secure.phabricator.com/D19269 --- src/__phutil_library_map__.php | 5 ++ .../storage/HarbormasterBuildMessage.php | 16 ++++- .../storage/HarbormasterBuildable.php | 34 +++++++++- .../storage/build/HarbormasterBuild.php | 32 +++++++++- .../build/HarbormasterBuildArtifact.php | 22 ++++++- .../storage/build/HarbormasterBuildTarget.php | 62 ++++++++++++++++++- 6 files changed, 162 insertions(+), 9 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b1afef3600..59d0e7eb99 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -6525,6 +6525,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'PhabricatorConduitResultInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildAbortedException' => 'Exception', 'HarbormasterBuildActionController' => 'HarbormasterController', @@ -6532,6 +6533,7 @@ phutil_register_library_map(array( 'HarbormasterBuildArtifact' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildArtifactPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildArtifactQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -6564,6 +6566,7 @@ phutil_register_library_map(array( 'HarbormasterBuildMessage' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildMessageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'HarbormasterBuildPHIDType' => 'PhabricatorPHIDType', @@ -6614,6 +6617,7 @@ phutil_register_library_map(array( 'HarbormasterBuildTarget' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildTargetPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildTargetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -6628,6 +6632,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'HarbormasterBuildableInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildableActionController' => 'HarbormasterController', 'HarbormasterBuildableListController' => 'HarbormasterController', diff --git a/src/applications/harbormaster/storage/HarbormasterBuildMessage.php b/src/applications/harbormaster/storage/HarbormasterBuildMessage.php index 1066a93610..34aab3957e 100644 --- a/src/applications/harbormaster/storage/HarbormasterBuildMessage.php +++ b/src/applications/harbormaster/storage/HarbormasterBuildMessage.php @@ -6,8 +6,11 @@ * conditions where we receive a message before a build plan is ready to * accept it. */ -final class HarbormasterBuildMessage extends HarbormasterDAO - implements PhabricatorPolicyInterface { +final class HarbormasterBuildMessage + extends HarbormasterDAO + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $authorPHID; protected $receiverPHID; @@ -74,4 +77,13 @@ final class HarbormasterBuildMessage extends HarbormasterDAO return pht('Build messages have the same policies as their receivers.'); } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + $this->delete(); + } + } diff --git a/src/applications/harbormaster/storage/HarbormasterBuildable.php b/src/applications/harbormaster/storage/HarbormasterBuildable.php index 5de2159e8d..3a092900eb 100644 --- a/src/applications/harbormaster/storage/HarbormasterBuildable.php +++ b/src/applications/harbormaster/storage/HarbormasterBuildable.php @@ -1,10 +1,12 @@ getViewer(); + + $this->openTransaction(); + $builds = id(new HarbormasterBuildQuery()) + ->setViewer($viewer) + ->withBuildablePHIDs(array($this->getPHID())) + ->execute(); + foreach ($builds as $build) { + $engine->destroyObject($build); + } + + $messages = id(new HarbormasterBuildMessageQuery()) + ->setViewer($viewer) + ->withReceiverPHIDs(array($this->getPHID())) + ->execute(); + foreach ($messages as $message) { + $engine->destroyObject($message); + } + + $this->delete(); + $this->saveTransaction(); + } + } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php index d43b19d71f..ae0f6b13f3 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -4,7 +4,8 @@ final class HarbormasterBuild extends HarbormasterDAO implements PhabricatorApplicationTransactionInterface, PhabricatorPolicyInterface, - PhabricatorConduitResultInterface { + PhabricatorConduitResultInterface, + PhabricatorDestructibleInterface { protected $buildablePHID; protected $buildPlanPHID; @@ -455,4 +456,33 @@ final class HarbormasterBuild extends HarbormasterDAO ); } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + $viewer = $engine->getViewer(); + + $this->openTransaction(); + $targets = id(new HarbormasterBuildTargetQuery()) + ->setViewer($viewer) + ->withBuildPHIDs(array($this->getPHID())) + ->execute(); + foreach ($targets as $target) { + $engine->destroyObject($target); + } + + $messages = id(new HarbormasterBuildMessageQuery()) + ->setViewer($viewer) + ->withReceiverPHIDs(array($this->getPHID())) + ->execute(); + foreach ($messages as $message) { + $engine->destroyObject($message); + } + + $this->delete(); + $this->saveTransaction(); + } + + } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php b/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php index 461ef4b06f..7cd8d60b6a 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildArtifact.php @@ -1,7 +1,10 @@ getViewer(); + + $this->openTransaction(); + $this->releaseArtifact($viewer); + $this->delete(); + $this->saveTransaction(); + } + } diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php index 8b47bdfc21..b559a66198 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuildTarget.php @@ -1,7 +1,10 @@ getViewer(); + + $this->openTransaction(); + + $lint_message = new HarbormasterBuildLintMessage(); + $conn = $lint_message->establishConnection('w'); + queryfx( + $conn, + 'DELETE FROM %T WHERE buildTargetPHID = %s', + $lint_message->getTableName(), + $this->getPHID()); + + $unit_message = new HarbormasterBuildUnitMessage(); + $conn = $unit_message->establishConnection('w'); + queryfx( + $conn, + 'DELETE FROM %T WHERE buildTargetPHID = %s', + $unit_message->getTableName(), + $this->getPHID()); + + $logs = id(new HarbormasterBuildLogQuery()) + ->setViewer($viewer) + ->withBuildTargetPHIDs(array($this->getPHID())) + ->execute(); + foreach ($logs as $log) { + $engine->destroyObject($log); + } + + $artifacts = id(new HarbormasterBuildArtifactQuery()) + ->setViewer($viewer) + ->withBuildTargetPHIDs(array($this->getPHID())) + ->execute(); + foreach ($artifacts as $artifact) { + $engine->destroyObject($artifact); + } + + $messages = id(new HarbormasterBuildMessageQuery()) + ->setViewer($viewer) + ->withReceiverPHIDs(array($this->getPHID())) + ->execute(); + foreach ($messages as $message) { + $engine->destroyObject($message); + } + + $this->delete(); + $this->saveTransaction(); + } + + }