From 78e36d6b17a534bc4130886b07908cd3909ae39d Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 18 Mar 2016 07:16:24 -0700 Subject: [PATCH] Implement DestructibleInterface on GitLFS refs Summary: Ref T7789. Make sure these get cleaned up when a repository is destroyed. Test Plan: - Created a new repository. - Pushed some LFS data to it. - Used `bin/remove destroy` to nuke it. - Verified the LFS stuff was cleaned up and the underlying files were destroyed (`SELECT * FROM repository_gitlfsref`, etc). Reviewers: chad Reviewed By: chad Maniphest Tasks: T7789 Differential Revision: https://secure.phabricator.com/D15493 --- src/__phutil_library_map__.php | 1 + .../storage/PhabricatorRepository.php | 8 +++++++ .../PhabricatorRepositoryGitLFSRef.php | 23 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 34ec91844d..02a011ec72 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -7672,6 +7672,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryGitLFSRef' => array( 'PhabricatorRepositoryDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'PhabricatorRepositoryGitLFSRefQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorRepositoryGraphCache' => 'Phobject', diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index fbc8e38193..7068657acc 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -2435,6 +2435,14 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO $engine->destroyObject($atom); } + $lfs_refs = id(new PhabricatorRepositoryGitLFSRefQuery()) + ->setViewer($engine->getViewer()) + ->withRepositoryPHIDs(array($phid)) + ->execute(); + foreach ($lfs_refs as $ref) { + $engine->destroyObject($ref); + } + $this->saveTransaction(); } diff --git a/src/applications/repository/storage/PhabricatorRepositoryGitLFSRef.php b/src/applications/repository/storage/PhabricatorRepositoryGitLFSRef.php index c049b4897a..507af99cb4 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryGitLFSRef.php +++ b/src/applications/repository/storage/PhabricatorRepositoryGitLFSRef.php @@ -2,7 +2,9 @@ final class PhabricatorRepositoryGitLFSRef extends PhabricatorRepositoryDAO - implements PhabricatorPolicyInterface { + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $repositoryPHID; protected $objectHash; @@ -48,4 +50,23 @@ final class PhabricatorRepositoryGitLFSRef } +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $file_phid = $this->getFilePHID(); + + $file = id(new PhabricatorFileQuery()) + ->setViewer($engine->getViewer()) + ->withPHIDs(array($file_phid)) + ->executeOne(); + if ($file) { + $engine->destroyObject($file); + } + + $this->delete(); + } + }