Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/controller/HeraldTestConsoleController.php
Show First 20 Lines • Show All 254 Lines • ▼ Show 20 Lines | private function loadAppliedTransactions($object) { | ||||
if (!($object instanceof PhabricatorApplicationTransactionInterface)) { | if (!($object instanceof PhabricatorApplicationTransactionInterface)) { | ||||
return null; | return null; | ||||
} | } | ||||
$query = PhabricatorApplicationTransactionQuery::newQueryForObject( | $query = PhabricatorApplicationTransactionQuery::newQueryForObject( | ||||
$object); | $object); | ||||
$xactions = $query | $query | ||||
->withObjectPHIDs(array($object->getPHID())) | ->withObjectPHIDs(array($object->getPHID())) | ||||
->setViewer($viewer) | ->setViewer($viewer); | ||||
->setLimit(100) | |||||
->execute(); | $xactions = new PhabricatorQueryIterator($query); | ||||
$applied = array(); | $applied = array(); | ||||
// Pick the most recent group of transactions. This may not be exactly the | $recent_id = null; | ||||
// same as what Herald acted on: for example, we may select a single group | $hard_limit = 1000; | ||||
// of transactions here which were really applied across two or more edits. | |||||
// Since this is relatively rare and we show you what we picked, it's okay | |||||
// that we just do roughly the right thing. | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
if (!$xaction->shouldDisplayGroupWith($applied)) { | $group_id = $xaction->getTransactionGroupID(); | ||||
// If this is the first transaction, save the group ID: we want to | |||||
// select all transactions in the same group. | |||||
if (!$applied) { | |||||
$recent_id = $group_id; | |||||
if ($recent_id === null) { | |||||
// If the first transaction has no group ID, it is likely an older | |||||
// transaction from before the introduction of group IDs. In this | |||||
// case, select only the most recent transaction and bail out. | |||||
$applied[] = $xaction; | |||||
break; | |||||
} | |||||
} | |||||
// If this transaction is from a different transaction group, we've | |||||
// found all the transactions applied in the most recent group. | |||||
if ($group_id !== $recent_id) { | |||||
break; | break; | ||||
} | } | ||||
$applied[] = $xaction; | $applied[] = $xaction; | ||||
if (count($applied) > $hard_limit) { | |||||
throw new Exception( | |||||
pht( | |||||
'This object ("%s") has more than %s transactions in its most '. | |||||
'recent transaction group; this is too many.', | |||||
$object->getPHID(), | |||||
new PhutilNumber($hard_limit))); | |||||
} | |||||
} | } | ||||
return $applied; | return $applied; | ||||
} | } | ||||
} | } |