2011-01-24 22:18:41 +01:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DifferentialDiffViewController extends DifferentialController {
|
2011-01-24 22:18:41 +01:00
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
2014-06-10 16:49:42 +02:00
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
2011-01-31 03:52:29 +01:00
|
|
|
$request = $this->getRequest();
|
2013-07-01 21:37:54 +02:00
|
|
|
$viewer = $request->getUser();
|
2011-01-31 03:52:29 +01:00
|
|
|
|
2013-07-01 21:38:42 +02:00
|
|
|
$diff = id(new DifferentialDiffQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
2011-01-24 22:18:41 +01:00
|
|
|
if (!$diff) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-02-02 05:14:56 +01:00
|
|
|
$error_view = id(new PHUIErrorView())
|
|
|
|
->setSeverity(PHUIErrorView::SEVERITY_NOTICE);
|
2011-05-03 02:44:47 +02:00
|
|
|
if ($diff->getRevisionID()) {
|
2014-01-13 21:17:37 +01:00
|
|
|
$error_view->appendChild(
|
2013-07-01 21:37:54 +02:00
|
|
|
pht(
|
|
|
|
'This diff belongs to revision %s.',
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/D'.$diff->getRevisionID(),
|
|
|
|
),
|
|
|
|
'D'.$diff->getRevisionID())));
|
2011-05-03 02:44:47 +02:00
|
|
|
} else {
|
2013-07-01 21:37:54 +02:00
|
|
|
// TODO: implement optgroup support in AphrontFormSelectControl?
|
2011-05-03 02:44:47 +02:00
|
|
|
$select = array();
|
2013-02-05 23:30:29 +01:00
|
|
|
$select[] = hsprintf('<optgroup label="%s">', pht('Create New Revision'));
|
2013-11-11 18:23:23 +01:00
|
|
|
$select[] = phutil_tag(
|
|
|
|
'option',
|
|
|
|
array('value' => ''),
|
2013-02-05 23:30:29 +01:00
|
|
|
pht('Create a new Revision...'));
|
|
|
|
$select[] = hsprintf('</optgroup>');
|
2011-02-04 00:41:58 +01:00
|
|
|
|
2013-07-01 21:37:54 +02:00
|
|
|
$revisions = id(new DifferentialRevisionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withAuthors(array($viewer->getPHID()))
|
|
|
|
->withStatus(DifferentialRevisionQuery::STATUS_OPEN)
|
|
|
|
->execute();
|
2011-05-03 02:44:47 +02:00
|
|
|
|
|
|
|
if ($revisions) {
|
2013-02-05 23:30:29 +01:00
|
|
|
$select[] = hsprintf(
|
|
|
|
'<optgroup label="%s">',
|
|
|
|
pht('Update Existing Revision'));
|
2011-05-03 02:44:47 +02:00
|
|
|
foreach ($revisions as $revision) {
|
2013-01-18 03:43:35 +01:00
|
|
|
$select[] = phutil_tag(
|
2011-05-03 02:44:47 +02:00
|
|
|
'option',
|
|
|
|
array(
|
|
|
|
'value' => $revision->getID(),
|
|
|
|
),
|
2014-08-30 00:15:13 +02:00
|
|
|
id(new PhutilUTF8StringTruncator())
|
|
|
|
->setMaximumGlyphs(128)
|
|
|
|
->truncateString(
|
|
|
|
'D'.$revision->getID().' '.$revision->getTitle()));
|
2011-05-03 02:44:47 +02:00
|
|
|
}
|
2013-02-05 23:30:29 +01:00
|
|
|
$select[] = hsprintf('</optgroup>');
|
2011-05-03 02:44:47 +02:00
|
|
|
}
|
|
|
|
|
2013-02-05 23:30:29 +01:00
|
|
|
$select = phutil_tag(
|
|
|
|
'select',
|
|
|
|
array('name' => 'revisionID'),
|
|
|
|
$select);
|
2011-05-03 02:44:47 +02:00
|
|
|
|
2013-07-01 21:37:54 +02:00
|
|
|
$form = id(new AphrontFormView())
|
2011-05-03 02:44:47 +02:00
|
|
|
->setUser($request->getUser())
|
|
|
|
->setAction('/differential/revision/edit/')
|
|
|
|
->addHiddenInput('diffID', $diff->getID())
|
|
|
|
->addHiddenInput('viaDiffView', 1)
|
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 20:11:09 +01:00
|
|
|
->addHiddenInput(
|
|
|
|
id(new DifferentialRepositoryField())->getFieldKey(),
|
|
|
|
$diff->getRepositoryPHID())
|
2013-07-01 21:37:54 +02:00
|
|
|
->appendRemarkupInstructions(
|
|
|
|
pht(
|
|
|
|
'Review the diff for correctness. When you are satisfied, either '.
|
|
|
|
'**create a new revision** or **update an existing revision**.'))
|
2011-05-03 02:44:47 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormMarkupControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setLabel(pht('Attach To'))
|
2011-02-04 00:41:58 +01:00
|
|
|
->setValue($select))
|
2011-05-03 02:44:47 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-01-24 19:46:47 +01:00
|
|
|
->setValue(pht('Continue')));
|
2011-01-26 00:19:06 +01:00
|
|
|
|
2014-01-13 21:17:37 +01:00
|
|
|
$error_view->appendChild($form);
|
2011-05-03 02:44:47 +02:00
|
|
|
}
|
2011-01-26 00:19:06 +01:00
|
|
|
|
2012-11-16 20:48:17 +01:00
|
|
|
$props = id(new DifferentialDiffProperty())->loadAllWhere(
|
|
|
|
'diffID = %d',
|
|
|
|
$diff->getID());
|
|
|
|
$props = mpull($props, 'getData', 'getName');
|
|
|
|
|
2013-09-17 18:12:37 +02:00
|
|
|
$property_head = id(new PHUIHeaderView())
|
2013-07-01 21:37:54 +02:00
|
|
|
->setHeader(pht('Properties'));
|
|
|
|
|
2013-10-11 16:53:56 +02:00
|
|
|
$property_view = new PHUIPropertyListView();
|
2012-11-16 20:48:17 +01:00
|
|
|
|
2011-01-24 22:18:41 +01:00
|
|
|
$changesets = $diff->loadChangesets();
|
|
|
|
$changesets = msort($changesets, 'getSortKey');
|
|
|
|
|
|
|
|
$table_of_contents = id(new DifferentialDiffTableOfContentsView())
|
2012-03-15 18:45:35 +01:00
|
|
|
->setChangesets($changesets)
|
2012-11-07 00:33:56 +01:00
|
|
|
->setVisibleChangesets($changesets)
|
2012-11-19 23:52:01 +01:00
|
|
|
->setUnitTestData(idx($props, 'arc:unit', array()));
|
2011-01-24 22:18:41 +01:00
|
|
|
|
2011-05-13 21:27:12 +02:00
|
|
|
$refs = array();
|
|
|
|
foreach ($changesets as $changeset) {
|
|
|
|
$refs[$changeset->getID()] = $changeset->getID();
|
|
|
|
}
|
|
|
|
|
2011-01-25 20:57:47 +01:00
|
|
|
$details = id(new DifferentialChangesetListView())
|
2011-05-13 21:27:12 +02:00
|
|
|
->setChangesets($changesets)
|
2012-05-01 21:09:50 +02:00
|
|
|
->setVisibleChangesets($changesets)
|
2012-01-16 20:08:54 +01:00
|
|
|
->setRenderingReferences($refs)
|
2012-04-13 07:08:44 +02:00
|
|
|
->setStandaloneURI('/differential/changeset/')
|
2012-12-13 06:21:56 +01:00
|
|
|
->setDiff($diff)
|
2013-01-24 19:46:47 +01:00
|
|
|
->setTitle(pht('Diff %d', $diff->getID()))
|
2012-01-16 20:08:54 +01:00
|
|
|
->setUser($request->getUser());
|
2011-01-24 22:18:41 +01:00
|
|
|
|
2013-07-01 21:37:54 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Diff %d', $diff->getID()));
|
2013-07-01 21:37:54 +02:00
|
|
|
|
2014-01-13 21:17:37 +01:00
|
|
|
$prop_box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($property_head)
|
|
|
|
->addPropertyList($property_view)
|
|
|
|
->setErrorView($error_view);
|
|
|
|
|
2013-07-01 21:37:54 +02:00
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
2014-01-13 21:17:37 +01:00
|
|
|
$prop_box,
|
2013-07-01 21:37:54 +02:00
|
|
|
$table_of_contents,
|
|
|
|
$details,
|
|
|
|
),
|
2011-01-24 22:18:41 +01:00
|
|
|
array(
|
2013-01-24 19:46:47 +01:00
|
|
|
'title' => pht('Diff View'),
|
2011-01-24 22:18:41 +01:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|