Skip to content

Commit 731a690

Browse files
committed
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
1 parent da7940b commit 731a690

File tree

6 files changed

+132
-8
lines changed

6 files changed

+132
-8
lines changed

scripts/repository/manage_repositories.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
new PhabricatorRepositoryManagementPullWorkflow(),
3636
new PhabricatorRepositoryManagementDiscoverWorkflow(),
3737
new PhabricatorRepositoryManagementListWorkflow(),
38+
new PhabricatorRepositoryManagementDeleteWorkflow(),
3839
new PhutilHelpArgumentWorkflow(),
3940
);
4041

src/__phutil_library_map__.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@
10101010
'PhabricatorRepositoryGitCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryGitCommitChangeParserWorker.php',
10111011
'PhabricatorRepositoryGitCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryGitCommitMessageParserWorker.php',
10121012
'PhabricatorRepositoryListController' => 'applications/repository/controller/PhabricatorRepositoryListController.php',
1013+
'PhabricatorRepositoryManagementDeleteWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDeleteWorkflow.php',
10131014
'PhabricatorRepositoryManagementDiscoverWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementDiscoverWorkflow.php',
10141015
'PhabricatorRepositoryManagementListWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementListWorkflow.php',
10151016
'PhabricatorRepositoryManagementPullWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementPullWorkflow.php',
@@ -2182,6 +2183,7 @@
21822183
'PhabricatorRepositoryGitCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
21832184
'PhabricatorRepositoryGitCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
21842185
'PhabricatorRepositoryListController' => 'PhabricatorRepositoryController',
2186+
'PhabricatorRepositoryManagementDeleteWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
21852187
'PhabricatorRepositoryManagementDiscoverWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
21862188
'PhabricatorRepositoryManagementListWorkflow' => 'PhabricatorRepositoryManagementWorkflow',
21872189
'PhabricatorRepositoryManagementPullWorkflow' => 'PhabricatorRepositoryManagementWorkflow',

src/applications/repository/controller/PhabricatorRepositoryDeleteController.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,27 @@ public function processRequest() {
3535
$request = $this->getRequest();
3636

3737
if ($request->isDialogFormPost()) {
38-
$repository->delete();
3938
return id(new AphrontRedirectResponse())->setURI('/repository/');
4039
}
4140

4241
$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>');
4353
$dialog
4454
->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)
5057
->setSubmitURI('/repository/delete/'.$this->id.'/')
51-
->addSubmitButton('Delete Repository')
52-
->addCancelButton('/repository/');
58+
->addSubmitButton(pht('Okay'));
5359

5460
return id(new AphrontDialogResponse())->setDialog($dialog);
5561
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

src/applications/repository/storage/PhabricatorRepository.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,53 @@ private function isSSHProtocol($protocol) {
548548
return ($protocol == 'ssh' || $protocol == 'svn+ssh');
549549
}
550550

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+
}
551600
}

src/applications/repository/storage/PhabricatorRepositoryCommit.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ public function save() {
9191

9292
public function delete() {
9393
$data = $this->loadCommitData();
94+
$audits = id(new PhabricatorRepositoryAuditRequest())
95+
->loadAllWhere('commitPHID = %s', $this->getPHID());
9496
$this->openTransaction();
9597

9698
if ($data) {
9799
$data->delete();
98100
}
101+
foreach ($audits as $audit) {
102+
$audit->delete();
103+
}
99104
$result = parent::delete();
100105

101106
$this->saveTransaction();

0 commit comments

Comments
 (0)