1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 12:30:56 +01:00

Implement Differential subscribers as a CustomField

Summary: Ref T3886. Now that a custom field can emit a core transaction, just emit a subscribers transaction.

Test Plan: {F116014}

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3886

Differential Revision: https://secure.phabricator.com/D8289
This commit is contained in:
epriestley 2014-02-21 11:54:08 -08:00
parent f91e94eb90
commit aa7ba4c6e6
9 changed files with 66 additions and 18 deletions

View file

@ -464,6 +464,7 @@ phutil_register_library_map(array(
'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php', 'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php',
'DifferentialSearchIndexer' => 'applications/differential/search/DifferentialSearchIndexer.php', 'DifferentialSearchIndexer' => 'applications/differential/search/DifferentialSearchIndexer.php',
'DifferentialSubscribeController' => 'applications/differential/controller/DifferentialSubscribeController.php', 'DifferentialSubscribeController' => 'applications/differential/controller/DifferentialSubscribeController.php',
'DifferentialSubscribersField' => 'applications/differential/customfield/DifferentialSubscribersField.php',
'DifferentialSummaryField' => 'applications/differential/customfield/DifferentialSummaryField.php', 'DifferentialSummaryField' => 'applications/differential/customfield/DifferentialSummaryField.php',
'DifferentialSummaryFieldSpecification' => 'applications/differential/field/specification/DifferentialSummaryFieldSpecification.php', 'DifferentialSummaryFieldSpecification' => 'applications/differential/field/specification/DifferentialSummaryFieldSpecification.php',
'DifferentialTasksAttacher' => 'applications/differential/DifferentialTasksAttacher.php', 'DifferentialTasksAttacher' => 'applications/differential/DifferentialTasksAttacher.php',
@ -3012,6 +3013,7 @@ phutil_register_library_map(array(
'DifferentialRevisionViewController' => 'DifferentialController', 'DifferentialRevisionViewController' => 'DifferentialController',
'DifferentialSearchIndexer' => 'PhabricatorSearchDocumentIndexer', 'DifferentialSearchIndexer' => 'PhabricatorSearchDocumentIndexer',
'DifferentialSubscribeController' => 'DifferentialController', 'DifferentialSubscribeController' => 'DifferentialController',
'DifferentialSubscribersField' => 'DifferentialCoreCustomField',
'DifferentialSummaryField' => 'DifferentialCoreCustomField', 'DifferentialSummaryField' => 'DifferentialCoreCustomField',
'DifferentialSummaryFieldSpecification' => 'DifferentialFreeformFieldSpecification', 'DifferentialSummaryFieldSpecification' => 'DifferentialFreeformFieldSpecification',
'DifferentialTestPlanField' => 'DifferentialCoreCustomField', 'DifferentialTestPlanField' => 'DifferentialCoreCustomField',

View file

@ -14,9 +14,11 @@ abstract class DifferentialCoreCustomField
abstract protected function readValueFromRevision( abstract protected function readValueFromRevision(
DifferentialRevision $revision); DifferentialRevision $revision);
abstract protected function writeValueToRevision( protected function writeValueToRevision(
DifferentialRevision $revision, DifferentialRevision $revision,
$value); $value) {
throw new PhabricatorCustomFieldImplementationIncompleteException($this);
}
protected function isCoreFieldRequired() { protected function isCoreFieldRequired() {
return false; return false;

View file

@ -20,12 +20,6 @@ final class DifferentialEditPolicyField
return $revision->getEditPolicy(); return $revision->getEditPolicy();
} }
protected function writeValueToRevision(
DifferentialRevision $revision,
$value) {
$revision->setEditPolicy($value);
}
public function readValueFromRequest(AphrontRequest $request) { public function readValueFromRequest(AphrontRequest $request) {
$this->setValue($request->getStr($this->getFieldKey())); $this->setValue($request->getStr($this->getFieldKey()));
} }

View file

@ -29,7 +29,7 @@ final class DifferentialRepositoryField
public function readValueFromRequest(AphrontRequest $request) { public function readValueFromRequest(AphrontRequest $request) {
$phids = $request->getArr($this->getFieldKey()); $phids = $request->getArr($this->getFieldKey());
$first = head($phids); $first = head($phids);
$this->setValue(coalesce($first, null)); $this->setValue(nonempty($first, null));
} }
public function getRequiredHandlePHIDsForEdit() { public function getRequiredHandlePHIDsForEdit() {
@ -41,7 +41,6 @@ final class DifferentialRepositoryField
} }
public function renderEditControl(array $handles) { public function renderEditControl(array $handles) {
if ($this->getValue()) { if ($this->getValue()) {
$control_value = array_select_keys($handles, array($this->getValue())); $control_value = array_select_keys($handles, array($this->getValue()));
} else { } else {
@ -97,7 +96,6 @@ final class DifferentialRepositoryField
$xaction->renderHandleLink($author_phid), $xaction->renderHandleLink($author_phid),
$xaction->renderHandleLink($old)); $xaction->renderHandleLink($old));
} }
} }
public function getApplicationTransactionTitleForFeed( public function getApplicationTransactionTitleForFeed(

View file

@ -0,0 +1,49 @@
<?php
final class DifferentialSubscribersField
extends DifferentialCoreCustomField {
public function getFieldKey() {
return 'differential:subscribers';
}
public function getFieldName() {
return pht('Subscribers');
}
public function getFieldDescription() {
return pht('Manage subscribers.');
}
protected function readValueFromRevision(
DifferentialRevision $revision) {
return PhabricatorSubscribersQuery::loadSubscribersForPHID(
$revision->getPHID());
}
public function getNewValueForApplicationTransactions() {
return array('=' => $this->getValue());
}
public function readValueFromRequest(AphrontRequest $request) {
$this->setValue($request->getArr($this->getFieldKey()));
}
public function getRequiredHandlePHIDsForEdit() {
return $this->getValue();
}
public function renderEditControl(array $handles) {
return id(new AphrontFormTokenizerControl())
->setName($this->getFieldKey())
->setDatasource('/typeahead/common/mailable/')
->setValue($handles)
->setError($this->getFieldError())
->setLabel($this->getFieldName());
}
public function getApplicationTransactionType() {
return PhabricatorTransactions::TYPE_SUBSCRIBERS;
}
}

View file

@ -20,12 +20,6 @@ final class DifferentialViewPolicyField
return $revision->getViewPolicy(); return $revision->getViewPolicy();
} }
protected function writeValueToRevision(
DifferentialRevision $revision,
$value) {
$revision->setViewPolicy($value);
}
public function readValueFromRequest(AphrontRequest $request) { public function readValueFromRequest(AphrontRequest $request) {
$this->setValue($request->getStr($this->getFieldKey())); $this->setValue($request->getStr($this->getFieldKey()));
} }

View file

@ -58,6 +58,8 @@ final class DifferentialTransactionEditor
case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY:
$object->setEditPolicy($xaction->getNewValue()); $object->setEditPolicy($xaction->getNewValue());
return; return;
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
return;
} }
return parent::applyCustomInternalTransaction($object, $xaction); return parent::applyCustomInternalTransaction($object, $xaction);
@ -71,6 +73,8 @@ final class DifferentialTransactionEditor
case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_VIEW_POLICY:
case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY:
return; return;
case PhabricatorTransactions::TYPE_SUBSCRIBERS:
return;
} }
return parent::applyCustomExternalTransaction($object, $xaction); return parent::applyCustomExternalTransaction($object, $xaction);

View file

@ -469,6 +469,7 @@ final class DifferentialRevision extends DifferentialDAO
new DifferentialTitleField(), new DifferentialTitleField(),
new DifferentialSummaryField(), new DifferentialSummaryField(),
new DifferentialTestPlanField(), new DifferentialTestPlanField(),
new DifferentialSubscribersField(),
new DifferentialRepositoryField(), new DifferentialRepositoryField(),
new DifferentialViewPolicyField(), new DifferentialViewPolicyField(),
new DifferentialEditPolicyField(), new DifferentialEditPolicyField(),

View file

@ -186,7 +186,11 @@ abstract class PhabricatorApplicationTransaction
public function getHandle($phid) { public function getHandle($phid) {
if (empty($this->handles[$phid])) { if (empty($this->handles[$phid])) {
throw new Exception( throw new Exception(
"Transaction requires a handle ('{$phid}') it did not load."); pht(
'Transaction ("%s") requires a handle ("%s") that it did not '.
'load.',
$this->getPHID(),
$phid));
} }
return $this->handles[$phid]; return $this->handles[$phid];
} }