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
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
2014-11-19 12:16:07 -08:00
|
|
|
$viewer = $request->getUser();
|
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(
|
2014-06-09 11:36:49 -07:00
|
|
|
'You can not create an empty diff. Copy/paste a diff, or upload a '.
|
|
|
|
|
'diff file.');
|
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();
|
|
|
|
|
$path = id(new PhutilURI($result['uri']))->getPath();
|
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($path);
|
|
|
|
|
} 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',
|
|
|
|
|
),
|
|
|
|
|
'Arcanist');
|
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();
|
|
|
|
|
|
2011-02-05 12:20:18 -08:00
|
|
|
$form
|
|
|
|
|
->setAction('/differential/diff/create/')
|
2011-10-18 19:46:52 -07:00
|
|
|
->setEncType('multipart/form-data')
|
2014-11-19 12:16:07 -08:00
|
|
|
->setUser($viewer)
|
2013-07-03 10:32:02 -07:00
|
|
|
->appendInstructions(
|
2013-02-07 14:39:04 -08:00
|
|
|
pht(
|
|
|
|
|
'The best way to create a Differential diff is by using %s, but you '.
|
2013-07-03 10:32:02 -07:00
|
|
|
'can also just paste a diff (for example, from %s, %s or %s) into '.
|
|
|
|
|
'this box, or upload a diff file.',
|
2013-02-07 14:39:04 -08:00
|
|
|
$arcanist_link,
|
|
|
|
|
phutil_tag('tt', array(), 'svn diff'),
|
2013-07-03 10:32:02 -07:00
|
|
|
phutil_tag('tt', array(), 'git diff'),
|
2013-11-19 16:52:35 -08:00
|
|
|
phutil_tag('tt', array(), 'hg diff --git')))
|
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)
|
2014-06-09 11:36:49 -07:00
|
|
|
->setValue(pht('Create Diff')));
|
2011-02-05 12:20:18 -08:00
|
|
|
|
2013-09-25 11:23:29 -07:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 11:53:11 -07:00
|
|
|
->setHeaderText(pht('Create New Diff'))
|
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
|
|
|
|
2014-01-09 08:51:57 -08:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
$crumbs->addTextCrumb(pht('Create Diff'));
|
|
|
|
|
|
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(
|
2013-01-24 10:46:47 -08:00
|
|
|
'title' => pht('Create Diff'),
|
2011-02-05 12:20:18 -08:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|