diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -6525,6 +6525,7 @@ 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'PhabricatorConduitResultInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildAbortedException' => 'Exception', 'HarbormasterBuildActionController' => 'HarbormasterController', @@ -6532,6 +6533,7 @@ 'HarbormasterBuildArtifact' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildArtifactPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildArtifactQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -6564,6 +6566,7 @@ 'HarbormasterBuildMessage' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildMessageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'HarbormasterBuildPHIDType' => 'PhabricatorPHIDType', @@ -6614,6 +6617,7 @@ 'HarbormasterBuildTarget' => array( 'HarbormasterDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildTargetPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildTargetQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -6628,6 +6632,7 @@ 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'HarbormasterBuildableInterface', + 'PhabricatorDestructibleInterface', ), 'HarbormasterBuildableActionController' => 'HarbormasterController', 'HarbormasterBuildableListController' => 'HarbormasterController', diff --git a/src/applications/harbormaster/storage/HarbormasterBuildMessage.php b/src/applications/harbormaster/storage/HarbormasterBuildMessage.php --- 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 @@ 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 --- 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 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -4,7 +4,8 @@ implements PhabricatorApplicationTransactionInterface, PhabricatorPolicyInterface, - PhabricatorConduitResultInterface { + PhabricatorConduitResultInterface, + PhabricatorDestructibleInterface { protected $buildablePHID; protected $buildPlanPHID; @@ -455,4 +456,33 @@ ); } + +/* -( 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 --- 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 --- 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(); + } + + }