mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-06 04:41:01 +01:00
016b62a7ef
Summary: Ref T2784. This one was a wee bit complicated. Had to add PhabricatorUser and concept of initFromConduit (or not) to DiffusionRequest. Test Plan: foreach repo, visited CALLSIGN and clicked a commit and verified they laoded correctly. Hacked code to hit NOT via Conduit and repeated tests to great success. Reviewers: epriestley Reviewed By: epriestley CC: chad, aran, Korvin Maniphest Tasks: T2784 Differential Revision: https://secure.phabricator.com/D5928
100 lines
3.1 KiB
PHP
100 lines
3.1 KiB
PHP
<?php
|
|
|
|
final class DiffusionCommitEditController extends DiffusionController {
|
|
|
|
public function willProcessRequest(array $data) {
|
|
$data['user'] = $this->getRequest()->getUser();
|
|
$this->diffusionRequest = DiffusionRequest::newFromDictionary($data);
|
|
}
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
$user = $request->getUser();
|
|
$drequest = $this->getDiffusionRequest();
|
|
$callsign = $drequest->getRepository()->getCallsign();
|
|
$repository = $drequest->getRepository();
|
|
$commit = $drequest->loadCommit();
|
|
$page_title = pht('Edit Diffusion Commit');
|
|
|
|
if (!$commit) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$commit_phid = $commit->getPHID();
|
|
$edge_type = PhabricatorEdgeConfig::TYPE_COMMIT_HAS_PROJECT;
|
|
$current_proj_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
$commit_phid,
|
|
$edge_type);
|
|
$handles = $this->loadViewerHandles($current_proj_phids);
|
|
$proj_t_values = mpull($handles, 'getFullName', 'getPHID');
|
|
|
|
if ($request->isFormPost()) {
|
|
$proj_phids = $request->getArr('projects');
|
|
$new_proj_phids = array_values($proj_phids);
|
|
$rem_proj_phids = array_diff($current_proj_phids,
|
|
$new_proj_phids);
|
|
$editor = id(new PhabricatorEdgeEditor());
|
|
$editor->setActor($user);
|
|
foreach ($rem_proj_phids as $phid) {
|
|
$editor->removeEdge($commit_phid, $edge_type, $phid);
|
|
}
|
|
foreach ($new_proj_phids as $phid) {
|
|
$editor->addEdge($commit_phid, $edge_type, $phid);
|
|
}
|
|
$editor->save();
|
|
|
|
id(new PhabricatorSearchIndexer())
|
|
->indexDocumentByPHID($commit->getPHID());
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI('/r'.$callsign.$commit->getCommitIdentifier());
|
|
}
|
|
|
|
$tokenizer_id = celerity_generate_unique_node_id();
|
|
$form = id(new AphrontFormView())
|
|
->setUser($user)
|
|
->setAction($request->getRequestURI()->getPath())
|
|
->setFlexible(true)
|
|
->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Projects'))
|
|
->setName('projects')
|
|
->setValue($proj_t_values)
|
|
->setID($tokenizer_id)
|
|
->setCaption(
|
|
javelin_tag(
|
|
'a',
|
|
array(
|
|
'href' => '/project/create/',
|
|
'mustcapture' => true,
|
|
'sigil' => 'project-create',
|
|
),
|
|
pht('Create New Project')))
|
|
->setDatasource('/typeahead/common/projects/'));;
|
|
|
|
Javelin::initBehavior('project-create', array(
|
|
'tokenizerID' => $tokenizer_id,
|
|
));
|
|
|
|
$submit = id(new AphrontFormSubmitControl())
|
|
->setValue(pht('Save'))
|
|
->addCancelButton('/r'.$callsign.$commit->getCommitIdentifier());
|
|
$form->appendChild($submit);
|
|
|
|
$header = new PhabricatorHeaderView();
|
|
$header->setHeader(pht('Edit Diffusion Commit'));
|
|
|
|
return $this->buildApplicationPage(
|
|
array(
|
|
$header,
|
|
$form,
|
|
),
|
|
array(
|
|
'title' => $page_title,
|
|
'device' => true,
|
|
'dust' => true,
|
|
));
|
|
}
|
|
|
|
}
|