mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23: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()
|
||||
->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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
$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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -115,11 +115,6 @@ abstract class PhabricatorEditType extends Phobject {
|
|||
}
|
||||
|
||||
|
||||
public function newRawBulkTransaction(array $xaction) {
|
||||
return $xaction;
|
||||
}
|
||||
|
||||
|
||||
/* -( Conduit )------------------------------------------------------------ */
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue