Path: blob/master/src/applications/fact/engine/PhabricatorTransactionFactEngine.php
12256 views
<?php12abstract class PhabricatorTransactionFactEngine3extends PhabricatorFactEngine {45public function newTransactionGroupsForObject(PhabricatorLiskDAO $object) {6$viewer = $this->getViewer();78$xaction_query = PhabricatorApplicationTransactionQuery::newQueryForObject(9$object);10$xactions = $xaction_query11->setViewer($viewer)12->withObjectPHIDs(array($object->getPHID()))13->execute();1415$xactions = msortv($xactions, 'newChronologicalSortVector');1617return $this->groupTransactions($xactions);18}1920protected function groupTransactions(array $xactions) {21// These grouping rules are generally much looser than the display grouping22// rules. As long as the same user is editing the task and they don't leave23// it alone for a particularly long time, we'll group things together.2425$breaks = array();2627$touch_window = phutil_units('15 minutes in seconds');28$user_type = PhabricatorPeopleUserPHIDType::TYPECONST;2930$last_actor = null;31$last_epoch = null;3233foreach ($xactions as $key => $xaction) {34$this_actor = $xaction->getAuthorPHID();35if (phid_get_type($this_actor) != $user_type) {36$this_actor = null;37}3839if ($this_actor && $last_actor && ($this_actor != $last_actor)) {40$breaks[$key] = true;41}4243// If too much time passed between changes, group them separately.44$this_epoch = $xaction->getDateCreated();45if ($last_epoch) {46if (($this_epoch - $last_epoch) > $touch_window) {47$breaks[$key] = true;48}49}5051// The clock gets reset every time the same real user touches the52// task, but does not reset if an automated actor touches things.53if (!$last_actor || ($this_actor == $last_actor)) {54$last_epoch = $this_epoch;55}5657if ($this_actor && ($last_actor != $this_actor)) {58$last_actor = $this_actor;59$last_epoch = $this_epoch;60}61}6263$groups = array();64$group = array();65foreach ($xactions as $key => $xaction) {66if (isset($breaks[$key])) {67if ($group) {68$groups[] = $group;69$group = array();70}71}7273$group[] = $xaction;74}7576if ($group) {77$groups[] = $group;78}7980return $groups;81}8283}848586