mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
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
This commit is contained in:
parent
da7940b0a8
commit
731a6900bd
6 changed files with 132 additions and 8 deletions
|
@ -35,6 +35,7 @@ $workflows = array(
|
|||
new PhabricatorRepositoryManagementPullWorkflow(),
|
||||
new PhabricatorRepositoryManagementDiscoverWorkflow(),
|
||||
new PhabricatorRepositoryManagementListWorkflow(),
|
||||
new PhabricatorRepositoryManagementDeleteWorkflow(),
|
||||
new PhutilHelpArgumentWorkflow(),
|
||||
);
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
'<p>'.$text_1.'</p><p><tt>'.$command.'</tt></p><p>'.$text_2.'</p>');
|
||||
$dialog
|
||||
->setUser($request->getUser())
|
||||
->setTitle('Really delete repository?')
|
||||
->appendChild(
|
||||
'<p>Really delete the "'.phutil_escape_html($repository->getName()).
|
||||
'" ('.phutil_escape_html($repository->getCallsign()).') repository? '.
|
||||
'This operation can not be undone.</p>')
|
||||
->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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class PhabricatorRepositoryManagementDeleteWorkflow
|
||||
extends PhabricatorRepositoryManagementWorkflow {
|
||||
|
||||
public function didConstruct() {
|
||||
$this
|
||||
->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue