mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 01:02:42 +01:00
Reuse more transaction construction code in bulk editor
Summary: Ref T13025. Currently, the bulk editor takes an HTTP request and emits a list of "raw" transactions (simple dictionaries). This goes into the job queue, and the background job builds a real transaction. However, the logic to turn an HTTP request into a raw transaction is ending up with some duplication, since we generally already have logic to turn an HTTP request into a full object. Instead: build real objects first, then serialize them to dictionaries. Send those to the job queue, rebuild them into objects again, and we end up in the same spot with a little less code duplication. Finally, delete the mostly-copied code. Test Plan: Used bulk editor to add comments, projects, and rename tasks. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13025 Differential Revision: https://secure.phabricator.com/D18875
This commit is contained in:
parent
91a78db99b
commit
1e51f1d0dc
6 changed files with 29 additions and 57 deletions
|
@ -72,8 +72,8 @@ final class PhabricatorEditEngineBulkJobType
|
||||||
$xaction = $object->getApplicationTransactionTemplate()
|
$xaction = $object->getApplicationTransactionTemplate()
|
||||||
->setTransactionType($raw_xaction['type']);
|
->setTransactionType($raw_xaction['type']);
|
||||||
|
|
||||||
if (isset($raw_xaction['value'])) {
|
if (isset($raw_xaction['new'])) {
|
||||||
$xaction->setNewValue($raw_xaction['value']);
|
$xaction->setNewValue($raw_xaction['new']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($raw_xaction['comment'])) {
|
if (isset($raw_xaction['comment'])) {
|
||||||
|
@ -88,6 +88,10 @@ final class PhabricatorEditEngineBulkJobType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('old', $raw_xaction)) {
|
||||||
|
$xaction->setOldValue($raw_xaction['old']);
|
||||||
|
}
|
||||||
|
|
||||||
$xactions[] = $xaction;
|
$xactions[] = $xaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2472,14 +2472,15 @@ abstract class PhabricatorEditEngine
|
||||||
$fields = $this->buildEditFields($object);
|
$fields = $this->buildEditFields($object);
|
||||||
|
|
||||||
$edit_types = $this->getBulkEditTypesFromFields($fields);
|
$edit_types = $this->getBulkEditTypesFromFields($fields);
|
||||||
|
$template = $object->getApplicationTransactionTemplate();
|
||||||
|
|
||||||
|
$raw_xactions = array();
|
||||||
foreach ($xactions as $key => $xaction) {
|
foreach ($xactions as $key => $xaction) {
|
||||||
PhutilTypeSpec::checkMap(
|
PhutilTypeSpec::checkMap(
|
||||||
$xaction,
|
$xaction,
|
||||||
array(
|
array(
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'value' => 'optional wild',
|
'value' => 'optional wild',
|
||||||
'comment' => 'optional string',
|
|
||||||
));
|
));
|
||||||
|
|
||||||
$type = $xaction['type'];
|
$type = $xaction['type'];
|
||||||
|
@ -2497,18 +2498,31 @@ abstract class PhabricatorEditEngine
|
||||||
// but it's possible that this isn't the case.
|
// but it's possible that this isn't the case.
|
||||||
$xaction['type'] = $edit_type->getTransactionType();
|
$xaction['type'] = $edit_type->getTransactionType();
|
||||||
|
|
||||||
$xaction['metadata'] = $edit_type->getMetadata();
|
$xaction_objects = $edit_type->generateTransactions(
|
||||||
|
clone $template,
|
||||||
|
$xaction);
|
||||||
|
|
||||||
$xaction = $edit_type->newRawBulkTransaction($xaction);
|
foreach ($xaction_objects as $xaction_object) {
|
||||||
if ($xaction === null) {
|
$raw_xaction = array(
|
||||||
unset($xactions[$key]);
|
'type' => $xaction_object->getTransactionType(),
|
||||||
continue;
|
'metadata' => $xaction_object->getMetadata(),
|
||||||
|
'new' => $xaction_object->getNewValue(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($xaction_object->hasOldValue()) {
|
||||||
|
$raw_xaction['old'] = $xaction_object->getOldValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
$xactions[$key] = $xaction;
|
if ($xaction_object->hasComment()) {
|
||||||
|
$comment = $xaction_object->getComment();
|
||||||
|
$raw_xaction['comment'] = $comment->getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $xactions;
|
$raw_xactions[] = $raw_xaction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $raw_xactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBulkEditTypesFromFields(array $fields) {
|
private function getBulkEditTypesFromFields(array $fields) {
|
||||||
|
|
|
@ -10,17 +10,6 @@ final class PhabricatorCommentEditType extends PhabricatorEditType {
|
||||||
return new BulkRemarkupParameterType();
|
return new BulkRemarkupParameterType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newRawBulkTransaction(array $xaction) {
|
|
||||||
if (!strlen($xaction['value'])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$xaction['comment'] = $xaction['value'];
|
|
||||||
unset($xaction['value']);
|
|
||||||
|
|
||||||
return $xaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function generateTransactions(
|
public function generateTransactions(
|
||||||
PhabricatorApplicationTransaction $template,
|
PhabricatorApplicationTransaction $template,
|
||||||
array $spec) {
|
array $spec) {
|
||||||
|
|
|
@ -19,20 +19,4 @@ final class PhabricatorDatasourceEditType
|
||||||
return '?';
|
return '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newRawBulkTransaction(array $xaction) {
|
|
||||||
$value = idx($xaction, 'value');
|
|
||||||
|
|
||||||
if ($this->getIsSingleValue()) {
|
|
||||||
if ($value) {
|
|
||||||
$value = head($value);
|
|
||||||
} else {
|
|
||||||
$value = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$xaction['value'] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $xaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,18 +43,4 @@ final class PhabricatorEdgeEditType
|
||||||
->setDatasource($this->getDatasource());
|
->setDatasource($this->getDatasource());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newRawBulkTransaction(array $xaction) {
|
|
||||||
$value = idx($xaction, 'value');
|
|
||||||
|
|
||||||
if ($this->getEdgeOperation() !== null) {
|
|
||||||
$value = array_fuse($value);
|
|
||||||
$value = array(
|
|
||||||
$this->getEdgeOperation() => $value,
|
|
||||||
);
|
|
||||||
$xaction['value'] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $xaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,11 +115,6 @@ abstract class PhabricatorEditType extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function newRawBulkTransaction(array $xaction) {
|
|
||||||
return $xaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -( Conduit )------------------------------------------------------------ */
|
/* -( Conduit )------------------------------------------------------------ */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue