1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Add UI for defining repository mirrors

Summary:
Ref T4038. This adds everything except the actual pushing part for mirrors.

This isn't the most beautiful or sophisticated UI, but I want get the authoritative repositories self-hosted and get users beta-ing hosting as soon as possible. We can do transactions, etc., later on.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4038

Differential Revision: https://secure.phabricator.com/D7632
This commit is contained in:
epriestley 2013-11-22 15:23:50 -08:00
parent 51fb1ca16d
commit 4b91c4f7ae
12 changed files with 584 additions and 35 deletions

View file

@ -0,0 +1,13 @@
CREATE TABLE {$NAMESPACE}_repository.repository_mirror (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
phid VARCHAR(64) NOT NULL COLLATE utf8_bin,
repositoryPHID VARCHAR(64) NOT NULL COLLATE utf8_bin,
remoteURI VARCHAR(255) NOT NULL COLLATE utf8_bin,
credentialPHID VARCHAR(64) COLLATE utf8_bin,
dateCreated INT UNSIGNED NOT NULL,
dateModified INT UNSIGNED NOT NULL,
UNIQUE KEY `key_phid` (phid),
KEY `key_repository` (repositoryPHID)
) ENGINE=InnoDB, COLLATE utf8_general_ci;

View file

@ -510,6 +510,8 @@ phutil_register_library_map(array(
'DiffusionMercurialRequest' => 'applications/diffusion/request/DiffusionMercurialRequest.php', 'DiffusionMercurialRequest' => 'applications/diffusion/request/DiffusionMercurialRequest.php',
'DiffusionMercurialResponse' => 'applications/diffusion/response/DiffusionMercurialResponse.php', 'DiffusionMercurialResponse' => 'applications/diffusion/response/DiffusionMercurialResponse.php',
'DiffusionMercurialWireProtocol' => 'applications/diffusion/protocol/DiffusionMercurialWireProtocol.php', 'DiffusionMercurialWireProtocol' => 'applications/diffusion/protocol/DiffusionMercurialWireProtocol.php',
'DiffusionMirrorDeleteController' => 'applications/diffusion/controller/DiffusionMirrorDeleteController.php',
'DiffusionMirrorEditController' => 'applications/diffusion/controller/DiffusionMirrorEditController.php',
'DiffusionPathChange' => 'applications/diffusion/data/DiffusionPathChange.php', 'DiffusionPathChange' => 'applications/diffusion/data/DiffusionPathChange.php',
'DiffusionPathChangeQuery' => 'applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php', 'DiffusionPathChangeQuery' => 'applications/diffusion/query/pathchange/DiffusionPathChangeQuery.php',
'DiffusionPathCompleteController' => 'applications/diffusion/controller/DiffusionPathCompleteController.php', 'DiffusionPathCompleteController' => 'applications/diffusion/controller/DiffusionPathCompleteController.php',
@ -1770,8 +1772,11 @@ phutil_register_library_map(array(
'PhabricatorRepositoryManagementWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementWorkflow.php', 'PhabricatorRepositoryManagementWorkflow' => 'applications/repository/management/PhabricatorRepositoryManagementWorkflow.php',
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'applications/repository/worker/commitchangeparser/PhabricatorRepositoryMercurialCommitChangeParserWorker.php',
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'applications/repository/worker/commitmessageparser/PhabricatorRepositoryMercurialCommitMessageParserWorker.php',
'PhabricatorRepositoryMirror' => 'applications/repository/storage/PhabricatorRepositoryMirror.php',
'PhabricatorRepositoryMirrorQuery' => 'applications/repository/query/PhabricatorRepositoryMirrorQuery.php',
'PhabricatorRepositoryPHIDTypeArcanistProject' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php', 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeArcanistProject.php',
'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php', 'PhabricatorRepositoryPHIDTypeCommit' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeCommit.php',
'PhabricatorRepositoryPHIDTypeMirror' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeMirror.php',
'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php', 'PhabricatorRepositoryPHIDTypeRepository' => 'applications/repository/phid/PhabricatorRepositoryPHIDTypeRepository.php',
'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php', 'PhabricatorRepositoryPullEngine' => 'applications/repository/engine/PhabricatorRepositoryPullEngine.php',
'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php', 'PhabricatorRepositoryPullLocalDaemon' => 'applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php',
@ -2823,6 +2828,8 @@ phutil_register_library_map(array(
'DiffusionMercurialRawDiffQuery' => 'DiffusionRawDiffQuery', 'DiffusionMercurialRawDiffQuery' => 'DiffusionRawDiffQuery',
'DiffusionMercurialRequest' => 'DiffusionRequest', 'DiffusionMercurialRequest' => 'DiffusionRequest',
'DiffusionMercurialResponse' => 'AphrontResponse', 'DiffusionMercurialResponse' => 'AphrontResponse',
'DiffusionMirrorDeleteController' => 'DiffusionController',
'DiffusionMirrorEditController' => 'DiffusionController',
'DiffusionPathCompleteController' => 'DiffusionController', 'DiffusionPathCompleteController' => 'DiffusionController',
'DiffusionPathQueryTestCase' => 'PhabricatorTestCase', 'DiffusionPathQueryTestCase' => 'PhabricatorTestCase',
'DiffusionPathValidateController' => 'DiffusionController', 'DiffusionPathValidateController' => 'DiffusionController',
@ -4253,8 +4260,15 @@ phutil_register_library_map(array(
'PhabricatorRepositoryManagementWorkflow' => 'PhutilArgumentWorkflow', 'PhabricatorRepositoryManagementWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker', 'PhabricatorRepositoryMercurialCommitChangeParserWorker' => 'PhabricatorRepositoryCommitChangeParserWorker',
'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker', 'PhabricatorRepositoryMercurialCommitMessageParserWorker' => 'PhabricatorRepositoryCommitMessageParserWorker',
'PhabricatorRepositoryMirror' =>
array(
0 => 'PhabricatorRepositoryDAO',
1 => 'PhabricatorPolicyInterface',
),
'PhabricatorRepositoryMirrorQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorRepositoryPHIDTypeArcanistProject' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeArcanistProject' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeCommit' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeMirror' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType', 'PhabricatorRepositoryPHIDTypeRepository' => 'PhabricatorPHIDType',
'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine', 'PhabricatorRepositoryPullEngine' => 'PhabricatorRepositoryEngine',
'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon', 'PhabricatorRepositoryPullLocalDaemon' => 'PhabricatorDaemon',

View file

@ -80,6 +80,10 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication {
'hosting/' => 'DiffusionRepositoryEditHostingController', 'hosting/' => 'DiffusionRepositoryEditHostingController',
'(?P<serve>serve)/' => 'DiffusionRepositoryEditHostingController', '(?P<serve>serve)/' => 'DiffusionRepositoryEditHostingController',
), ),
'mirror/' => array(
'edit/(?:(?P<id>\d+)/)?' => 'DiffusionMirrorEditController',
'delete/(?P<id>\d+)/' => 'DiffusionMirrorDeleteController',
),
), ),
// NOTE: This must come after the rule above; it just gives us a // NOTE: This must come after the rule above; it just gives us a

View file

@ -0,0 +1,47 @@
<?php
final class DiffusionMirrorDeleteController
extends DiffusionController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
parent::willProcessRequest($data);
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->diffusionRequest;
$repository = $drequest->getRepository();
$mirror = id(new PhabricatorRepositoryMirrorQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->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);
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Really delete mirror?'))
->appendChild(
pht('Phabricator will stop pushing updates to this mirror.'))
->addSubmitButton(pht('Delete Mirror'))
->addCancelButton($edit_uri);
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
}

View file

@ -0,0 +1,121 @@
<?php
final class DiffusionMirrorEditController
extends DiffusionController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
parent::willProcessRequest($data);
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$drequest = $this->diffusionRequest;
$repository = $drequest->getRepository();
if ($this->id) {
$mirror = id(new PhabricatorRepositoryMirrorQuery())
->setViewer($viewer)
->withIDs(array($this->id))
->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)) {
$e_remote = null;
} 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 AphrontErrorView())
->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))
->appendChild(
id(new PassphraseCredentialControl())
->setLabel(pht('Credentials'))
->setName('credential')
->setAllowNull(true)
->setValue($v_credentials)
->setError($e_credentials)
->setOptions($credentials));
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle($title)
->setWidth(AphrontDialogView::WIDTH_FORM)
->appendChild($form_errors)
->appendChild($form)
->addSubmitButton($submit)
->addCancelButton($edit_uri);
return id(new AphrontDialogResponse())
->setDialog($dialog);
}
}

