1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02: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:
epriestley 2018-01-19 05:49:44 -08:00
parent 91a78db99b
commit 1e51f1d0dc
6 changed files with 29 additions and 57 deletions

View file

@ -72,8 +72,8 @@ final class PhabricatorEditEngineBulkJobType
$xaction = $object->getApplicationTransactionTemplate()
->setTransactionType($raw_xaction['type']);
if (isset($raw_xaction['value'])) {
$xaction->setNewValue($raw_xaction['value']);
if (isset($raw_xaction['new'])) {
$xaction->setNewValue($raw_xaction['new']);
}
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;
}

View file

@ -2472,14 +2472,15 @@ abstract class PhabricatorEditEngine
$fields = $this->buildEditFields($object);
$edit_types = $this->getBulkEditTypesFromFields($fields);
$template = $object->getApplicationTransactionTemplate();
$raw_xactions = array();
foreach ($xactions as $key => $xaction) {
PhutilTypeSpec::checkMap(
$xaction,
array(
'type' => 'string',
'value' => 'optional wild',
'comment' => 'optional string',
));
$type = $xaction['type'];
@ -2497,18 +2498,31 @@ abstract class PhabricatorEditEngine
// but it's possible that this isn't the case.
$xaction['type'] = $edit_type->getTransactionType();
$xaction['metadata'] = $edit_type->getMetadata();
$xaction_objects = $edit_type->generateTransactions(
clone $template,
$xaction);
$xaction = $edit_type->newRawBulkTransaction($xaction);
if ($xaction === null) {
unset($xactions[$key]);
continue;
foreach ($xaction_objects as $xaction_object) {
$raw_xaction = array(
'type' => $xaction_object->getTransactionType(),
'metadata' => $xaction_object->getMetadata(),
'new' => $xaction_object->getNewValue(),
);
if ($xaction_object->hasOldValue()) {
$raw_xaction['old'] = $xaction_object->getOldValue();
}
if ($xaction_object->hasComment()) {
$comment = $xaction_object->getComment();
$raw_xaction['comment'] = $comment->getContent();
}
$raw_xactions[] = $raw_xaction;
}
$xactions[$key] = $xaction;
}
return $xactions;
return $raw_xactions;
}
private function getBulkEditTypesFromFields(array $fields) {

View file

@ -10,17 +10,6 @@ final class PhabricatorCommentEditType extends PhabricatorEditType {
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(
PhabricatorApplicationTransaction $template,
array $spec) {

View file

@ -19,20 +19,4 @@ final class PhabricatorDatasourceEditType
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;
}
}

View file

@ -43,18 +43,4 @@ final class PhabricatorEdgeEditType
->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;
}
}

View file

@ -115,11 +115,6 @@ abstract class PhabricatorEditType extends Phobject {
}
public function newRawBulkTransaction(array $xaction) {
return $xaction;
}
/* -( Conduit )------------------------------------------------------------ */