Path: blob/master/src/applications/audit/view/PhabricatorAuditTransactionView.php
12256 views
<?php12final class PhabricatorAuditTransactionView3extends PhabricatorApplicationTransactionView {45private $pathMap = array();67public function setPathMap(array $path_map) {8$this->pathMap = $path_map;9return $this;10}1112public function getPathMap() {13return $this->pathMap;14}1516// TODO: This shares a lot of code with Differential and Pholio and should17// probably be merged up.1819protected function shouldGroupTransactions(20PhabricatorApplicationTransaction $u,21PhabricatorApplicationTransaction $v) {2223if ($u->getAuthorPHID() != $v->getAuthorPHID()) {24// Don't group transactions by different authors.25return false;26}2728if (($v->getDateCreated() - $u->getDateCreated()) > 60) {29// Don't group if transactions that happened more than 60s apart.30return false;31}3233switch ($u->getTransactionType()) {34case PhabricatorTransactions::TYPE_COMMENT:35case PhabricatorAuditActionConstants::INLINE:36break;37default:38return false;39}4041switch ($v->getTransactionType()) {42case PhabricatorAuditActionConstants::INLINE:43return true;44}4546return parent::shouldGroupTransactions($u, $v);47}4849protected function renderTransactionContent(50PhabricatorApplicationTransaction $xaction) {5152$out = array();5354$type_inline = PhabricatorAuditActionConstants::INLINE;5556$group = $xaction->getTransactionGroup();5758if ($xaction->getTransactionType() == $type_inline) {59array_unshift($group, $xaction);60} else {61$out[] = parent::renderTransactionContent($xaction);62}6364if ($this->getIsPreview()) {65return $out;66}6768if (!$group) {69return $out;70}7172$inlines = array();73foreach ($group as $xaction) {74switch ($xaction->getTransactionType()) {75case PhabricatorAuditActionConstants::INLINE:76$inlines[] = $xaction;77break;78default:79throw new Exception(pht('Unknown grouped transaction type!'));80}81}8283$structs = array();84foreach ($inlines as $key => $inline) {85$comment = $inline->getComment();86if (!$comment) {87// TODO: Migrate these away? They probably do not exist on normal88// non-development installs.89unset($inlines[$key]);90continue;91}9293$path_id = $comment->getPathID();94$path = idx($this->pathMap, $path_id);95if ($path === null) {96continue;97}9899$structs[] = array(100'inline' => $inline,101'path' => $path,102'sort' => (string)id(new PhutilSortVector())103->addString($path)104->addInt($comment->getLineNumber())105->addInt($comment->getLineLength())106->addInt($inline->getID()),107);108}109110if (!$structs) {111return $out;112}113114$structs = isort($structs, 'sort');115$structs = igroup($structs, 'path');116117$inline_view = new PhabricatorInlineSummaryView();118foreach ($structs as $path => $group) {119$inlines = ipull($group, 'inline');120$items = array();121foreach ($inlines as $inline) {122$comment = $inline->getComment();123$items[] = array(124'id' => $comment->getID(),125'line' => $comment->getLineNumber(),126'length' => $comment->getLineLength(),127'content' => parent::renderTransactionContent($inline),128);129}130$inline_view->addCommentGroup($path, $items);131}132133$out[] = $inline_view;134135return $out;136}137138}139140141