View file

@ -67,6 +67,7 @@ final class DiffusionRepositoryEditMainController
$repository, $repository,
$this->buildHostingActions($repository)); $this->buildHostingActions($repository));
$branches_properties = null; $branches_properties = null;
if ($has_branches) { if ($has_branches) {
$branches_properties = $this->buildBranchesProperties( $branches_properties = $this->buildBranchesProperties(
@ -114,36 +115,78 @@ final class DiffusionRepositoryEditMainController
->setTransactions($xactions) ->setTransactions($xactions)
->setMarkupEngine($engine); ->setMarkupEngine($engine);
$obj_box = id(new PHUIObjectBoxView()) $boxes = array();
$boxes[] = id(new PHUIObjectBoxView())
->setHeader($header) ->setHeader($header)
->addPropertyList($basic_properties) ->addPropertyList($basic_properties);
->addPropertyList($policy_properties)
$boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Policies'))
->addPropertyList($policy_properties);
$boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Hosting'))
->addPropertyList($hosting_properties); ->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');
$boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Mirrors'))
->addPropertyList($mirror_properties);
$boxes[] = $mirror_list;
}
if ($remote_properties) { if ($remote_properties) {
$obj_box->addPropertyList($remote_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Remote'))
->addPropertyList($remote_properties);
} }
if ($local_properties) { if ($local_properties) {
$obj_box->addPropertyList($local_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Local'))
->addPropertyList($local_properties);
} }
$obj_box->addPropertyList($encoding_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Text Encoding'))
->addPropertyList($encoding_properties);
if ($branches_properties) { if ($branches_properties) {
$obj_box->addPropertyList($branches_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Branches'))
->addPropertyList($branches_properties);
} }
if ($subversion_properties) { if ($subversion_properties) {
$obj_box->addPropertyList($subversion_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Subversion'))
->addPropertyList($subversion_properties);
} }
$obj_box->addPropertyList($actions_properties); $boxes[] = id(new PHUIObjectBoxView())
->setHeaderText(pht('Actions'))
->addPropertyList($actions_properties);
return $this->buildApplicationPage( return $this->buildApplicationPage(
array( array(
$crumbs, $crumbs,
$obj_box, $boxes,
$xaction_view, $xaction_view,
), ),
array( array(
@ -253,8 +296,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Text Encoding'));
$encoding = $repository->getDetail('encoding'); $encoding = $repository->getDetail('encoding');
if (!$encoding) { if (!$encoding) {
@ -291,8 +333,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Policies'));
$descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
$viewer, $viewer,
@ -339,8 +380,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Branches'));
$default_branch = nonempty( $default_branch = nonempty(
$repository->getHumanReadableDetail('default-branch'), $repository->getHumanReadableDetail('default-branch'),
@ -390,8 +430,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Subversion'));
$svn_uuid = nonempty( $svn_uuid = nonempty(
$repository->getUUID(), $repository->getUUID(),
@ -431,8 +470,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Actions'));
$notify = $repository->getDetail('herald-disabled') $notify = $repository->getDetail('herald-disabled')
? pht('Off') ? pht('Off')
@ -474,8 +512,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Remote'));
$view->addProperty( $view->addProperty(
pht('Remote URI'), pht('Remote URI'),
@ -517,8 +554,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($viewer) ->setUser($viewer)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Local'));
$view->addProperty( $view->addProperty(
pht('Local Path'), pht('Local Path'),
@ -552,8 +588,7 @@ final class DiffusionRepositoryEditMainController
$view = id(new PHUIPropertyListView()) $view = id(new PHUIPropertyListView())
->setUser($user) ->setUser($user)
->setActionList($actions) ->setActionList($actions);
->addSectionHeader(pht('Hosting'));
$hosting = $repository->isHosted() $hosting = $repository->isHosted()
? pht('Hosted on Phabricator') ? pht('Hosted on Phabricator')
@ -903,4 +938,86 @@ final class DiffusionRepositoryEditMainController
return $view; return $view;
} }
private function buildMirrorActions(
PhabricatorRepository $repository) {
$viewer = $this->getRequest()->getUser();
$mirror_actions = id(new PhabricatorActionListView())
->setObjectURI($this->getRequest()->getRequestURI())
->setUser($viewer);
$new_mirror_uri = $this->getRepositoryControllerURI(
$repository,
'mirror/edit/');
$mirror_actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Add Mirror'))
->setIcon('new')
->setHref($new_mirror_uri)
->setWorkflow(true));
return $mirror_actions;
}
private function buildMirrorProperties(
PhabricatorRepository $repository,
PhabricatorActionListView $actions) {
$viewer = $this->getRequest()->getUser();
$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('edit')
->setHref($edit_uri)
->setWorkflow(true));
$item->addAction(
id(new PHUIListItemView())
->setIcon('delete')
->setHref($delete_uri)
->setWorkflow(true));
$mirror_list->addItem($item);
}
return $mirror_list;
}
} }

View file

@ -68,15 +68,19 @@ final class PassphraseCredentialControl extends AphrontFormControl {
'sigil' => 'passphrase-credential-select', 'sigil' => 'passphrase-credential-select',
)); ));
$button = javelin_tag( if ($this->credentialType) {
'a', $button = javelin_tag(
array( 'a',
'href' => '#', array(
'class' => 'button grey', 'href' => '#',
'sigil' => 'passphrase-credential-add', 'class' => 'button grey',
'mustcapture' => true, 'sigil' => 'passphrase-credential-add',
), 'mustcapture' => true,
pht('Add Credential')); ),
pht('Add Credential'));
} else {
$button = null;
}
return javelin_tag( return javelin_tag(
'div', 'div',

View file

@ -0,0 +1,47 @@
<?php
final class PhabricatorRepositoryPHIDTypeMirror
extends PhabricatorPHIDType {
const TYPECONST = 'RMIR';
public function getTypeConstant() {
return self::TYPECONST;
}
public function getTypeName() {
return pht('Repository Mirror');
}
public function newObject() {
return new PhabricatorRepositoryMirror();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new PhabricatorRepositoryMirrorQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$mirror = $objects[$phid];
$handle->setName(
pht('Mirror %d %s', $mirror->getID(), $mirror->getRemoteURI()));
$handle->setURI("/diffusion/mirror/".$mirror->getID()."/");
}
}
public function canLoadNamedObject($name) {
return false;
}
}

View file

@ -0,0 +1,101 @@
<?php
final class PhabricatorRepositoryMirrorQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $repositoryPHIDs;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withRepositoryPHIDs(array $repository_phids) {
$this->repositoryPHIDs = $repository_phids;
return $this;
}
protected function loadPage() {
$table = new PhabricatorRepositoryMirror();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
public function willFilterPage(array $mirrors) {
assert_instances_of($mirrors, 'PhabricatorRepositoryMirror');
$repository_phids = mpull($mirrors, 'getRepositoryPHID');
if ($repository_phids) {
$repositories = id(new PhabricatorRepositoryQuery())
->setViewer($this->getViewer())
->withPHIDs($repository_phids)
->execute();
$repositories = mpull($repositories, null, 'getPHID');
} else {
$repositories = array();
}
foreach ($mirrors as $key => $mirror) {
$phid = $mirror->getRepositoryPHID();
if (empty($repositories[$phid])) {
unset($mirrors[$key]);
continue;
}
$mirror->attachRepository($repositories[$phid]);
}
return $mirrors;
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
if ($this->repositoryPHIDs) {
$where[] = qsprintf(
$conn_r,
'repositoryPHID IN (%Ls)',
$this->repositoryPHIDs);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
public function getQueryApplicationClass() {
return 'PhabricatorApplicationDiffusion';
}
}

View file

@ -740,6 +740,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
$commit->delete(); $commit->delete();
} }
$mirrors = id(new PhabricatorRepositoryMirror())
->loadAllWhere('repositoryPHID = %s', $this->getPHID());
foreach ($mirrors as $mirror) {
$mirror->delete();
}
$conn_w = $this->establishConnection('w'); $conn_w = $this->establishConnection('w');
queryfx( queryfx(
@ -894,6 +900,17 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
return Filesystem::isDescendant($this->getLocalPath(), $default_path); return Filesystem::isDescendant($this->getLocalPath(), $default_path);
} }
public function canMirror() {
if (!$this->isHosted()) {
return false;
}
if ($this->isGit()) {
return true;
}
return false;
}
public function writeStatusMessage( public function writeStatusMessage(
$status_type, $status_type,

View file

@ -0,0 +1,60 @@
<?php
final class PhabricatorRepositoryMirror extends PhabricatorRepositoryDAO
implements PhabricatorPolicyInterface {
protected $repositoryPHID;
protected $remoteURI;
protected $credentialPHID;
private $repository = self::ATTACHABLE;
public static function initializeNewMirror(PhabricatorUser $actor) {
return id(new PhabricatorRepositoryMirror())
->setRemoteURI('');
}
public function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
PhabricatorRepositoryPHIDTypeMirror::TYPECONST);
}
public function attachRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function getRepository() {
return $this->assertAttached($this->repository);
}
/* -( PhabricatorPolicyInterface )----------------------------------------- */
public function getCapabilities() {
return array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
);
}
public function getPolicy($capability) {
return $this->getRepository()->getPolicy($capability);
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
return $this->getRepository()->hasAutomaticCapability($capability, $viewer);
}
public function describeAutomaticCapability($capability) {
return null;
}
}

View file

@ -1784,6 +1784,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'php', 'type' => 'php',
'name' => $this->getPatchPath('20131121.repocredentials.2.mig.php'), 'name' => $this->getPatchPath('20131121.repocredentials.2.mig.php'),
), ),
'20131122.repomirror.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20131122.repomirror.sql'),
),
); );
} }
} }