Cut mirroring over to new URIs
Summary: Ref T10748. This migrates and swaps mirroring to `PhabricatorRepositoryURI`, obsoleting `PhabricatorRepositoryMirror`. This prevents you from editing, adding or disabling mirrors unless you know a secret URI (until the UI cuts over fully), but existing mirroring is not affected. Test Plan: - Added a mirroring URI to an old repository. - Verified it worked with `bin/repository mirror`. - Migrated forward. - Verified it still worked with `bin/repository mirror`. - Wow, mirroring: https://github.com/epriestley/locktopia-mirror Reviewers: chad Reviewed By: chad Maniphest Tasks: T10748 Differential Revision: https://secure.phabricator.com/D15841
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class DiffusionMirrorDeleteController
|
||||
extends DiffusionController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$response = $this->loadDiffusionContext();
|
||||
if ($response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
$mirror = id(new PhabricatorRepositoryMirrorQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getURIData('id')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$mirror) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/#mirrors');
|
||||
|
||||
if ($request->isFormPost()) {
|
||||
$mirror->delete();
|
||||
return id(new AphrontReloadResponse())->setURI($edit_uri);
|
||||
}
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle(pht('Really delete mirror?'))
|
||||
->appendChild(
|
||||
pht('Phabricator will stop pushing updates to this mirror.'))
|
||||
->addSubmitButton(pht('Delete Mirror'))
|
||||
->addCancelButton($edit_uri);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class DiffusionMirrorEditController
|
||||
extends DiffusionController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$response = $this->loadDiffusionContext();
|
||||
if ($response) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
$repository = $drequest->getRepository();
|
||||
|
||||
PhabricatorPolicyFilter::requireCapability(
|
||||
$viewer,
|
||||
$repository,
|
||||
PhabricatorPolicyCapability::CAN_EDIT);
|
||||
|
||||
if ($request->getURIData('id')) {
|
||||
$mirror = id(new PhabricatorRepositoryMirrorQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($request->getURIData('id')))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$mirror) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
$is_new = false;
|
||||
} else {
|
||||
$mirror = PhabricatorRepositoryMirror::initializeNewMirror($viewer)
|
||||
->setRepositoryPHID($repository->getPHID())
|
||||
->attachRepository($repository);
|
||||
$is_new = true;
|
||||
}
|
||||
|
||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/#mirrors');
|
||||
|
||||
$v_remote = $mirror->getRemoteURI();
|
||||
$e_remote = true;
|
||||
|
||||
$v_credentials = $mirror->getCredentialPHID();
|
||||
$e_credentials = null;
|
||||
|
||||
$credentials = id(new PassphraseCredentialQuery())
|
||||
->setViewer($viewer)
|
||||
->withIsDestroyed(false)
|
||||
->execute();
|
||||
|
||||
$errors = array();
|
||||
if ($request->isFormPost()) {
|
||||
$v_remote = $request->getStr('remoteURI');
|
||||
if (strlen($v_remote)) {
|
||||
try {
|
||||
PhabricatorRepository::assertValidRemoteURI($v_remote);
|
||||
$e_remote = null;
|
||||
} catch (Exception $ex) {
|
||||
$e_remote = pht('Invalid');
|
||||
$errors[] = $ex->getMessage();
|
||||
}
|
||||
} else {
|
||||
$e_remote = pht('Required');
|
||||
$errors[] = pht('You must provide a remote URI.');
|
||||
}
|
||||
|
||||
$v_credentials = $request->getStr('credential');
|
||||
if ($v_credentials) {
|
||||
$phids = mpull($credentials, null, 'getPHID');
|
||||
if (empty($phids[$v_credentials])) {
|
||||
$e_credentials = pht('Invalid');
|
||||
$errors[] = pht(
|
||||
'You do not have permission to use those credentials.');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$errors) {
|
||||
$mirror
|
||||
->setRemoteURI($v_remote)
|
||||
->setCredentialPHID($v_credentials)
|
||||
->save();
|
||||
return id(new AphrontReloadResponse())->setURI($edit_uri);
|
||||
}
|
||||
}
|
||||
|
||||
$form_errors = null;
|
||||
if ($errors) {
|
||||
$form_errors = id(new PHUIInfoView())
|
||||
->setErrors($errors);
|
||||
}
|
||||
|
||||
if ($is_new) {
|
||||
$title = pht('Create Mirror');
|
||||
$submit = pht('Create Mirror');
|
||||
} else {
|
||||
$title = pht('Edit Mirror');
|
||||
$submit = pht('Save Changes');
|
||||
}
|
||||
|
||||
$form = id(new PHUIFormLayoutView())
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Remote URI'))
|
||||
->setName('remoteURI')
|
||||
->setValue($v_remote)
|
||||
->setError($e_remote))
|
||||
->appendControl(
|
||||
id(new PassphraseCredentialControl())
|
||||
->setLabel(pht('Credentials'))
|
||||
->setName('credential')
|
||||
->setAllowNull(true)
|
||||
->setValue($v_credentials)
|
||||
->setError($e_credentials)
|
||||
->setOptions($credentials));
|
||||
|
||||
return $this->newDialog()
|
||||
->setTitle($title)
|
||||
->setWidth(AphrontDialogView::WIDTH_FORM)
|
||||
->appendChild($form_errors)
|
||||
->appendChild($form)
|
||||
->addSubmitButton($submit)
|
||||
->addCancelButton($edit_uri);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -129,37 +129,6 @@ final class DiffusionRepositoryEditMainController
|
||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->addPropertyList($hosting_properties);
|
||||
|
||||
if ($repository->canMirror()) {
|
||||
$mirror_actions = $this->buildMirrorActions($repository);
|
||||
$mirror_properties = $this->buildMirrorProperties(
|
||||
$repository,
|
||||
$mirror_actions);
|
||||
|
||||
$mirrors = id(new PhabricatorRepositoryMirrorQuery())
|
||||
->setViewer($viewer)
|
||||
->withRepositoryPHIDs(array($repository->getPHID()))
|
||||
->execute();
|
||||
|
||||
$mirror_list = $this->buildMirrorList($repository, $mirrors);
|
||||
|
||||
$boxes[] = id(new PhabricatorAnchorView())->setAnchorName('mirrors');
|
||||
|
||||
$mirror_info = array();
|
||||
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
|
||||
$mirror_info[] = pht(
|
||||
'Phabricator is running in silent mode, so changes will not '.
|
||||
'be pushed to mirrors.');
|
||||
}
|
||||
|
||||
$boxes[] = id(new PHUIObjectBoxView())
|
||||
->setFormErrors($mirror_info)
|
||||
->setHeaderText(pht('Mirrors'))
|
||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->addPropertyList($mirror_properties);
|
||||
|
||||
$boxes[] = $mirror_list;
|
||||
}
|
||||
|
||||
if ($remote_properties) {
|
||||
$boxes[] = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Remote'))
|
||||
@@ -1193,90 +1162,6 @@ final class DiffusionRepositoryEditMainController
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function buildMirrorActions(
|
||||
PhabricatorRepository $repository) {
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$mirror_actions = id(new PhabricatorActionListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$new_mirror_uri = $this->getRepositoryControllerURI(
|
||||
$repository,
|
||||
'mirror/edit/');
|
||||
|
||||
$mirror_actions->addAction(
|
||||
id(new PhabricatorActionView())
|
||||
->setName(pht('Add Mirror'))
|
||||
->setIcon('fa-plus')
|
||||
->setHref($new_mirror_uri)
|
||||
->setWorkflow(true));
|
||||
|
||||
return $mirror_actions;
|
||||
}
|
||||
|
||||
private function buildMirrorProperties(
|
||||
PhabricatorRepository $repository,
|
||||
PhabricatorActionListView $actions) {
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$mirror_properties = id(new PHUIPropertyListView())
|
||||
->setUser($viewer)
|
||||
->setActionList($actions);
|
||||
|
||||
$mirror_properties->addProperty(
|
||||
'',
|
||||
phutil_tag(
|
||||
'em',
|
||||
array(),
|
||||
pht('Automatically push changes into other remotes.')));
|
||||
|
||||
return $mirror_properties;
|
||||
}
|
||||
|
||||
private function buildMirrorList(
|
||||
PhabricatorRepository $repository,
|
||||
array $mirrors) {
|
||||
assert_instances_of($mirrors, 'PhabricatorRepositoryMirror');
|
||||
|
||||
$mirror_list = id(new PHUIObjectItemListView())
|
||||
->setNoDataString(pht('This repository has no configured mirrors.'));
|
||||
|
||||
foreach ($mirrors as $mirror) {
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($mirror->getRemoteURI());
|
||||
|
||||
$edit_uri = $this->getRepositoryControllerURI(
|
||||
$repository,
|
||||
'mirror/edit/'.$mirror->getID().'/');
|
||||
|
||||
$delete_uri = $this->getRepositoryControllerURI(
|
||||
$repository,
|
||||
'mirror/delete/'.$mirror->getID().'/');
|
||||
|
||||
$item->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setIcon('fa-pencil')
|
||||
->setHref($edit_uri)
|
||||
->setWorkflow(true));
|
||||
|
||||
$item->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setIcon('fa-times')
|
||||
->setHref($delete_uri)
|
||||
->setWorkflow(true));
|
||||
|
||||
$mirror_list->addItem($item);
|
||||
}
|
||||
|
||||
return id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Configured Mirrors'))
|
||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
||||
->setObjectList($mirror_list);
|
||||
}
|
||||
|
||||
private function buildSymbolsActions(PhabricatorRepository $repository) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user