2016-12-13 12:11:17 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialRevisionEditEngine
|
|
|
|
extends PhabricatorEditEngine {
|
|
|
|
|
2016-12-14 05:34:50 -08:00
|
|
|
private $diff;
|
|
|
|
|
2016-12-13 12:11:17 -08:00
|
|
|
const ENGINECONST = 'differential.revision';
|
|
|
|
|
2016-12-16 04:45:55 -08:00
|
|
|
const KEY_UPDATE = 'update';
|
|
|
|
|
2016-12-13 12:11:17 -08:00
|
|
|
public function getEngineName() {
|
|
|
|
return pht('Revisions');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummaryHeader() {
|
|
|
|
return pht('Configure Revision Forms');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSummaryText() {
|
|
|
|
return pht(
|
|
|
|
'Configure creation and editing revision forms in Differential.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEngineApplicationClass() {
|
|
|
|
return 'PhabricatorDifferentialApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function supportsEditEngineConfiguration() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newEditableObject() {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
return DifferentialRevision::initializeNewRevision($viewer);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function newObjectQuery() {
|
2016-12-13 15:46:46 -08:00
|
|
|
return id(new DifferentialRevisionQuery())
|
2016-12-14 05:34:50 -08:00
|
|
|
->needActiveDiffs(true)
|
2016-12-29 10:35:47 -08:00
|
|
|
->needReviewerStatus(true)
|
|
|
|
->needReviewerAuthority(true);
|
2016-12-13 12:11:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateTitleText($object) {
|
|
|
|
return pht('Create New Revision');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectEditTitleText($object) {
|
2016-12-14 05:34:50 -08:00
|
|
|
$monogram = $object->getMonogram();
|
|
|
|
$title = $object->getTitle();
|
|
|
|
|
|
|
|
$diff = $this->getDiff();
|
|
|
|
if ($diff) {
|
|
|
|
return pht('Update Revision %s: %s', $monogram, $title);
|
|
|
|
} else {
|
|
|
|
return pht('Edit Revision %s: %s', $monogram, $title);
|
|
|
|
}
|
2016-12-13 12:11:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectEditShortText($object) {
|
|
|
|
return $object->getMonogram();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectCreateShortText() {
|
|
|
|
return pht('Create Revision');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectName() {
|
|
|
|
return pht('Revision');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getObjectViewURI($object) {
|
|
|
|
return $object->getURI();
|
|
|
|
}
|
|
|
|
|
2016-12-28 09:49:24 -08:00
|
|
|
protected function getEditorURI() {
|
|
|
|
return $this->getApplication()->getApplicationURI('revision/edit/');
|
|
|
|
}
|
|
|
|
|
2016-12-14 05:34:50 -08:00
|
|
|
public function setDiff(DifferentialDiff $diff) {
|
|
|
|
$this->diff = $diff;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDiff() {
|
|
|
|
return $this->diff;
|
|
|
|
}
|
|
|
|
|
2016-12-13 12:11:17 -08:00
|
|
|
protected function buildCustomEditFields($object) {
|
2016-12-28 10:21:54 -08:00
|
|
|
$viewer = $this->getViewer();
|
2016-12-13 15:24:55 -08:00
|
|
|
|
|
|
|
$plan_required = PhabricatorEnv::getEnvConfig(
|
|
|
|
'differential.require-test-plan-field');
|
|
|
|
$plan_enabled = $this->isCustomFieldEnabled(
|
|
|
|
$object,
|
|
|
|
'differential:test-plan');
|
|
|
|
|
2016-12-14 05:34:50 -08:00
|
|
|
$diff = $this->getDiff();
|
|
|
|
if ($diff) {
|
|
|
|
$diff_phid = $diff->getPHID();
|
|
|
|
} else {
|
|
|
|
$diff_phid = null;
|
|
|
|
}
|
|
|
|
|
2016-12-13 15:39:10 -08:00
|
|
|
$is_create = $this->getIsCreate();
|
|
|
|
$is_update = ($diff && !$is_create);
|
2016-12-14 05:34:50 -08:00
|
|
|
|
2016-12-13 15:24:55 -08:00
|
|
|
$fields = array();
|
2016-12-14 05:34:50 -08:00
|
|
|
|
2016-12-16 04:45:55 -08:00
|
|
|
$fields[] = id(new PhabricatorHandlesEditField())
|
|
|
|
->setKey(self::KEY_UPDATE)
|
|
|
|
->setLabel(pht('Update Diff'))
|
|
|
|
->setDescription(pht('New diff to create or update the revision with.'))
|
|
|
|
->setConduitDescription(pht('Create or update a revision with a diff.'))
|
|
|
|
->setConduitTypeDescription(pht('PHID of the diff.'))
|
|
|
|
->setTransactionType(DifferentialTransaction::TYPE_UPDATE)
|
|
|
|
->setHandleParameterType(new AphrontPHIDListHTTPParameterType())
|
|
|
|
->setSingleValue($diff_phid)
|
|
|
|
->setIsConduitOnly(!$diff)
|
|
|
|
->setIsReorderable(false)
|
|
|
|
->setIsDefaultable(false)
|
|
|
|
->setIsInvisible(true)
|
|
|
|
->setIsLockable(false);
|
2016-12-14 05:34:50 -08:00
|
|
|
|
|
|
|
if ($is_update) {
|
|
|
|
$fields[] = id(new PhabricatorInstructionsEditField())
|
|
|
|
->setKey('update.help')
|
|
|
|
->setValue(pht('Describe the updates you have made to the diff.'));
|
|
|
|
$fields[] = id(new PhabricatorCommentEditField())
|
|
|
|
->setKey('update.comment')
|
|
|
|
->setLabel(pht('Comment'))
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->setIsWebOnly(true)
|
|
|
|
->setDescription(pht('Comments providing context for the update.'));
|
|
|
|
$fields[] = id(new PhabricatorSubmitEditField())
|
|
|
|
->setKey('update.submit')
|
|
|
|
->setValue($this->getObjectEditButtonText($object));
|
|
|
|
$fields[] = id(new PhabricatorDividerEditField())
|
|
|
|
->setKey('update.note');
|
|
|
|
}
|
|
|
|
|
2016-12-13 15:24:55 -08:00
|
|
|
$fields[] = id(new PhabricatorTextEditField())
|
2016-12-16 04:45:55 -08:00
|
|
|
->setKey(DifferentialRevisionTitleTransaction::EDITKEY)
|
2016-12-13 15:24:55 -08:00
|
|
|
->setLabel(pht('Title'))
|
|
|
|
->setIsRequired(true)
|
|
|
|
->setTransactionType(
|
|
|
|
DifferentialRevisionTitleTransaction::TRANSACTIONTYPE)
|
|
|
|
->setDescription(pht('The title of the revision.'))
|
|
|
|
->setConduitDescription(pht('Retitle the revision.'))
|
|
|
|
->setConduitTypeDescription(pht('New revision title.'))
|
|
|
|
->setValue($object->getTitle());
|
|
|
|
|
|
|
|
$fields[] = id(new PhabricatorRemarkupEditField())
|
2016-12-16 04:45:55 -08:00
|
|
|
->setKey(DifferentialRevisionSummaryTransaction::EDITKEY)
|
2016-12-13 15:24:55 -08:00
|
|
|
->setLabel(pht('Summary'))
|
|
|
|
->setTransactionType(
|
|
|
|
DifferentialRevisionSummaryTransaction::TRANSACTIONTYPE)
|
|
|
|
->setDescription(pht('The summary of the revision.'))
|
|
|
|
->setConduitDescription(pht('Change the revision summary.'))
|
|
|
|
->setConduitTypeDescription(pht('New revision summary.'))
|
|
|
|
->setValue($object->getSummary());
|
|
|
|
|
|
|
|
if ($plan_enabled) {
|
|
|
|
$fields[] = id(new PhabricatorRemarkupEditField())
|
2016-12-16 04:45:55 -08:00
|
|
|
->setKey(DifferentialRevisionTestPlanTransaction::EDITKEY)
|
2016-12-13 15:24:55 -08:00
|
|
|
->setLabel(pht('Test Plan'))
|
|
|
|
->setIsRequired($plan_required)
|
2016-12-13 15:01:52 -08:00
|
|
|
->setTransactionType(
|
2016-12-13 15:24:55 -08:00
|
|
|
DifferentialRevisionTestPlanTransaction::TRANSACTIONTYPE)
|
|
|
|
->setDescription(
|
|
|
|
pht('Actions performed to verify the behavior of the change.'))
|
|
|
|
->setConduitDescription(pht('Update the revision test plan.'))
|
|
|
|
->setConduitTypeDescription(pht('New test plan.'))
|
|
|
|
->setValue($object->getTestPlan());
|
|
|
|
}
|
|
|
|
|
2016-12-13 15:46:46 -08:00
|
|
|
$fields[] = id(new PhabricatorDatasourceEditField())
|
2016-12-16 04:45:55 -08:00
|
|
|
->setKey(DifferentialRevisionReviewersTransaction::EDITKEY)
|
2016-12-13 15:46:46 -08:00
|
|
|
->setLabel(pht('Reviewers'))
|
|
|
|
->setDatasource(new DifferentialReviewerDatasource())
|
|
|
|
->setUseEdgeTransactions(true)
|
|
|
|
->setTransactionType(
|
|
|
|
DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE)
|
2016-12-28 10:21:54 -08:00
|
|
|
->setCommentActionLabel(pht('Change Reviewers'))
|
2016-12-13 15:46:46 -08:00
|
|
|
->setDescription(pht('Reviewers for this revision.'))
|
|
|
|
->setConduitDescription(pht('Change the reviewers for this revision.'))
|
|
|
|
->setConduitTypeDescription(pht('New reviewers.'))
|
|
|
|
->setValue($object->getReviewerPHIDsForEdit());
|
|
|
|
|
2016-12-13 15:24:55 -08:00
|
|
|
$fields[] = id(new PhabricatorDatasourceEditField())
|
|
|
|
->setKey('repositoryPHID')
|
|
|
|
->setLabel(pht('Repository'))
|
|
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
|
|
->setTransactionType(
|
|
|
|
DifferentialRevisionRepositoryTransaction::TRANSACTIONTYPE)
|
|
|
|
->setDescription(pht('The repository the revision belongs to.'))
|
|
|
|
->setConduitDescription(pht('Change the repository for this revision.'))
|
|
|
|
->setConduitTypeDescription(pht('New repository.'))
|
|
|
|
->setSingleValue($object->getRepositoryPHID());
|
|
|
|
|
2016-12-16 09:57:10 -08:00
|
|
|
// This is a little flimsy, but allows "Maniphest Tasks: ..." to continue
|
|
|
|
// working properly in commit messages until we fully sort out T5873.
|
|
|
|
$fields[] = id(new PhabricatorHandlesEditField())
|
|
|
|
->setKey('tasks')
|
|
|
|
->setUseEdgeTransactions(true)
|
|
|
|
->setIsConduitOnly(true)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue(
|
|
|
|
'edge:type',
|
|
|
|
DifferentialRevisionHasTaskEdgeType::EDGECONST)
|
|
|
|
->setDescription(pht('Tasks associated with this revision.'))
|
|
|
|
->setConduitDescription(pht('Change associated tasks.'))
|
|
|
|
->setConduitTypeDescription(pht('List of tasks.'))
|
|
|
|
->setValue(array());
|
|
|
|
|
2016-12-28 10:21:54 -08:00
|
|
|
$actions = DifferentialRevisionActionTransaction::loadAllActions();
|
|
|
|
foreach ($actions as $key => $action) {
|
|
|
|
$fields[] = $action->newEditField($object, $viewer);
|
|
|
|
}
|
|
|
|
|
2016-12-13 15:24:55 -08:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function isCustomFieldEnabled(DifferentialRevision $revision, $key) {
|
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$revision,
|
2016-12-13 15:39:10 -08:00
|
|
|
PhabricatorCustomField::ROLE_VIEW);
|
2016-12-13 15:24:55 -08:00
|
|
|
|
|
|
|
$fields = $field_list->getFields();
|
|
|
|
return isset($fields[$key]);
|
2016-12-13 12:11:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|