2011-02-05 21:20:18 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DifferentialDiffCreateController extends DifferentialController {
|
2011-02-05 21:20:18 +01:00
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
$request = $this->getRequest();
|
|
|
|
|
2013-07-03 19:32:02 +02:00
|
|
|
$errors = array();
|
|
|
|
$e_diff = null;
|
|
|
|
$e_file = null;
|
2011-02-05 21:20:18 +01:00
|
|
|
if ($request->isFormPost()) {
|
2011-10-19 04:46:52 +02:00
|
|
|
$diff = null;
|
2013-01-09 17:14:17 +01:00
|
|
|
|
|
|
|
if ($request->getFileExists('diff-file')) {
|
2011-10-19 04:46:52 +02:00
|
|
|
$diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']);
|
2013-01-09 17:14:17 +01:00
|
|
|
} else {
|
2011-10-19 04:46:52 +02:00
|
|
|
$diff = $request->getStr('diff');
|
|
|
|
}
|
2011-02-05 21:20:18 +01:00
|
|
|
|
2013-07-03 19:32:02 +02:00
|
|
|
if (!strlen($diff)) {
|
|
|
|
$errors[] = pht(
|
|
|
|
"You can not create an empty diff. Copy/paste a diff, or upload a ".
|
|
|
|
"diff file.");
|
|
|
|
$e_diff = pht('Required');
|
|
|
|
$e_file = pht('Required');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$call = new ConduitCall(
|
|
|
|
'differential.createrawdiff',
|
|
|
|
array(
|
|
|
|
'diff' => $diff,
|
|
|
|
));
|
|
|
|
$call->setUser($request->getUser());
|
|
|
|
$result = $call->execute();
|
2011-02-05 21:20:18 +01:00
|
|
|
|
2013-07-03 19:32:02 +02:00
|
|
|
$path = id(new PhutilURI($result['uri']))->getPath();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($path);
|
|
|
|
}
|
2011-02-05 21:20:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$form = new AphrontFormView();
|
2011-12-02 01:05:54 +01:00
|
|
|
$arcanist_href = PhabricatorEnv::getDoclink(
|
|
|
|
'article/Arcanist_User_Guide.html');
|
2013-01-18 03:57:09 +01:00
|
|
|
$arcanist_link = phutil_tag(
|
2011-12-02 01:05:54 +01:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $arcanist_href,
|
|
|
|
'target' => '_blank',
|
|
|
|
),
|
|
|
|
'Arcanist');
|
2013-07-03 19:32:02 +02:00
|
|
|
|
|
|
|
$cancel_uri = $this->getApplicationURI();
|
|
|
|
|
2011-02-05 21:20:18 +01:00
|
|
|
$form
|
|
|
|
->setAction('/differential/diff/create/')
|
2011-10-19 04:46:52 +02:00
|
|
|
->setEncType('multipart/form-data')
|
2011-02-05 21:20:18 +01:00
|
|
|
->setUser($request->getUser())
|
2013-07-03 19:32:02 +02:00
|
|
|
->appendInstructions(
|
2013-02-07 23:39:04 +01:00
|
|
|
pht(
|
|
|
|
'The best way to create a Differential diff is by using %s, but you '.
|
2013-07-03 19:32:02 +02: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 23:39:04 +01:00
|
|
|
$arcanist_link,
|
|
|
|
phutil_tag('tt', array(), 'svn diff'),
|
2013-07-03 19:32:02 +02:00
|
|
|
phutil_tag('tt', array(), 'git diff'),
|
|
|
|
phutil_tag('tt', array(), 'hg diff')))
|
2011-02-05 21:20:18 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextAreaControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setLabel(pht('Raw Diff'))
|
2011-02-05 21:20:18 +01:00
|
|
|
->setName('diff')
|
2013-07-03 19:32:02 +02:00
|
|
|
->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)
|
|
|
|
->setError($e_diff))
|
2011-10-19 04:46:52 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormFileControl())
|
2013-07-03 19:32:02 +02:00
|
|
|
->setLabel(pht('Raw Diff From File'))
|
|
|
|
->setName('diff-file')
|
|
|
|
->setError($e_file))
|
2011-02-05 21:20:18 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-07-03 19:32:02 +02:00
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->setValue(pht("Create Diff")));
|
2011-02-05 21:20:18 +01:00
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText(pht('Create New Diff'))
|
|
|
|
->setFormError($errors)
|
|
|
|
->setForm($form);
|
|
|
|
|
2013-03-26 21:15:15 +01:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addCrumb(
|
|
|
|
id(new PhabricatorCrumbView())
|
2013-07-03 19:32:02 +02:00
|
|
|
->setName(pht('Create Diff')));
|
|
|
|
|
|
|
|
if ($errors) {
|
|
|
|
$errors = id(new AphrontErrorView())
|
|
|
|
->setErrors($errors);
|
|
|
|
}
|
2013-03-26 21:15:15 +01:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2013-08-26 20:53:11 +02:00
|
|
|
$form_box,
|
2013-03-26 21:15:15 +01:00
|
|
|
),
|
2011-02-05 21:20:18 +01:00
|
|
|
array(
|
2013-01-24 19:46:47 +01:00
|
|
|
'title' => pht('Create Diff'),
|
2013-03-26 21:15:15 +01:00
|
|
|
'device' => true,
|
2011-02-05 21:20:18 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|