@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+132 -8
+1
scripts/repository/manage_repositories.php
··· 35 35 new PhabricatorRepositoryManagementPullWorkflow(), 36 36 new PhabricatorRepositoryManagementDiscoverWorkflow(), 37 37 new PhabricatorRepositoryManagementListWorkflow(), 38 + new PhabricatorRepositoryManagementDeleteWorkflow(), 38 39 new PhutilHelpArgumentWorkflow(), 39 40 ); 40 41
+2
src/__phutil_library_map__.php
··· 1010 1010 'PhabricatorRepositoryGitCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php', 1011 1011 'PhabricatorRepositoryGitCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php', 1012 1012 'PhabricatorRepositoryListController' => 'applications/repository/controller/PhabricatorRepositoryListController.php', 1013 + 'PhabricatorRepositoryManagementDeleteWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php', 1013 1014 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php', 1014 1015 'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php', 1015 1016 'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php', ··· 2182 2183 'PhabricatorRepositoryGitCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 2183 2184 'PhabricatorRepositoryGitCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 2184 2185 'PhabricatorRepositoryListController' => 'PhabricatorRepositoryController', 2186 + 'PhabricatorRepositoryManagementDeleteWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 2185 2187 'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 2186 2188 'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow', 2187 2189 'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
+14 -8
src/applications/repository/controller/PhabricatorRepositoryDeleteController.php
··· 35 35 $request = $this->getRequest(); 36 36 37 37 if ($request->isDialogFormPost()) { 38 - $repository->delete(); 39 38 return id(new AphrontRedirectResponse())->setURI('/repository/'); 40 39 } 41 40 42 41 $dialog = new AphrontDialogView(); 42 + $text_1 = pht('If you really want to delete the repository, you must run:'); 43 + $command = 'bin/repository delete '. 44 + phutil_escape_html($repository->getCallsign()); 45 + $text_2 = pht('Repositories touch many objects and as such deletes are '. 46 + 'prohibitively expensive to run from the web UI.'); 47 + $body = phutil_render_tag( 48 + 'div', 49 + array( 50 + 'class' => 'phabricator-remarkup', 51 + ), 52 + '<p>'.$text_1.'</p><p><tt>'.$command.'</tt></p><p>'.$text_2.'</p>'); 43 53 $dialog 44 54 ->setUser($request->getUser()) 45 - ->setTitle('Really delete repository?') 46 - ->appendChild( 47 - '<p>Really delete the "'.phutil_escape_html($repository->getName()). 48 - '" ('.phutil_escape_html($repository->getCallsign()).') repository? '. 49 - 'This operation can not be undone.</p>') 55 + ->setTitle(pht('Really want to delete the repository?')) 56 + ->appendChild($body) 50 57 ->setSubmitURI('/repository/delete/'.$this->id.'/') 51 - ->addSubmitButton('Delete Repository') 52 - ->addCancelButton('/repository/'); 58 + ->addSubmitButton(pht('Okay')); 53 59 54 60 return id(new AphrontDialogResponse())->setDialog($dialog); 55 61 }
+61
src/applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class PhabricatorRepositoryManagementDeleteWorkflow 20 + extends PhabricatorRepositoryManagementWorkflow { 21 + 22 + public function didConstruct() { 23 + $this 24 + ->setName('delete') 25 + ->setExamples('**delete** __repository__ ...') 26 + ->setSynopsis('Delete __repository__, named by callsign or PHID.') 27 + ->setArguments( 28 + array( 29 + array( 30 + 'name' => 'verbose', 31 + 'help' => 'Show additional debugging information.', 32 + ), 33 + array( 34 + 'name' => 'repos', 35 + 'wildcard' => true, 36 + ), 37 + )); 38 + } 39 + 40 + public function execute(PhutilArgumentParser $args) { 41 + $names = $args->getArg('repos'); 42 + $repos = PhabricatorRepository::loadAllByPHIDOrCallsign($names); 43 + 44 + if (!$repos) { 45 + throw new PhutilArgumentUsageException( 46 + "Specify one or more repositories to delete, by callsign or PHID."); 47 + } 48 + 49 + $console = PhutilConsole::getConsole(); 50 + foreach ($repos as $repo) { 51 + $console->writeOut("Deleting '%s'...\n", $repo->getCallsign()); 52 + 53 + $repo->delete(); 54 + } 55 + 56 + $console->writeOut("Done.\n"); 57 + 58 + return 0; 59 + } 60 + 61 + }
+49
src/applications/repository/storage/PhabricatorRepository.php
··· 548 548 return ($protocol == 'ssh' || $protocol == 'svn+ssh'); 549 549 } 550 550 551 + public function delete() { 552 + $this->openTransaction(); 553 + 554 + $paths = id(new PhabricatorOwnersPath()) 555 + ->loadAllWhere('repositoryPHID = %s', $this->getPHID()); 556 + foreach ($paths as $path) { 557 + $path->delete(); 558 + } 559 + 560 + $projects = id(new PhabricatorRepositoryArcanistProject()) 561 + ->loadAllWhere('repositoryID = %d', $this->getID()); 562 + foreach ($projects as $project) { 563 + /// note each project deletes its PhabricatorRepositorySymbols 564 + $project->delete(); 565 + } 566 + 567 + $commits = id(new PhabricatorRepositoryCommit()) 568 + ->loadAllWhere('repositoryID = %d', $this->getID()); 569 + foreach ($commits as $commit) { 570 + // note PhabricatorRepositoryAuditRequests and 571 + // PhabricatorRepositoryCommitData are deleted here too. 572 + $commit->delete(); 573 + } 574 + 575 + $conn_w = $this->establishConnection('w'); 576 + 577 + queryfx( 578 + $conn_w, 579 + 'DELETE FROM %T WHERE repositoryID = %d', 580 + self::TABLE_FILESYSTEM, 581 + $this->getID()); 582 + 583 + queryfx( 584 + $conn_w, 585 + 'DELETE FROM %T WHERE repositoryID = %d', 586 + self::TABLE_PATHCHANGE, 587 + $this->getID()); 588 + 589 + queryfx( 590 + $conn_w, 591 + 'DELETE FROM %T WHERE repositoryID = %d', 592 + self::TABLE_SUMMARY, 593 + $this->getID()); 594 + 595 + $result = parent::delete(); 596 + 597 + $this->saveTransaction(); 598 + return $result; 599 + } 551 600 }
+5
src/applications/repository/storage/PhabricatorRepositoryCommit.php
··· 91 91 92 92 public function delete() { 93 93 $data = $this->loadCommitData(); 94 + $audits = id(new PhabricatorRepositoryAuditRequest()) 95 + ->loadAllWhere('commitPHID = %s', $this->getPHID()); 94 96 $this->openTransaction(); 95 97 96 98 if ($data) { 97 99 $data->delete(); 100 + } 101 + foreach ($audits as $audit) { 102 + $audit->delete(); 98 103 } 99 104 $result = parent::delete(); 100 105