@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.

In Herald, save applied transaction PHIDs in the transcript and display them in the UI

Summary:
Ref T13283. Since D14575, we already pass applied transactions to Herald, but they exist only as a backwards compatibility layer and have no upstream callsites.

Save the applied transaction PHIDs as part of the object transcript, and show them in the UI.

Test Plan:
- Viewed a modern transcript, saw a list of transactions.
- Viewed an older transcript, saw nothing (since there were no transactions in the transcript).

{F6456431}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13283

Differential Revision: https://secure.phabricator.com/D20518

+138 -6
+94
src/applications/herald/controller/HeraldTranscriptController.php
··· 20 20 return new Aphront404Response(); 21 21 } 22 22 23 + $object = $xscript->getObject(); 24 + 23 25 require_celerity_resource('herald-test-css'); 24 26 $content = array(); 25 27 ··· 72 74 $content[] = array( 73 75 $this->buildActionTranscriptPanel($xscript), 74 76 $this->buildObjectTranscriptPanel($xscript), 77 + $this->buildTransactionsTranscriptPanel( 78 + $object, 79 + $xscript), 75 80 ); 76 81 } 77 82 ··· 500 505 $box->appendChild($property_list); 501 506 502 507 return $box; 508 + } 509 + 510 + private function buildTransactionsTranscriptPanel( 511 + $object, 512 + HeraldTranscript $xscript) { 513 + $viewer = $this->getViewer(); 514 + 515 + $object_xscript = $xscript->getObjectTranscript(); 516 + 517 + $xaction_phids = $object_xscript->getAppliedTransactionPHIDs(); 518 + 519 + // If the value is "null", this is an older transcript or this adapter 520 + // does not use transactions. We render nothing. 521 + // 522 + // If the value is "array()", this is a modern transcript which uses 523 + // transactions, there just weren't any applied. Below, we'll render a 524 + // "No Transactions Applied" state. 525 + if ($xaction_phids === null) { 526 + return null; 527 + } 528 + 529 + // If this object doesn't implement the right interface, we won't be 530 + // able to load the transactions. Just bail. 531 + if (!($object instanceof PhabricatorApplicationTransactionInterface)) { 532 + return null; 533 + } 534 + 535 + $query = PhabricatorApplicationTransactionQuery::newQueryForObject( 536 + $object); 537 + 538 + if ($xaction_phids) { 539 + $xactions = $query 540 + ->setViewer($viewer) 541 + ->withPHIDs($xaction_phids) 542 + ->execute(); 543 + $xactions = mpull($xactions, null, 'getPHID'); 544 + } else { 545 + $xactions = array(); 546 + } 547 + 548 + $rows = array(); 549 + foreach ($xaction_phids as $xaction_phid) { 550 + $xaction = idx($xactions, $xaction_phid); 551 + 552 + $xaction_identifier = $xaction_phid; 553 + $xaction_date = null; 554 + $xaction_display = null; 555 + if ($xaction) { 556 + $xaction_identifier = $xaction->getID(); 557 + $xaction_date = phabricator_datetime( 558 + $xaction->getDateCreated(), 559 + $viewer); 560 + 561 + // Since we don't usually render transactions outside of the context 562 + // of objects, some of them might depend on missing object data. Out of 563 + // an abundance of caution, catch any rendering issues. 564 + try { 565 + $xaction_display = $xaction->getTitle(); 566 + } catch (Exception $ex) { 567 + $xaction_display = $ex->getMessage(); 568 + } 569 + } 570 + 571 + $rows[] = array( 572 + $xaction_identifier, 573 + $xaction_display, 574 + $xaction_date, 575 + ); 576 + } 577 + 578 + $table_view = id(new AphrontTableView($rows)) 579 + ->setHeaders( 580 + array( 581 + pht('ID'), 582 + pht('Transaction'), 583 + pht('Date'), 584 + )) 585 + ->setColumnClasses( 586 + array( 587 + null, 588 + 'wide', 589 + null, 590 + )); 591 + 592 + $box_view = id(new PHUIObjectBoxView()) 593 + ->setHeaderText(pht('Transactions')) 594 + ->setTable($table_view); 595 + 596 + return $box_view; 503 597 } 504 598 505 599
+12 -5
src/applications/herald/engine/HeraldEngine.php
··· 126 126 } 127 127 } 128 128 129 - $object_transcript = new HeraldObjectTranscript(); 130 - $object_transcript->setPHID($object->getPHID()); 131 - $object_transcript->setName($object->getHeraldName()); 132 - $object_transcript->setType($object->getAdapterContentType()); 133 - $object_transcript->setFields($this->fieldCache); 129 + $xaction_phids = null; 130 + $xactions = $object->getAppliedTransactions(); 131 + if ($xactions !== null) { 132 + $xaction_phids = mpull($xactions, 'getPHID'); 133 + } 134 + 135 + $object_transcript = id(new HeraldObjectTranscript()) 136 + ->setPHID($object->getPHID()) 137 + ->setName($object->getHeraldName()) 138 + ->setType($object->getAdapterContentType()) 139 + ->setFields($this->fieldCache) 140 + ->setAppliedTransactionPHIDs($xaction_phids); 134 141 135 142 $this->transcript->setObjectTranscript($object_transcript); 136 143
+11 -1
src/applications/herald/query/HeraldTranscriptQuery.php
··· 81 81 ->execute(); 82 82 83 83 foreach ($transcripts as $key => $transcript) { 84 - if (empty($objects[$transcript->getObjectPHID()])) { 84 + $object_phid = $transcript->getObjectPHID(); 85 + 86 + if (!$object_phid) { 87 + $transcript->attachObject(null); 88 + continue; 89 + } 90 + 91 + $object = idx($objects, $object_phid); 92 + if (!$object) { 85 93 $this->didRejectResult($transcript); 86 94 unset($transcripts[$key]); 87 95 } 96 + 97 + $transcript->attachObject($object); 88 98 } 89 99 90 100 return $transcripts;
+10
src/applications/herald/storage/transcript/HeraldObjectTranscript.php
··· 6 6 protected $type; 7 7 protected $name; 8 8 protected $fields; 9 + protected $appliedTransactionPHIDs; 9 10 10 11 public function setPHID($phid) { 11 12 $this->phid = $phid; ··· 45 46 46 47 public function getFields() { 47 48 return $this->fields; 49 + } 50 + 51 + public function setAppliedTransactionPHIDs($phids) { 52 + $this->appliedTransactionPHIDs = $phids; 53 + return $this; 54 + } 55 + 56 + public function getAppliedTransactionPHIDs() { 57 + return $this->appliedTransactionPHIDs; 48 58 } 49 59 50 60 private static function truncateValue($value, $length) {
+11
src/applications/herald/storage/transcript/HeraldTranscript.php
··· 18 18 protected $dryRun; 19 19 protected $garbageCollected = 0; 20 20 21 + private $object = self::ATTACHABLE; 22 + 21 23 const TABLE_SAVED_HEADER = 'herald_savedheader'; 22 24 23 25 public function getXHeraldRulesHeader() { ··· 192 194 public function generatePHID() { 193 195 return PhabricatorPHID::generateNewPHID( 194 196 HeraldTranscriptPHIDType::TYPECONST); 197 + } 198 + 199 + public function attachObject($object = null) { 200 + $this->object = $object; 201 + return $this; 202 + } 203 + 204 + public function getObject() { 205 + return $this->assertAttached($this->object); 195 206 } 196 207 197 208 /* -( PhabricatorPolicyInterface )----------------------------------------- */