Consolidate transaction generation in EditType objects
Summary: Ref T9132. This is a bit more cleanup to make adding CustomField support easier. Right now, both `EditField` and `EditType` can actually generate a transaction. This doesn't matter too much in practice today, but gets a little more complicated a couple of diffs from now with CustomField stuff. Instead, always use `EditType` to generate the transaction. In the future, this should give us less total code and make more things work cleanly by default. Test Plan: Used web UI and Conduit to make various edits to pastes, including doing race-condition tests on "Projects". Reviewers: chad Reviewed By: chad Maniphest Tasks: T9132 Differential Revision: https://secure.phabricator.com/D14607
This commit is contained in:
@@ -630,13 +630,22 @@ abstract class PhabricatorEditEngine
|
|||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$xaction = $field->generateTransaction(clone $template);
|
$types = $field->getWebEditTypes();
|
||||||
|
foreach ($types as $type) {
|
||||||
|
$type_xactions = $type->generateTransactions(
|
||||||
|
clone $template,
|
||||||
|
array(
|
||||||
|
'value' => $field->getValueForTransaction(),
|
||||||
|
));
|
||||||
|
|
||||||
if (!$xaction) {
|
if (!$type_xactions) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($type_xactions as $type_xaction) {
|
||||||
|
$xactions[] = $type_xaction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$xactions[] = $xaction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$editor = $object->getApplicationTransactionEditor()
|
$editor = $object->getApplicationTransactionEditor()
|
||||||
@@ -941,7 +950,7 @@ abstract class PhabricatorEditEngine
|
|||||||
|
|
||||||
$fields = $this->buildEditFields($object);
|
$fields = $this->buildEditFields($object);
|
||||||
|
|
||||||
$types = $this->getAllEditTypesFromFields($fields);
|
$types = $this->getConduitEditTypesFromFields($fields);
|
||||||
$template = $object->getApplicationTransactionTemplate();
|
$template = $object->getApplicationTransactionTemplate();
|
||||||
|
|
||||||
$xactions = $this->getConduitTransactions($request, $types, $template);
|
$xactions = $this->getConduitTransactions($request, $types, $template);
|
||||||
@@ -1031,9 +1040,13 @@ abstract class PhabricatorEditEngine
|
|||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
$type = $types[$xaction['type']];
|
$type = $types[$xaction['type']];
|
||||||
|
|
||||||
$results[] = $type->generateTransaction(
|
$type_xactions = $type->generateTransactions(
|
||||||
clone $template,
|
clone $template,
|
||||||
$xaction);
|
$xaction);
|
||||||
|
|
||||||
|
foreach ($type_xactions as $type_xaction) {
|
||||||
|
$results[] = $type_xaction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
@@ -1044,10 +1057,10 @@ abstract class PhabricatorEditEngine
|
|||||||
* @return map<string, PhabricatorEditType>
|
* @return map<string, PhabricatorEditType>
|
||||||
* @task conduit
|
* @task conduit
|
||||||
*/
|
*/
|
||||||
private function getAllEditTypesFromFields(array $fields) {
|
private function getConduitEditTypesFromFields(array $fields) {
|
||||||
$types = array();
|
$types = array();
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
$field_types = $field->getEditTransactionTypes();
|
$field_types = $field->getConduitEditTypes();
|
||||||
|
|
||||||
if ($field_types === null) {
|
if ($field_types === null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -1061,7 +1074,7 @@ abstract class PhabricatorEditEngine
|
|||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAllEditTypes() {
|
public function getConduitEditTypes() {
|
||||||
$config = $this->loadEditEngineConfiguration(null);
|
$config = $this->loadEditEngineConfiguration(null);
|
||||||
if (!$config) {
|
if (!$config) {
|
||||||
return array();
|
return array();
|
||||||
@@ -1069,7 +1082,7 @@ abstract class PhabricatorEditEngine
|
|||||||
|
|
||||||
$object = $this->newEditableObject();
|
$object = $this->newEditableObject();
|
||||||
$fields = $this->buildEditFields($object);
|
$fields = $this->buildEditFields($object);
|
||||||
return $this->getAllEditTypesFromFields($fields);
|
return $this->getConduitEditTypesFromFields($fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
final public static function getAllEditEngines() {
|
final public static function getAllEditEngines() {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ abstract class PhabricatorEditEngineAPIMethod
|
|||||||
$engine = $this->newEditEngine()
|
$engine = $this->newEditEngine()
|
||||||
->setViewer($viewer);
|
->setViewer($viewer);
|
||||||
|
|
||||||
$types = $engine->getAllEditTypes();
|
$types = $engine->getConduitEditTypes();
|
||||||
|
|
||||||
$out = array();
|
$out = array();
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,4 @@ final class PhabricatorCommentEditField
|
|||||||
return new PhabricatorCommentEditType();
|
return new PhabricatorCommentEditType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTransaction(
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
$spec = array(
|
|
||||||
'value' => $this->getValueForTransaction(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return head($this->getEditTransactionTypes())
|
|
||||||
->generateTransaction($xaction, $spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,24 +268,6 @@ abstract class PhabricatorEditField extends Phobject {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTransaction(
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
if (!$this->getTransactionType()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$xaction
|
|
||||||
->setTransactionType($this->getTransactionType())
|
|
||||||
->setNewValue($this->getValueForTransaction());
|
|
||||||
|
|
||||||
foreach ($this->metadata as $key => $value) {
|
|
||||||
$xaction->setMetadataValue($key, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $xaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setMetadataValue($key, $value) {
|
public function setMetadataValue($key, $value) {
|
||||||
$this->metadata[$key] = $value;
|
$this->metadata[$key] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -295,7 +277,7 @@ abstract class PhabricatorEditField extends Phobject {
|
|||||||
return $this->metadata;
|
return $this->metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getValueForTransaction() {
|
public function getValueForTransaction() {
|
||||||
return $this->getValue();
|
return $this->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +431,7 @@ abstract class PhabricatorEditField extends Phobject {
|
|||||||
->setValueType($this->getHTTPParameterType()->getTypeName());
|
->setValueType($this->getHTTPParameterType()->getTypeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getEditTransactionType() {
|
protected function getEditType() {
|
||||||
$transaction_type = $this->getTransactionType();
|
$transaction_type = $this->getTransactionType();
|
||||||
|
|
||||||
if ($transaction_type === null) {
|
if ($transaction_type === null) {
|
||||||
@@ -465,8 +447,18 @@ abstract class PhabricatorEditField extends Phobject {
|
|||||||
->setMetadata($this->getMetadata());
|
->setMetadata($this->getMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEditTransactionTypes() {
|
public function getConduitEditTypes() {
|
||||||
$edit_type = $this->getEditTransactionType();
|
$edit_type = $this->getEditType();
|
||||||
|
|
||||||
|
if ($edit_type === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array($edit_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWebEditTypes() {
|
||||||
|
$edit_type = $this->getEditType();
|
||||||
|
|
||||||
if ($edit_type === null) {
|
if ($edit_type === null) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ abstract class PhabricatorPHIDListEditField
|
|||||||
return new AphrontPHIDListHTTPParameterType();
|
return new AphrontPHIDListHTTPParameterType();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getValueForTransaction() {
|
public function getValueForTransaction() {
|
||||||
$new = parent::getValueForTransaction();
|
$new = parent::getValueForTransaction();
|
||||||
|
|
||||||
if (!$this->getUseEdgeTransactions()) {
|
if (!$this->getUseEdgeTransactions()) {
|
||||||
@@ -71,9 +71,9 @@ abstract class PhabricatorPHIDListEditField
|
|||||||
return parent::newEditType();
|
return parent::newEditType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEditTransactionTypes() {
|
public function getConduitEditTypes() {
|
||||||
if (!$this->getUseEdgeTransactions()) {
|
if (!$this->getUseEdgeTransactions()) {
|
||||||
return parent::getEditTransactionTypes();
|
return parent::getConduitEditTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
$transaction_type = $this->getTransactionType();
|
$transaction_type = $this->getTransactionType();
|
||||||
@@ -84,7 +84,7 @@ abstract class PhabricatorPHIDListEditField
|
|||||||
$type_key = $this->getEditTypeKey();
|
$type_key = $this->getEditTypeKey();
|
||||||
$strings = $this->transactionDescriptions;
|
$strings = $this->transactionDescriptions;
|
||||||
|
|
||||||
$base = $this->getEditTransactionType();
|
$base = $this->getEditType();
|
||||||
|
|
||||||
$add = id(clone $base)
|
$add = id(clone $base)
|
||||||
->setEditType($type_key.'.add')
|
->setEditType($type_key.'.add')
|
||||||
|
|||||||
@@ -6,22 +6,17 @@ final class PhabricatorCommentEditType extends PhabricatorEditType {
|
|||||||
return id(new AphrontStringHTTPParameterType())->getTypeName();
|
return id(new AphrontStringHTTPParameterType())->getTypeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTransaction(
|
public function generateTransactions(
|
||||||
PhabricatorApplicationTransaction $template,
|
PhabricatorApplicationTransaction $template,
|
||||||
array $spec) {
|
array $spec) {
|
||||||
|
|
||||||
$comment = $template->getApplicationTransactionCommentObject()
|
$comment = $template->getApplicationTransactionCommentObject()
|
||||||
->setContent(idx($spec, 'value'));
|
->setContent(idx($spec, 'value'));
|
||||||
|
|
||||||
$template
|
$xaction = $this->newTransaction($template)
|
||||||
->setTransactionType($this->getTransactionType())
|
|
||||||
->attachComment($comment);
|
->attachComment($comment);
|
||||||
|
|
||||||
foreach ($this->getMetadata() as $key => $value) {
|
return array($xaction);
|
||||||
$template->setMetadataValue($key, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $template;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValueDescription() {
|
public function getValueDescription() {
|
||||||
|
|||||||
@@ -18,25 +18,23 @@ final class PhabricatorEdgeEditType extends PhabricatorEditType {
|
|||||||
return 'list<phid>';
|
return 'list<phid>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTransaction(
|
public function generateTransactions(
|
||||||
PhabricatorApplicationTransaction $template,
|
PhabricatorApplicationTransaction $template,
|
||||||
array $spec) {
|
array $spec) {
|
||||||
|
|
||||||
$value = idx($spec, 'value');
|
$value = idx($spec, 'value');
|
||||||
$value = array_fuse($value);
|
|
||||||
$value = array(
|
|
||||||
$this->getEdgeOperation() => $value,
|
|
||||||
);
|
|
||||||
|
|
||||||
$template
|
if ($this->getEdgeOperation() !== null) {
|
||||||
->setTransactionType($this->getTransactionType())
|
$value = array_fuse($value);
|
||||||
->setNewValue($value);
|
$value = array(
|
||||||
|
$this->getEdgeOperation() => $value,
|
||||||
foreach ($this->getMetadata() as $key => $value) {
|
);
|
||||||
$template->setMetadataValue($key, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $template;
|
$xaction = $this->newTransaction($template)
|
||||||
|
->setNewValue($value);
|
||||||
|
|
||||||
|
return array($xaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValueDescription($value_description) {
|
public function setValueDescription($value_description) {
|
||||||
|
|||||||
@@ -66,11 +66,24 @@ abstract class PhabricatorEditType extends Phobject {
|
|||||||
return $this->transactionType;
|
return $this->transactionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public function generateTransaction(
|
abstract public function generateTransactions(
|
||||||
PhabricatorApplicationTransaction $template,
|
PhabricatorApplicationTransaction $template,
|
||||||
array $spec);
|
array $spec);
|
||||||
|
|
||||||
abstract public function getValueType();
|
abstract public function getValueType();
|
||||||
abstract public function getValueDescription();
|
abstract public function getValueDescription();
|
||||||
|
|
||||||
|
protected function newTransaction(
|
||||||
|
PhabricatorApplicationTransaction $template) {
|
||||||
|
|
||||||
|
$xaction = id(clone $template)
|
||||||
|
->setTransactionType($this->getTransactionType());
|
||||||
|
|
||||||
|
foreach ($this->getMetadata() as $key => $value) {
|
||||||
|
$xaction->setMetadataValue($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $xaction;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,19 +14,14 @@ final class PhabricatorSimpleEditType extends PhabricatorEditType {
|
|||||||
return $this->valueType;
|
return $this->valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateTransaction(
|
public function generateTransactions(
|
||||||
PhabricatorApplicationTransaction $template,
|
PhabricatorApplicationTransaction $template,
|
||||||
array $spec) {
|
array $spec) {
|
||||||
|
|
||||||
$template
|
$edit = $this->newTransaction($template)
|
||||||
->setTransactionType($this->getTransactionType())
|
|
||||||
->setNewValue(idx($spec, 'value'));
|
->setNewValue(idx($spec, 'value'));
|
||||||
|
|
||||||
foreach ($this->getMetadata() as $key => $value) {
|
return array($edit);
|
||||||
$template->setMetadataValue($key, $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $template;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValueDescription($value_description) {
|
public function setValueDescription($value_description) {
|
||||||
|
|||||||
Reference in New Issue
Block a user