From 731a6900bd0f0489b6591a70d0974853cb62592e Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 25 Oct 2012 16:23:41 -0700 Subject: [PATCH] upgrade repository delete function to full-blown workflow Summary: fancy title. really just make the delete() method aware of related objects and build a quick workflow which calls delete(). also make commit delete savvy about audit requests. Test Plan: deleted a repository per the instructions given to me in the web UI Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1416, T1958, T1372 Differential Revision: https://secure.phabricator.com/D3822 --- scripts/repository/manage_repositories.php | 1 + src/__phutil_library_map__.php | 2 + .../PhabricatorRepositoryDeleteController.php | 22 ++++--- ...atorRepositoryManagementDeleteWorkflow.php | 61 +++++++++++++++++++ .../storage/PhabricatorRepository.php | 49 +++++++++++++++ .../storage/PhabricatorRepositoryCommit.php | 5 ++ 6 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php diff --git a/scripts/repository/manage_repositories.php b/scripts/repository/manage_repositories.php index bcf163096d..b1e23f5ed8 100755 --- a/scripts/repository/manage_repositories.php +++ b/scripts/repository/manage_repositories.php @@ -35,6 +35,7 @@ $workflows = array( new PhabricatorRepositoryManagementPullWorkflow(), new PhabricatorRepositoryManagementDiscoverWorkflow(), new PhabricatorRepositoryManagementListWorkflow(), + new PhabricatorRepositoryManagementDeleteWorkflow(), new PhutilHelpArgumentWorkflow(), ); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a0414b56bc..7005c7a1be 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1010,6 +1010,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryGitCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php', 'PhabricatorRepositoryGitCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php', 'PhabricatorRepositoryListController' => 'applications/repository/controller/PhabricatorRepositoryListController.php', + 'PhabricatorRepositoryManagementDeleteWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php', 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php', 'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php', 'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php', @@ -2182,6 +2183,7 @@ phutil_register_library_map(array( 'PhabricatorRepositoryGitCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 'PhabricatorRepositoryGitCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 'PhabricatorRepositoryListController' => 'PhabricatorRepositoryController', + 'PhabricatorRepositoryManagementDeleteWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow', diff --git a/src/applications/repository/controller/PhabricatorRepositoryDeleteController.php b/src/applications/repository/controller/PhabricatorRepositoryDeleteController.php index 344cbb24b7..e8acc63f7e 100644 --- a/src/applications/repository/controller/PhabricatorRepositoryDeleteController.php +++ b/src/applications/repository/controller/PhabricatorRepositoryDeleteController.php @@ -35,21 +35,27 @@ final class PhabricatorRepositoryDeleteController $request = $this->getRequest(); if ($request->isDialogFormPost()) { - $repository->delete(); return id(new AphrontRedirectResponse())->setURI('/repository/'); } $dialog = new AphrontDialogView(); + $text_1 = pht('If you really want to delete the repository, you must run:'); + $command = 'bin/repository delete '. + phutil_escape_html($repository->getCallsign()); + $text_2 = pht('Repositories touch many objects and as such deletes are '. + 'prohibitively expensive to run from the web UI.'); + $body = phutil_render_tag( + 'div', + array( + 'class' => 'phabricator-remarkup', + ), + '

'.$text_1.'

'.$command.'

'.$text_2.'

'); $dialog ->setUser($request->getUser()) - ->setTitle('Really delete repository?') - ->appendChild( - '

Really delete the "'.phutil_escape_html($repository->getName()). - '" ('.phutil_escape_html($repository->getCallsign()).') repository? '. - 'This operation can not be undone.

') + ->setTitle(pht('Really want to delete the repository?')) + ->appendChild($body) ->setSubmitURI('/repository/delete/'.$this->id.'/') - ->addSubmitButton('Delete Repository') - ->addCancelButton('/repository/'); + ->addSubmitButton(pht('Okay')); return id(new AphrontDialogResponse())->setDialog($dialog); } diff --git a/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php b/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php new file mode 100644 index 0000000000..107c22963e --- /dev/null +++ b/src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php @@ -0,0 +1,61 @@ +setName('delete') + ->setExamples('**delete** __repository__ ...') + ->setSynopsis('Delete __repository__, named by callsign or PHID.') + ->setArguments( + array( + array( + 'name' => 'verbose', + 'help' => 'Show additional debugging information.', + ), + array( + 'name' => 'repos', + 'wildcard' => true, + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $names = $args->getArg('repos'); + $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); + + if (!$repos) { + throw new PhutilArgumentUsageException( + "Specify one or more repositories to delete, by callsign or PHID."); + } + + $console = PhutilConsole::getConsole(); + foreach ($repos as $repo) { + $console->writeOut("Deleting '%s'...\n", $repo->getCallsign()); + + $repo->delete(); + } + + $console->writeOut("Done.\n"); + + return 0; + } + +} diff --git a/src/applications/repository/storage/PhabricatorRepository.php b/src/applications/repository/storage/PhabricatorRepository.php index f3387c5b36..1a3afcaeb1 100644 --- a/src/applications/repository/storage/PhabricatorRepository.php +++ b/src/applications/repository/storage/PhabricatorRepository.php @@ -548,4 +548,53 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO { return ($protocol == 'ssh' || $protocol == 'svn+ssh'); } + public function delete() { + $this->openTransaction(); + + $paths = id(new PhabricatorOwnersPath()) + ->loadAllWhere('repositoryPHID = %s', $this->getPHID()); + foreach ($paths as $path) { + $path->delete(); + } + + $projects = id(new PhabricatorRepositoryArcanistProject()) + ->loadAllWhere('repositoryID = %d', $this->getID()); + foreach ($projects as $project) { + /// note each project deletes its PhabricatorRepositorySymbols + $project->delete(); + } + + $commits = id(new PhabricatorRepositoryCommit()) + ->loadAllWhere('repositoryID = %d', $this->getID()); + foreach ($commits as $commit) { + // note PhabricatorRepositoryAuditRequests and + // PhabricatorRepositoryCommitData are deleted here too. + $commit->delete(); + } + + $conn_w = $this->establishConnection('w'); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE repositoryID = %d', + self::TABLE_FILESYSTEM, + $this->getID()); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE repositoryID = %d', + self::TABLE_PATHCHANGE, + $this->getID()); + + queryfx( + $conn_w, + 'DELETE FROM %T WHERE repositoryID = %d', + self::TABLE_SUMMARY, + $this->getID()); + + $result = parent::delete(); + + $this->saveTransaction(); + return $result; + } } diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php index ce178d5678..af788f1ae9 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php +++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php @@ -91,11 +91,16 @@ final class PhabricatorRepositoryCommit extends PhabricatorRepositoryDAO { public function delete() { $data = $this->loadCommitData(); + $audits = id(new PhabricatorRepositoryAuditRequest()) + ->loadAllWhere('commitPHID = %s', $this->getPHID()); $this->openTransaction(); if ($data) { $data->delete(); } + foreach ($audits as $audit) { + $audit->delete(); + } $result = parent::delete(); $this->saveTransaction();