2011-02-05 12:20:18 -08:00
|
|
|
<?php
|
|
|
|
|
|
2012-03-09 15:46:25 -08:00
|
|
|
final class DifferentialDiffCreateController extends DifferentialController {
|
2011-02-05 12:20:18 -08:00
|
|
|
|
2015-03-23 10:44:33 -07:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
|
|
// If we're on the "Update Diff" workflow, load the revision we're going
|
|
|
|
|
// to update.
|
|
|
|
|
$revision = null;
|
|
|
|
|
$revision_id = $request->getURIData('revisionID');
|
|
|
|
|
if ($revision_id) {
|
|
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->withIDs(array($revision_id))
|
|
|
|
|
->requireCapabilities(
|
|
|
|
|
array(
|
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
|
))
|
|
|
|
|
->executeOne();
|
|
|
|
|
if (!$revision) {
|
|
|
|
|
return new Aphront404Response();
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-05 12:20:18 -08:00
|
|
|
|
2014-11-18 15:32:23 -08:00
|
|
|
$diff = null;
|
2014-11-19 12:16:07 -08:00
|
|
|
// This object is just for policy stuff
|
|
|
|
|
$diff_object = DifferentialDiff::initializeNewDiff($viewer);
|
Differential - refine selecting a repository diff --> revision workflow
Summary: Fixes T6200. Ref T6237. When creating a diff from the web view, allow the user to select the repository at that time. When viewing a diff that has no associated revision and then creating a revision, pass along the repository phid to the create revision controller. Within the create revision controller, default the repository selector to this repository phid. Finally, in the editor, stop aggressively resetting the repository phid for every TYPE_UPDATE; rather, do so if its not a new object -- the diff should reign supreme in that case -- or if there's no repository -- let the diff be the guide.
Test Plan:
- made a diff with an associated repo, made a revision from the diff, saw the associated repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo to nothing and it stuck on save!
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T6237, T6200
Differential Revision: https://secure.phabricator.com/D10872
2014-11-19 11:11:09 -08:00
|
|
|
$repository_phid = null;
|
|
|
|
|
$repository_value = array();
|
2013-07-03 10:32:02 -07:00
|
|
|
$errors = array();
|
|
|
|
|
$e_diff = null;
|
|
|
|
|
$e_file = null;
|
2014-11-18 15:32:23 -08:00
|
|
|
$validation_exception = null;
|
2011-02-05 12:20:18 -08:00
|
|
|
if ($request->isFormPost()) {
|
2013-01-09 08:14:17 -08:00
|
|
|
|
Differential - refine selecting a repository diff --> revision workflow
Summary: Fixes T6200. Ref T6237. When creating a diff from the web view, allow the user to select the repository at that time. When viewing a diff that has no associated revision and then creating a revision, pass along the repository phid to the create revision controller. Within the create revision controller, default the repository selector to this repository phid. Finally, in the editor, stop aggressively resetting the repository phid for every TYPE_UPDATE; rather, do so if its not a new object -- the diff should reign supreme in that case -- or if there's no repository -- let the diff be the guide.
Test Plan:
- made a diff with an associated repo, made a revision from the diff, saw the associated repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo to nothing and it stuck on save!
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T6237, T6200
Differential Revision: https://secure.phabricator.com/D10872
2014-11-19 11:11:09 -08:00
|
|
|
$repository_tokenizer = $request->getArr(
|
|
|
|
|
id(new DifferentialRepositoryField())->getFieldKey());
|
|
|
|
|
if ($repository_tokenizer) {
|
|
|
|
|
$repository_phid = reset($repository_tokenizer);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-09 08:14:17 -08:00
|
|
|
if ($request->getFileExists('diff-file')) {
|
2011-10-18 19:46:52 -07:00
|
|
|
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
|
2013-01-09 08:14:17 -08:00
|
|
|
} else {
|
2011-10-18 19:46:52 -07:00
|
|
|
$diff = $request->getStr('diff');
|
|
|
|
|
}
|
2011-02-05 12:20:18 -08:00
|
|
|
|
2013-07-03 10:32:02 -07:00
|
|
|
if (!strlen($diff)) {
|
|
|
|
|
$errors[] = pht(
|
2015-03-23 10:44:33 -07:00
|
|
|
'You can not create an empty diff. Paste a diff or upload a '.
|
|
|
|
|
'file containing a diff.');
|
2013-07-03 10:32:02 -07:00
|
|
|
$e_diff = pht('Required');
|
|
|
|
|
$e_file = pht('Required');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$errors) {
|
2014-11-18 15:32:23 -08:00
|
|
|
try {
|
|
|
|
|
$call = new ConduitCall(
|
|
|
|
|
'differential.createrawdiff',
|
|
|
|
|
array(
|
|
|
|
|
'diff' => $diff,
|
2014-11-19 12:16:07 -08:00
|
|
|
'repositoryPHID' => $repository_phid,
|
|
|
|
|
'viewPolicy' => $request->getStr('viewPolicy'),));
|
|
|
|
|
$call->setUser($viewer);
|
2014-11-18 15:32:23 -08:00
|
|
|
$result = $call->execute();
|
2015-03-23 10:44:33 -07:00
|
|
|
|
|
|
|
|
$diff_id = $result['id'];
|
|
|
|
|
|
|
|
|
|
$uri = $this->getApplicationURI("diff/{$diff_id}/");
|
|
|
|
|
$uri = new PhutilURI($uri);
|
|
|
|
|
if ($revision) {
|
|
|
|
|
$uri->setQueryParam('revisionID', $revision->getID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($uri);
|
2014-11-18 15:32:23 -08:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
|
$validation_exception = $ex;
|
|
|
|
|
}
|
2013-07-03 10:32:02 -07:00
|
|
|
}
|
2011-02-05 12:20:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
2014-03-17 15:01:31 -07:00
|
|
|
$arcanist_href = PhabricatorEnv::getDoclink('Arcanist User Guide');
|
2013-01-17 18:57:09 -08:00
|
|
|
$arcanist_link = phutil_tag(
|
2011-12-01 16:05:54 -08:00
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => $arcanist_href,
|
|
|
|
|
'target' => '_blank',
|
|
|
|
|
),
|
2015-03-23 10:44:33 -07:00
|
|
|
'Learn More');
|
2013-07-03 10:32:02 -07:00
|
|
|
|
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
|
|
|
|
|
Differential - refine selecting a repository diff --> revision workflow
Summary: Fixes T6200. Ref T6237. When creating a diff from the web view, allow the user to select the repository at that time. When viewing a diff that has no associated revision and then creating a revision, pass along the repository phid to the create revision controller. Within the create revision controller, default the repository selector to this repository phid. Finally, in the editor, stop aggressively resetting the repository phid for every TYPE_UPDATE; rather, do so if its not a new object -- the diff should reign supreme in that case -- or if there's no repository -- let the diff be the guide.
Test Plan:
- made a diff with an associated repo, made a revision from the diff, saw the associated repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo to nothing and it stuck on save!
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T6237, T6200
Differential Revision: https://secure.phabricator.com/D10872
2014-11-19 11:11:09 -08:00
|
|
|
if ($repository_phid) {
|
|
|
|
|
$repository_value = $this->loadViewerHandles(array($repository_phid));
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 12:16:07 -08:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
|
->setViewer($viewer)
|
|
|
|
|
->setObject($diff_object)
|
|
|
|
|
->execute();
|
|
|
|
|
|
2015-03-23 10:44:33 -07:00
|
|
|
$info_view = null;
|
|
|
|
|
if (!$request->isFormPost()) {
|
|
|
|
|
$info_view = id(new PHUIInfoView())
|
|
|
|
|
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
|
|
|
|
|
->setErrors(
|
|
|
|
|
array(
|
|
|
|
|
array(
|
|
|
|
|
pht(
|
|
|
|
|
'The best way to create a diff is to use the Arcanist '.
|
|
|
|
|
'command-line tool.'),
|
|
|
|
|
' ',
|
|
|
|
|
$arcanist_link,
|
|
|
|
|
),
|
|
|
|
|
pht(
|
|
|
|
|
'You can also paste a diff below, or upload a file '.
|
|
|
|
|
'containing a diff (for example, from %s, %s or %s).',
|
|
|
|
|
phutil_tag('tt', array(), 'svn diff'),
|
|
|
|
|
phutil_tag('tt', array(), 'git diff'),
|
|
|
|
|
phutil_tag('tt', array(), 'hg diff --git')),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($revision) {
|
|
|
|
|
$title = pht('Update Diff');
|
|
|
|
|
$header = pht('Update Diff');
|
|
|
|
|
$button = pht('Continue');
|
|
|
|
|
} else {
|
|
|
|
|
$title = pht('Create Diff');
|
|
|
|
|
$header = pht('Create New Diff');
|
|
|
|
|
$button = pht('Create Diff');
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-05 12:20:18 -08:00
|
|
|
$form
|
2011-10-18 19:46:52 -07:00
|
|
|
->setEncType('multipart/form-data')
|
2015-03-23 10:44:33 -07:00
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
|
|
if ($revision) {
|
|
|
|
|
$revision_handles = $this->loadViewerHandles(array($revision->getPHID()));
|
|
|
|
|
$revision_handle = head($revision_handles);
|
|
|
|
|
|
|
|
|
|
$form->appendChild(
|
|
|
|
|
id(new AphrontFormMarkupControl())
|
|
|
|
|
->setLabel(pht('Updating Revision'))
|
|
|
|
|
->setValue($revision_handle->renderLink()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$form
|
2011-02-05 12:20:18 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-01-24 10:46:47 -08:00
|
|
|
->setLabel(pht('Raw Diff'))
|
2011-02-05 12:20:18 -08:00
|
|
|
->setName('diff')
|
2014-11-18 15:32:23 -08:00
|
|
|
->setValue($diff)
|
2013-07-03 10:32:02 -07:00
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
|
|
|
|
->setError($e_diff))
|
2011-10-18 19:46:52 -07:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormFileControl())
|
2013-07-03 10:32:02 -07:00
|
|
|
->setLabel(pht('Raw Diff From File'))
|
|
|
|
|
->setName('diff-file')
|
|
|
|
|
->setError($e_file))
|
Differential - refine selecting a repository diff --> revision workflow
Summary: Fixes T6200. Ref T6237. When creating a diff from the web view, allow the user to select the repository at that time. When viewing a diff that has no associated revision and then creating a revision, pass along the repository phid to the create revision controller. Within the create revision controller, default the repository selector to this repository phid. Finally, in the editor, stop aggressively resetting the repository phid for every TYPE_UPDATE; rather, do so if its not a new object -- the diff should reign supreme in that case -- or if there's no repository -- let the diff be the guide.
Test Plan:
- made a diff with an associated repo, made a revision from the diff, saw the associated repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo and it stuck on save!
- made a diff with an associated repo, made a revision from the diff but changed the repo to nothing and it stuck on save!
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T6237, T6200
Differential Revision: https://secure.phabricator.com/D10872
2014-11-19 11:11:09 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
|
->setName(id(new DifferentialRepositoryField())->getFieldKey())
|
|
|
|
|
->setLabel(pht('Repository'))
|
|
|
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
|
|
|
->setValue($repository_value)
|
|
|
|
|
->setLimit(1))
|
2014-11-19 12:16:07 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
|
->setUser($viewer)
|
|
|
|
|
->setName('viewPolicy')
|
|
|
|
|
->setPolicyObject($diff_object)
|
|
|
|
|
->setPolicies($policies)
|
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
2011-02-05 12:20:18 -08:00
|
|
|
->appendChild(
|
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-07-03 10:32:02 -07:00
|
|
|
->addCancelButton($cancel_uri)
|
2015-03-23 10:44:33 -07:00
|
|
|
->setValue($button));
|
2011-02-05 12:20:18 -08:00
|
|
|
|
2013-09-25 11:23:29 -07:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2015-03-23 10:44:33 -07:00
|
|
|
->setHeaderText($header)
|
2014-11-18 15:32:23 -08:00
|
|
|
->setValidationException($validation_exception)
|
2014-01-10 09:17:37 -08:00
|
|
|
->setForm($form)
|
|
|
|
|
->setFormErrors($errors);
|
2013-03-26 13:15:15 -07:00
|
|
|
|
2015-03-23 10:44:33 -07:00
|
|
|
if ($info_view) {
|
|
|
|
|
$form_box->setInfoView($info_view);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-09 08:51:57 -08:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2015-03-23 10:44:33 -07:00
|
|
|
if ($revision) {
|
|
|
|
|
$crumbs->addTextCrumb(
|
|
|
|
|
$revision->getMonogram(),
|
|
|
|
|
'/'.$revision->getMonogram());
|
|
|
|
|
}
|
|
|
|
|
$crumbs->addTextCrumb($title);
|
2014-01-09 08:51:57 -08:00
|
|
|
|
2013-03-26 13:15:15 -07:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
|
array(
|
|
|
|
|
$crumbs,
|
2013-08-26 11:53:11 -07:00
|
|
|
$form_box,
|
2013-03-26 13:15:15 -07:00
|
|
|
),
|
2011-02-05 12:20:18 -08:00
|
|
|
array(
|
2015-03-23 10:44:33 -07:00
|
|
|
'title' => $title,
|
2011-02-05 12:20:18 -08:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|