1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Begin adding "pro" modular transaction fields to Differential

Summary:
Ref T11114. Currently, all of Differential is extremely custom CustomFields. I want to back away from that somewhat and leverage more EditEngine / ModularTransactions infrastructure.

This allows EditEngine, ModularTransactions, and CustomFields to coexist in an uneasy peace. The "EditPro" controller applies a //different edit// than the CustomFields do, but everything works out in the end. I think.

Hopefully the horrible mess I am creating here will be short-lived.

Test Plan:
  - Edited a revision with the normal editor.
  - Edited a revision with the pro editor.
  - Created a revision with `arc diff`.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11114

Differential Revision: https://secure.phabricator.com/D17044
This commit is contained in:
epriestley 2016-12-13 13:03:32 -08:00
parent eda64b8549
commit 0906bf547b
6 changed files with 91 additions and 8 deletions

View file

@ -553,6 +553,8 @@ phutil_register_library_map(array(
'DifferentialRevisionStatus' => 'applications/differential/constants/DifferentialRevisionStatus.php',
'DifferentialRevisionSummaryHeraldField' => 'applications/differential/herald/DifferentialRevisionSummaryHeraldField.php',
'DifferentialRevisionTitleHeraldField' => 'applications/differential/herald/DifferentialRevisionTitleHeraldField.php',
'DifferentialRevisionTitleTransaction' => 'applications/differential/xaction/DifferentialRevisionTitleTransaction.php',
'DifferentialRevisionTransactionType' => 'applications/differential/xaction/DifferentialRevisionTransactionType.php',
'DifferentialRevisionUpdateHistoryView' => 'applications/differential/view/DifferentialRevisionUpdateHistoryView.php',
'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php',
'DifferentialSchemaSpec' => 'applications/differential/storage/DifferentialSchemaSpec.php',
@ -5201,6 +5203,8 @@ phutil_register_library_map(array(
'DifferentialRevisionStatus' => 'Phobject',
'DifferentialRevisionSummaryHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionTitleHeraldField' => 'DifferentialRevisionHeraldField',
'DifferentialRevisionTitleTransaction' => 'DifferentialRevisionTransactionType',
'DifferentialRevisionTransactionType' => 'PhabricatorModularTransactionType',
'DifferentialRevisionUpdateHistoryView' => 'AphrontView',
'DifferentialRevisionViewController' => 'DifferentialController',
'DifferentialSchemaSpec' => 'PhabricatorConfigSchemaSpec',
@ -5210,7 +5214,7 @@ phutil_register_library_map(array(
'DifferentialSummaryField' => 'DifferentialCoreCustomField',
'DifferentialTestPlanField' => 'DifferentialCoreCustomField',
'DifferentialTitleField' => 'DifferentialCoreCustomField',
'DifferentialTransaction' => 'PhabricatorApplicationTransaction',
'DifferentialTransaction' => 'PhabricatorModularTransaction',
'DifferentialTransactionComment' => 'PhabricatorApplicationTransactionComment',
'DifferentialTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'DifferentialTransactionQuery' => 'PhabricatorApplicationTransactionQuery',

View file

@ -60,7 +60,17 @@ final class DifferentialRevisionEditEngine
}
protected function buildCustomEditFields($object) {
return array();
return array(
id(new PhabricatorTextEditField())
->setKey('title')
->setLabel(pht('Title'))
->setTransactionType(
DifferentialRevisionTitleTransaction::TRANSACTIONTYPE)
->setDescription(pht('The title of the revision.'))
->setConduitDescription(pht('Retitle the revision.'))
->setConduitTypeDescription(pht('New revision title.'))
->setValue($object->getTitle()),
);
}
}

View file

@ -1,6 +1,7 @@
<?php
final class DifferentialTransaction extends PhabricatorApplicationTransaction {
final class DifferentialTransaction
extends PhabricatorModularTransaction {
private $isCommandeerSideEffect;
@ -17,6 +18,9 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction {
const MAILTAG_REVIEW_REQUEST = 'differential-review-request';
const MAILTAG_OTHER = 'differential-other';
public function getBaseTransactionClass() {
return 'DifferentialRevisionTransactionType';
}
public function setIsCommandeerSideEffect($is_side_effect) {
$this->isCommandeerSideEffect = $is_side_effect;

View file

@ -0,0 +1,57 @@
<?php
final class DifferentialRevisionTitleTransaction
extends DifferentialRevisionTransactionType {
const TRANSACTIONTYPE = 'differential.revision.title';
public function generateOldValue($object) {
return $object->getTitle();
}
public function applyInternalEffects($object, $value) {
$object->setTitle($value);
}
public function getTitle() {
return pht(
'%s retitled this revision from %s to %s.',
$this->renderAuthor(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function getTitleForFeed() {
return pht(
'%s retitled %s from %s to %s.',
$this->renderAuthor(),
$this->renderObject(),
$this->renderOldValue(),
$this->renderNewValue());
}
public function validateTransactions($object, array $xactions) {
$errors = array();
if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
$errors[] = $this->newRequiredError(
pht('Revisions must have a title.'));
}
$max_length = $object->getColumnMaximumByteLength('title');
foreach ($xactions as $xaction) {
$new_value = $xaction->getNewValue();
$new_length = strlen($new_value);
if ($new_length > $max_length) {
$errors[] = $this->newInvalidError(
pht(
'Revision title is too long: the maximum length of a '.
'revision title is 255 bytes.'),
$xaction);
}
}
return $errors;
}
}

View file

@ -0,0 +1,4 @@
<?php
abstract class DifferentialRevisionTransactionType
extends PhabricatorModularTransactionType {}

View file

@ -1,5 +1,9 @@
<?php
// TODO: Some "final" modifiers have been VERY TEMPORARILY moved aside to
// allow DifferentialTransaction to extend this class without converting
// fully to ModularTransactions.
abstract class PhabricatorModularTransaction
extends PhabricatorApplicationTransaction {
@ -76,7 +80,7 @@ abstract class PhabricatorModularTransaction
->applyExternalEffects($object);
}
final public function shouldHide() {
/* final */ public function shouldHide() {
if ($this->getTransactionImplementation()->shouldHide()) {
return true;
}
@ -84,7 +88,7 @@ abstract class PhabricatorModularTransaction
return parent::shouldHide();
}
final public function getIcon() {
/* final */ public function getIcon() {
$icon = $this->getTransactionImplementation()->getIcon();
if ($icon !== null) {
return $icon;
@ -93,7 +97,7 @@ abstract class PhabricatorModularTransaction
return parent::getIcon();
}
final public function getTitle() {
/* final */ public function getTitle() {
$title = $this->getTransactionImplementation()->getTitle();
if ($title !== null) {
return $title;
@ -111,7 +115,7 @@ abstract class PhabricatorModularTransaction
return $title;
}
final public function getTitleForFeed() {
/* final */ public function getTitleForFeed() {
$title = $this->getTransactionImplementation()->getTitleForFeed();
if ($title !== null) {
return $title;
@ -120,7 +124,7 @@ abstract class PhabricatorModularTransaction
return parent::getTitleForFeed();
}
final public function getColor() {
/* final */ public function getColor() {
$color = $this->getTransactionImplementation()->getColor();
if ($color !== null) {
return $color;