@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+29 -57
+6 -2
src/applications/transactions/bulk/PhabricatorEditEngineBulkJobType.php
··· 72 72 $xaction = $object->getApplicationTransactionTemplate() 73 73 ->setTransactionType($raw_xaction['type']); 74 74 75 - if (isset($raw_xaction['value'])) { 76 - $xaction->setNewValue($raw_xaction['value']); 75 + if (isset($raw_xaction['new'])) { 76 + $xaction->setNewValue($raw_xaction['new']); 77 77 } 78 78 79 79 if (isset($raw_xaction['comment'])) { ··· 86 86 foreach ($raw_xaction['metadata'] as $meta_key => $meta_value) { 87 87 $xaction->setMetadataValue($meta_key, $meta_value); 88 88 } 89 + } 90 + 91 + if (array_key_exists('old', $raw_xaction)) { 92 + $xaction->setOldValue($raw_xaction['old']); 89 93 } 90 94 91 95 $xactions[] = $xaction;
+23 -9
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 2472 2472 $fields = $this->buildEditFields($object); 2473 2473 2474 2474 $edit_types = $this->getBulkEditTypesFromFields($fields); 2475 + $template = $object->getApplicationTransactionTemplate(); 2475 2476 2477 + $raw_xactions = array(); 2476 2478 foreach ($xactions as $key => $xaction) { 2477 2479 PhutilTypeSpec::checkMap( 2478 2480 $xaction, 2479 2481 array( 2480 2482 'type' => 'string', 2481 2483 'value' => 'optional wild', 2482 - 'comment' => 'optional string', 2483 2484 )); 2484 2485 2485 2486 $type = $xaction['type']; ··· 2497 2498 // but it's possible that this isn't the case. 2498 2499 $xaction['type'] = $edit_type->getTransactionType(); 2499 2500 2500 - $xaction['metadata'] = $edit_type->getMetadata(); 2501 + $xaction_objects = $edit_type->generateTransactions( 2502 + clone $template, 2503 + $xaction); 2501 2504 2502 - $xaction = $edit_type->newRawBulkTransaction($xaction); 2503 - if ($xaction === null) { 2504 - unset($xactions[$key]); 2505 - continue; 2506 - } 2505 + foreach ($xaction_objects as $xaction_object) { 2506 + $raw_xaction = array( 2507 + 'type' => $xaction_object->getTransactionType(), 2508 + 'metadata' => $xaction_object->getMetadata(), 2509 + 'new' => $xaction_object->getNewValue(), 2510 + ); 2507 2511 2508 - $xactions[$key] = $xaction; 2512 + if ($xaction_object->hasOldValue()) { 2513 + $raw_xaction['old'] = $xaction_object->getOldValue(); 2514 + } 2515 + 2516 + if ($xaction_object->hasComment()) { 2517 + $comment = $xaction_object->getComment(); 2518 + $raw_xaction['comment'] = $comment->getContent(); 2519 + } 2520 + 2521 + $raw_xactions[] = $raw_xaction; 2522 + } 2509 2523 } 2510 2524 2511 - return $xactions; 2525 + return $raw_xactions; 2512 2526 } 2513 2527 2514 2528 private function getBulkEditTypesFromFields(array $fields) {
-11
src/applications/transactions/edittype/PhabricatorCommentEditType.php
··· 10 10 return new BulkRemarkupParameterType(); 11 11 } 12 12 13 - public function newRawBulkTransaction(array $xaction) { 14 - if (!strlen($xaction['value'])) { 15 - return null; 16 - } 17 - 18 - $xaction['comment'] = $xaction['value']; 19 - unset($xaction['value']); 20 - 21 - return $xaction; 22 - } 23 - 24 13 public function generateTransactions( 25 14 PhabricatorApplicationTransaction $template, 26 15 array $spec) {
-16
src/applications/transactions/edittype/PhabricatorDatasourceEditType.php
··· 19 19 return '?'; 20 20 } 21 21 22 - public function newRawBulkTransaction(array $xaction) { 23 - $value = idx($xaction, 'value'); 24 - 25 - if ($this->getIsSingleValue()) { 26 - if ($value) { 27 - $value = head($value); 28 - } else { 29 - $value = null; 30 - } 31 - 32 - $xaction['value'] = $value; 33 - } 34 - 35 - return $xaction; 36 - } 37 - 38 22 }
-14
src/applications/transactions/edittype/PhabricatorEdgeEditType.php
··· 43 43 ->setDatasource($this->getDatasource()); 44 44 } 45 45 46 - public function newRawBulkTransaction(array $xaction) { 47 - $value = idx($xaction, 'value'); 48 - 49 - if ($this->getEdgeOperation() !== null) { 50 - $value = array_fuse($value); 51 - $value = array( 52 - $this->getEdgeOperation() => $value, 53 - ); 54 - $xaction['value'] = $value; 55 - } 56 - 57 - return $xaction; 58 - } 59 - 60 46 }
-5
src/applications/transactions/edittype/PhabricatorEditType.php
··· 115 115 } 116 116 117 117 118 - public function newRawBulkTransaction(array $xaction) { 119 - return $xaction; 120 - } 121 - 122 - 123 118 /* -( Conduit )------------------------------------------------------------ */ 124 119 125 120